Guard against NaN when computing horiz padding

Issue #2467