# Align horizontal footer rule to outside margin with memoir class

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}

\begin{document}

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.

• 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

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:

\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

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

\begin{document}

Test.
\newpage
Test.
\newpage
Test.

\end{document}

Output:

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