0

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
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\begin{center}
\end{center}
\vspace{\fill}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\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}
  • 1
    Don't use fancyhdr with memoir, it has its own much better integrated system for handling headers and footer. Also memoir comes with its own system for setting margins. – daleif Jul 16 at 14:18
  • It should be noted that \footskip is the distance between the bottom of the text area (baseline) and the baseline of the footer. – John Kormylo Jul 16 at 15:22
0

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
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\begin{center}
\end{center}
\vspace{\fill}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\cfoot{\thepage}

%\topskip=\ht\strutbox
\begin{document}
Distance to header \the\dimexpr \topmargin+1in\relax=\the\dimexpr 1.8cm\relax

Distance to body \the\dimexpr \topmargin+1in+\headheight+\headsep\relax=\the\dimexpr 2.5cm\relax

Distance from footer to bottom \the\dimexpr \paperheight-\topmargin-1in-\headheight-\headsep-\textheight-\footskip\relax
 =\the\dimexpr 1.5cm\relax
\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[-\dp\strutbox]{1pt}{\dimexpr \baselineskip}}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[CE]{\small{Header2}}
\fancyhead[CO]{\small{Header1} \showstrut}
\renewcommand{\headrulewidth}{0pt}
\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\begin{center}
\end{center}
\vspace{\fill}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\cfoot{\thepage}

\topskip=\ht\strutbox
\begin{document}
Distance to header \the\dimexpr \topmargin+1in\relax=\the\dimexpr 1.8cm\relax

Distance to body \the\dimexpr \topmargin+1in+\headheight+\headsep\relax=\the\dimexpr 2.5cm\relax

Distance from footer to bottom \the\dimexpr \paperheight-\topmargin-1in-\headheight-\headsep-\textheight-\footskip\relax
 =\the\dimexpr 1.5cm\relax
\end{document}
  • Thank you, @John Kormylo, but I am still not sure about what to do if I want the header to fill the space reserved to it and if I want the text to reach the top of the box. – Catoblepa Jul 17 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.