# Putting page numbers in margin of header in Memoir class

I like books where the page numbers sit in the outer margins. I'm trying to reproduce this for my thesis in memoir class.

I have attempted it (see MWE) but it's a terrible approach - I used \hspace which breaks once the figure numbers go to two or three digits (see all the images of this code compiled).

Second issue: I can't get the odd numbered page numbers to sit outside the margin at all.

I want a smarter method as this manual approach will probably always fail - e.g. due to chapter or section title lengths changing and that sort of thing.

Any better ideas?

Below is MWE of what I've tried and some images.

\documentclass[12pt, openright]{memoir}

\usepackage{lipsum}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

%% Make headers what I want (don't say Chapter 1 chap 1 etc)
\createmark{chapter}{left}{nonumber}{}{\hspace{3mm}}
\createmark{section}{right}{shownumber}{}{\hspace{3mm}}

%% new page style
\makepagestyle{myvf}
\pagestyle{myvf}

%% line to show where page actually ends

%% attempt at header where page number exists in the margin - alternating left and right

\begin{document}

\chapter{Chap 1}

\section{sec 1}
\lipsum[1-150]\lipsum[1-150]\lipsum[1-150]

\section{sec 2}

\end{document}


Here is an easy code. All even page numbers end at the same distance from the left margin, all odd page numbers start at the same distance from the right margin.

\documentclass[12pt, openright]{memoir}

\usepackage{lipsum}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

%% Make headers what I want (don't say Chapter 1 chap 1 etc)
\createmark{chapter}{left}{nonumber}{}{\hspace{3mm}}
\createmark{section}{right}{shownumber}{}{\hspace{3mm}}

%% new page style
\makepagestyle{myvf}
\pagestyle{myvf}

%% line to show where page actually ends

%% attempt at header where page number exists in the margin - alternating left and right

\begin{document}

\chapter{Chap 1}

\section{sec 1}
\lipsum[1-150]\lipsum[1-150]\lipsum[1-150]

\section{sec 2}

\end{document}


• Why the <space> in \llap but none in \rlap? – Ruixi Zhang Aug 14 '18 at 15:55
• It was there inadvertently. I removed it. Thanks for pointing it! – Bernard Aug 14 '18 at 16:00