fix margin calculation problem
Merge pull request #914 from FHenry/3.4

fix margin calculation problem