5

How do I detect whether I'm on a left- or right-hand page?

I would like to define a custom command with a conditional statement that executes a certain command if it's on a left-hand page and another if it's on a right-hand page.

The command would be executed in the page body.

Geremia
  • 2,201
  • 1
    It would be good to know whether this command should be executed as part of the page body, or as part of a page style. – Werner Apr 15 '14 at 16:59
  • It would be great to a have a code in your post. Please try \ifodd\thepage A\else B\fi. – Malipivo Apr 15 '14 at 17:04
  • Related:http://tex.stackexchange.com/questions/6143/if-then-else-for-odd-page-even-page – cgnieder Apr 15 '14 at 17:06

2 Answers2

5

Try:

\documentclass[a4paper]{book}
\begin{document}
  ~\newpage
  \ifodd\thepage I am an odd page\else I am an even page \fi
  ~\newpage
  \ifodd\thepage I am an odd page\else I am an even page \fi
\end{document}

EDIT: If you are using roman page numbering this will work:

\documentclass[a4paper]{book}   
\begin{document}
  \pagenumbering{roman}
  ~\newpage
  \makeatletter\ifodd\c@page I am an odd page\else I am an even page \fi\makeatother
  ~\newpage
  \makeatletter\ifodd\c@page I am an odd page\else I am an even page \fi\makeatother
\end{document}
Lupino
  • 2,772
0

In ConTeXt, the standard way to define such custom commands is:

\signalrightpage % Synchronize page state
\doifrightpageelse{...if on right page...}{...if on left page...}
Aditya
  • 62,301