TransWikia.com

Distance between top (or bottom) margin and header (or footer)

TeX - LaTeX Asked by Catoblepa on August 22, 2020

I am preparing a camera-ready book. My publisher has given me a stylesheet that is based on a Microsoft Word template. I am having trouble setting the exact measurements of the sheet with the geometry and fancyhdr packages, in particular the position of the header and footer mostly because in Word you can set the distance of the header (or footer) from the paper edge as well as the distance from the text body from the paper edge.
I have looked at various solutions in this forum (for ex. here), but I haven’t found them useful or relevant to my problem.

In a nutshell, I need to format a text with the following specs:

  • Paper size: 16cm x 22cm
  • Top margin (i.e., the distance between the
    top edge and the body of the text): 2.5cm
  • Bottom margin (i.e., the
    distance between the bottom edge the body of the text): 2cm
  • Left margin: 2.35cm; Right margin: 2.75cm; mirrored
  • Header: 1.8cm from top edge
  • Footer: 1.5cm from bottom edge.

For the header distance I have used the solution indicated here, but: a) I don’t understand why I had to enter top=2.4cm when in fact the top margin is at 2.5cm; and b) the header distance from the top edge seems to vary from one page to another. For the footer distance I have not yet found a viable solution.

Please find attached a MWE:

documentclass[10pt, twoside]{memoir}
usepackage[papersize={16cm, 22cm},top=2.4cm,headheight=4.22mm,headsep=2.78mm,bottom=2cm,left=2.35cm,right=2.75cm,twoside]{geometry}
usepackage{fancyhdr}

pagestyle{fancy}
fancyhf{}
fancyhead[CE]{small{Header2}}
fancyhead[CO]{small{Header1}}
renewcommand{headrulewidth}{0pt}
makeatletter
defcleardoublepage{clearpageif@twoside ifoddc@pageelse
hbox{}
vspace*{fill}
begin{center}
end{center}
vspace{fill}
thispagestyle{empty}
newpage
if@twocolumnhbox{}newpagefififi}
makeatother
cfoot{thepage}
begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Nunc sed blandit libero volutpat sed cras ornare arcu dui. Sed viverra tellus in hac. Iaculis eu non diam phasellus vestibulum. Libero id faucibus nisl tincidunt. Orci phasellus egestas tellus rutrum tellus pellentesque eu tincidunt tortor. Tortor pretium viverra suspendisse potenti nullam ac. Eget nullam non nisi est sit amet facilisis magna etiam. Pulvinar pellentesque habitant morbi tristique senectus et. Eget gravida cum sociis natoque penatibus. Ut porttitor leo a diam sollicitudin. Blandit massa enim nec dui nunc mattis enim. Tincidunt praesent semper feugiat nibh sed pulvinar. Facilisis gravida neque convallis a cras semper. Consectetur adipiscing elit pellentesque habitant morbi tristique. Id porta nibh venenatis cras sed felis eget. Lacus suspendisse faucibus interdum posuere lorem ipsum dolor sit amet. Sagittis nisl rhoncus mattis rhoncus urna neque viverra. Risus quis varius quam quisque id diam vel quam.

Lobortis elementum nibh tellus molestie nunc non blandit massa. Vitae ultricies leo integer malesuada. Massa tempor nec feugiat nisl pretium fusce id velit ut. Vestibulum mattis ullamcorper velit sed ullamcorper. Dui vivamus arcu felis bibendum ut tristique et. In aliquam sem fringilla ut morbi. Nec dui nunc mattis enim ut tellus elementum. Ac turpis egestas sed tempus. Egestas maecenas pharetra convallis posuere morbi leo urna. Mauris nunc congue nisi vitae. Vitae turpis massa sed elementum tempus egestas sed sed risus. Augue neque gravida in fermentum. Lobortis feugiat vivamus at augue eget arcu.

Integer malesuada nunc vel risus commodo viverra maecenas accumsan lacus. Lacus viverra vitae congue eu. Mattis pellentesque id nibh tortor id aliquet lectus proin nibh. Id aliquet lectus proin nibh nisl. Integer malesuada nunc vel risus commodo viverra maecenas. Pellentesque sit amet porttitor eget dolor morbi non arcu. Nec tincidunt praesent semper feugiat nibh. Id aliquet risus feugiat in ante. Sagittis nisl rhoncus mattis rhoncus urna. Sapien et ligula ullamcorper malesuada proin.

