5

I'd like to put:

  • some text on the outer side of the page,
  • some another text on the inner side of the page.

For this, I make use of the (\checkoddpage) \ifoddpage test provided by the changepage package. That works pretty well, except if it turns out that there isn't enough space left on the current page where the code is inserted, as pointed out by the following MWE (the first two are okay, not the last two).

\documentclass{book}
\usepackage[inner=10mm,outer=30mm]{geometry}
\usepackage[strict]{changepage}

\newcommand{\onouterside}{%
  \begin{minipage}[t]{0.3\linewidth}
    Some text supposed to be on the outer side.
  \end{minipage}
}
\newcommand{\oninnerside}{%
  \begin{minipage}[t]{0.75\linewidth}
    Some text supposed to be on the inner side.
  \end{minipage}
}
\newcommand{\test}{%
  \checkoddpage%
  \ifoddpage%
  \oninnerside
  \hspace*{11mm}%
  \onouterside
  \else%
  \hspace*{-20mm}%
  \onouterside
  \hspace*{11mm}%
  \oninnerside
  \fi%
}
\begin{document}
\test
\newpage
\test
\newpage
\rule{0.4pt}{.969\textheight}\par
\test
\newpage
\mbox{}
\newpage
\rule{0.4pt}{.969\textheight}\par
\test
\end{document}

How could I make the odd/even page test robust? Should I get the vertical space of the texts and compare it to the vertical space left on the current page and, if so, how could I know the latter one?

1 Answer 1

6

Beware doing anything on the main vertical list:-)

This does the test in horizontal mode where things are safer.

\documentclass{book}
\usepackage[inner=10mm,outer=30mm]{geometry}
\usepackage[strict]{changepage}

\newcommand{\onouterside}{%
  \begin{minipage}[t]{0.3\linewidth}
    Some text supposed to be on the outer side.
  \end{minipage}
}
\newcommand{\oninnerside}{%
  \begin{minipage}[t]{0.75\linewidth}
    Some text supposed to be on the inner side.
  \end{minipage}
}
\newcommand{\test}{%
  \mbox{}\checkoddpage%
  \ifoddpage%
  \oninnerside
  \hspace*{11mm}%
  \onouterside
  \else%
  \hspace*{-20mm}%
  \onouterside
  \hspace*{11mm}%
  \oninnerside
  \fi%
}
\begin{document}
\test
\newpage
\test
\newpage
\rule{0.4pt}{.969\textheight}\par
\test
\newpage
\mbox{}
\newpage
\rule{0.4pt}{.969\textheight}\par
\test
\end{document}
2
  • Just this tiny \mbox{} makes such a difference: wow! :) Feb 15, 2015 at 10:16
  • 1
    @DenisBitouzé the test was accurately detecting page 3 (odd) but then a page break was getting in before your minipage, this way the paragraph starts so the \label used for the page testing is tied to the same line as the minipage and you can not have a linebreak (and so can not have a pagebreak) after the \label, so the page break happens before the test so it detects page 4. Feb 15, 2015 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .