Variable spacing for legend enteries instead of "labelspacing"

Could someone help me with this question in SO.

Thanks in advance.