I need to make all the sections of a certain chapter of my document (a book) appear in an odd page. Any ideas?
2 Answers
Here you have two solutions. The first one defines a new command \mysection
; the second one automates the procedure thanks to etoolbox
, but requires a conditional at the opening and one at the end of the chapter in which the sections must appear on an odd page. Here is a mwe:
\documentclass{book}
\usepackage{lipsum}
% first solution
\makeatletter
\newcommand{\mysection}[1]{%
\ifnum\value{section}=0\relax
\else
\cleardoublepage
\fi
\section{#1}}
\makeatother
% second solution
\usepackage{etoolbox}
\newif\ifoddsections
\pretocmd{\section}{
\ifoddsections
\ifnum\value{section}=0\relax
\else
\cleardoublepage
\fi
\else
\fi}{}{}
\begin{document}
\chapter{With a new section command}
\mysection{The first section of the chapter}\lipsum[1-6]
\mysection{A section starting on an odd page}
\mysection{A section starting on an odd page}
\chapter{With a conditional}
\oddsectionstrue
\section{The first section of the chapter}\lipsum[1-6]
\section{A section starting on an odd page}
\section{A section starting on an odd page}
\oddsectionsfalse
\chapter{A normal chapter with sections on even or odd pages}
\section{The first section of the chapter}\lipsum[1-6]
\section{A section starting on an odd page}
\section{A section starting on an odd page}
\end{document}
-
I think if you change your first version to end with
\fi\section}
, then you could drop the[1]
argument and have it still work with\section*
.– TeepeemmFeb 5, 2021 at 22:34 -
Doesn't work for me.. some sections appear in an even page, despite using the conditional or \mysection Feb 5, 2021 at 23:36
-
Ok, I did not fully understand your question... I edited my answer: now every section, except for the first, starts in an odd page.– IvanFeb 6, 2021 at 2:01
-
@Ivan Thanks a lot, it works now! But for future people looking at this, I think you forgot to edit the title of your sections. Second and third should say "A section command on an odd page". And the first one I guess it depends of where the chapter starts. Feb 6, 2021 at 17:04
-
I assume you want the sections to start the page, and not start halfway down an odd page? If there's not too many sections, you could just put \cleardoublepage
before all of them. A higher level approach would be etoolbox's \pretocmd{\section}{\cleardoublepage}{}{}
, appropriately localized. But that might also run into trouble, since \section
does some weird stuff.