Fixes issue #3740 for horizontal layouts