Dui id ornare arcu odio ut sem nulla pharetra. Dignissim cras tincidunt lobortis feugiat vivamus. Nisi scelerisque eu ultrices vitae auctor. Etiam dignissim diam quis enim lobortis scelerisque fermentum dui faucibus. Non curabitur gravida arcu ac tortor dignissim convallis. A erat nam at lectus urna duis convallis convallis tellus. Massa tincidunt nunc pulvinar sapien. Ac odio tempor orci dapibus. Odio euismod lacinia at quis. Venenatis lectus magna fringilla urna porttitor rhoncus dolor. Nisl condimentum id venenatis a condimentum. Viverra mauris in aliquam sem. Sed vulputate odio ut enim blandit volutpat. Et odio pellentesque diam volutpat commodo sed egestas. Tristique senectus et netus et malesuada. Quisque sagittis purus sit amet volutpat consequat mauris. Cursus risus at ultrices mi tempus imperdiet nulla malesuada. Amet porttitor eget dolor morbi. Consequat mauris nunc congue nisi vitae suscipit tellus mauris.
  end{document}

One Answer

Note that your header doesn't fill the space reserved for it. Nor does the text reach the top of the text area. (The first baseline is topskip below the top.)

documentclass[10pt, twoside]{memoir}
usepackage[papersize={16cm, 22cm},top=2.5cm,headheight=4.22mm,headsep=2.78mm,
  bottom=2cm,footskip=.5cm,left=2.35cm,right=2.75cm,twoside,showframe]{geometry}
usepackage{fancyhdr}

pagestyle{fancy}
fancyhf{}
fancyhead[CE]{small{Header2}}
fancyhead[CO]{small{Header1}}
renewcommand{headrulewidth}{0pt}
makeatletter
defcleardoublepage{clearpageif@twoside ifoddc@pageelse
hbox{}
vspace*{fill}
begin{center}
end{center}
vspace{fill}
thispagestyle{empty}
newpage
if@twocolumnhbox{}newpagefififi}
makeatother
cfoot{thepage}

%topskip=htstrutbox
begin{document}
Distance to header thedimexpr topmargin+1inrelax=thedimexpr 1.8cmrelax

Distance to body thedimexpr topmargin+1in+headheight+headseprelax=thedimexpr 2.5cmrelax

Distance from footer to bottom thedimexpr paperheight-topmargin-1in-headheight-headsep-textheight-footskiprelax
 =thedimexpr 1.5cmrelax
end{document}

Here I reduced topskip and headheight. Note that fancyhdr likes to change headheight based on the contents of the header. More to the point, reducing headheight below 10pt had unusual effects.

documentclass[10pt, twoside]{memoir}
usepackage[papersize={16cm, 22cm},top=2.5cm,headheight=10pt,headsep={dimexpr 0.7cm-10pt},
  bottom=2cm,footskip=.5cm,left=2.35cm,right=2.75cm,twoside,showframe]{geometry}
usepackage{fancyhdr}
usepackage{pgfmath}

newcommand{showstrut}{rule[-dpstrutbox]{1pt}{dimexpr baselineskip}}

pagestyle{fancy}
fancyhf{}
fancyhead[CE]{small{Header2}}
fancyhead[CO]{small{Header1} showstrut}
renewcommand{headrulewidth}{0pt}
makeatletter
defcleardoublepage{clearpageif@twoside ifoddc@pageelse
hbox{}
vspace*{fill}
begin{center}
end{center}
vspace{fill}
thispagestyle{empty}
newpage
if@twocolumnhbox{}newpagefififi}
makeatother
cfoot{thepage}

topskip=htstrutbox
begin{document}
Distance to header thedimexpr topmargin+1inrelax=thedimexpr 1.8cmrelax

Distance to body thedimexpr topmargin+1in+headheight+headseprelax=thedimexpr 2.5cmrelax

Distance from footer to bottom thedimexpr paperheight-topmargin-1in-headheight-headsep-textheight-footskiprelax
 =thedimexpr 1.5cmrelax
end{document}

Answered by John Kormylo on August 22, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP