Thanks for the code. I have a vertical legend in the upper right corner with two elements within the legend. The code is shrinking one of the elements as described but upon the second loop, I get the following error:
Error using hg.hggroup/get
The name 'XData' is not an accessible property for an instance of class 'hggroup'.
Error in legendshrink (line 114)
linepos = get(cch(ii),'XData');