Thanks for your suggestions.
The thread goes then on at:
By the way, there was a problem in my previous function if the left-right margins and top-bottom were not equivalent. I have corrected this in the follow-up thread, so ignore the previous code here.