1

Does anyone know how to left align section headings (so \raggedright) when they are on even pages (the normal behaviour for documents) but also to right align (so \raggedleft) them on odd pages (what I've shown in the MWE below)?

I've put a picture of the two pages of code below with an arrow showing what I want added to it.

I know \renewcommand\chapnamefont{\huge\bfseries\raggedleft} puts all section headings to the right of the page - but I need them to alternate on even and odd pages. I read somewhere this is easier in memoir than in the book class but I can't even begin to guess how to do it. Very new to memoir!

Thanks for any advice you may have.

\documentclass[12pt, openright]{memoir}

\usepackage{lipsum}

%% chapter always aligns right which is fine as chapters only appear on odd numbered pages
\renewcommand\chapnamefont{\huge\bfseries\raggedleft}

%% I want even page sections to be \raggedright and viceversa so they will match the headers (not shown in this MWE)

\setsecheadstyle{\large\bfseries\raggedleft} 

\begin{document}

\chapter{Name of chapter 1}
\section{sec 1}
\clearpage
\section{sec 2}


\end{document}

Page 1 = fine

How do I do this?

1

Disclaimer - I realise your question is about how to implement this using the memoir class, which has its own built in tools which match the functionality of packages like titlesec. But, until someone posts a memoir solution, here is a way to do it using titlesec.

\documentclass[12pt, openright]{memoir}
\usepackage{showframe} %<---- Just for testing

%% chapter always aligns right which is fine as chapters only appear on odd numbered pages
\renewcommand\chapnamefont{\huge\bfseries\raggedleft}

\usepackage{titlesec}
\titleformat{name=\section,page=odd}{\large\bfseries\raggedleft}{\thesection}{1em}{}
\titleformat{name=\section,page=even}{\large\bfseries\raggedright}{\thesection}{1em}{}

\begin{document}

\chapter{Name of chapter 1}
\section{sec 1}
\clearpage
\section{sec 2}

\end{document}

enter image description here

enter image description here

1

You are almost there --- use memoir's \checkoddpage macro. In your memoir preamble put:

% \strictpagecheck % uncomment if problems at new pages
\newcommand{\oddright}{\checkoddpage\ifoddpage\raggedleft\fi}
\setsecheadstyle{\oddright\Large\bfseries}

If you want a similar effect for \subsection then add

\setsubsecheadstyle{\oddright\large\bfseries}

See sections 18.12 and 6.6 in the manual (> texdoc memoir) for further information about odd/even page checking and changing the style of sectional headings.

  • Thanks - this is the answer I was looking for. I knew there'd be a memoir specific way of doing it. Cheers. – mr_phd Aug 14 '18 at 11: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.