4

I'm using the memoir document class with the twoside option, and want to use a \textwidth horizontal rule underneath my header, but a smaller horizontal rule above my footer. Unfortunately, the footer rule is always aligned to the left margin, whereas I want it aligned to the outer margin, above the page number.

Minimal working example:

\documentclass[twoside]{memoir}

\copypagestyle{myheadings}{headings}

% add the lines
\makeheadrule{myheadings}{\textwidth}{\normalrulethickness}
\makefootrule{myheadings}{2cm}{\normalrulethickness}{0pt}

% header/footer contents
\makeevenhead{myheadings}{\footnotesize\textsc{chapter \thechapter}}{}{}
\makeoddhead{myheadings}{}{}{\footnotesize\textsc{\MakeLowercase{\leftmark}}}
\makeevenfoot{myheadings}{\footnotesize\thepage}{}{}
\makeoddfoot{myheadings}{}{}{\footnotesize\thepage}

\begin{document}
\pagestyle{myheadings}

Test.
\newpage
Test.
\newpage
Test.

\end{document}

As you can see, page 2 has the line nicely above the page number, while pages 1 and 3 have the line on the other side.

I have tried to add \makeheadposition{myheadings}{}{}{\flushleft}{\flushright}, but that did not change anything.

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – karlkoeller Mar 26 '15 at 12:43
6

We first have to load the etoolbox package and patch the definition of \makefootrule:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\makefootrule}
  {\hrule\@width #2\@height #3 }
  {\rule{#2}{#3}}
  {}
  {}
\makeatother

Then we define \makeheadfootruleprefix to add the needed space in odd pages:

\makeheadfootruleprefix{myheadings}{}{%
  \checkoddpage\ifoddpage\hspace*{\dimexpr\textwidth-2cm\relax}\fi}

That's all.

MWE:

\documentclass[twoside]{memoir}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\makefootrule}
  {\hrule\@width #2\@height #3 }
  {\rule{#2}{#3}}
  {}
  {}
\makeatother

\copypagestyle{myheadings}{headings}

% add the lines
\makeheadfootruleprefix{myheadings}{}{%
  \checkoddpage\ifoddpage\hspace*{\dimexpr\textwidth-2cm\relax}\fi}
\makeheadrule{myheadings}{\textwidth}{\normalrulethickness}
\makefootrule{myheadings}{2cm}{\normalrulethickness}{-4pt}

% header/footer contents
\makeevenhead{myheadings}{\footnotesize\textsc{chapter \thechapter}}{}{}
\makeoddhead{myheadings}{}{}{\footnotesize\textsc{\MakeLowercase{\leftmark}}}
\makeevenfoot{myheadings}{\footnotesize\thepage}{}{}
\makeoddfoot{myheadings}{}{}{\footnotesize\thepage}

\begin{document}
\pagestyle{myheadings}

Test.
\newpage
Test.
\newpage
Test.

\end{document} 

Output:

enter image description here

Notice that I've adjusted \makefootrule to have a -4pt skip

\makefootrule{myheadings}{2cm}{\normalrulethickness}{-4pt}

since \rule is placed higher than \hrule.

  • Nice solution, but you are aware that \rule and \hrule are not placed the same?, \rule sits a few mms higher. – daleif Mar 26 '15 at 14:09
  • Excellent, thank you. However, the solution does not quite work within a multicols environment that stretches multiple pages; the rule is flushed to the right of the first column then. Any thoughts on how to get it to the right of the page instead of the column? (Again I tried to fix it myself, but got stuck.) – EelkeSpaak Mar 26 '15 at 14:12
  • 1
    @EelkeSpaak I've changed the answer and now it works even if you use multicols. – karlkoeller Mar 26 '15 at 16:09
  • @daleif Yes, you're right. Added a fix for that in the answer. – karlkoeller Mar 26 '15 at 16:10
  • @karlkoeller Great solution, thank you. I tried something with \hspace*{} myself, but could not get it to work. – EelkeSpaak Mar 26 '15 at 16:25

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.