0

Obviously, TeX does know the horizontal position of the paragraphs on the paper. It is what geometry calls left. How can I access it?

I suspect there is (or one can define) a simple length register, let's call it \realleftmargin that holds the total left margin of the current page (regardless if odd or even). Preferably without having to deal with too many geometry.sty internals, \ifodd\thepage, and expansion sequences.

My content (floats/figures) has full paper width. I want to have it span the physical paper, so that my margin definitions and odd/even pages cannot cut content at the boundaries. It's fine, too, if you come up with another strategy than preceding my graphics with \hspace*{-\realleftmargin}.

My findings so far:

  • Full-width figure, odd/even pages + margin asks a similar question with memoir (I'm on standard LaTeX/KOMA/geometry)
  • \Gm@lmargin/\Gm@rmargin on even/odd pages hold the right lengths, but discerning between those two is seemingly non-fundamental.
  • note that floats are typeset before they are allocated to a page so you can not simply ask for the margin, I have an answer that handles some cases, I'll see if I can find.... – David Carlisle Sep 20 at 19:27
  • you could use the same technique as this answer although that is testing for top and bottom rather than left and right, but the same issues arise as the test needs to be after the float is positioned. – David Carlisle Sep 20 at 19:33
  • It should be (on odd numbered pages) \dimexpr 1in+\hoffset+\oddsidemargin\relax. – Bernard Sep 20 at 22:15
0

I hope that this will get you going. In the following I have used the changepage package to adjust the contents of a figure environment depending on whether the figure ends up on an odd or even page.

% figpageprob.tex  SE 509111  Is figure on even or odd page
\documentclass{book}
\usepackage{changepage}
  \strictpagecheck
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{figure}
\checkoddpage
\ifoddpage
    FIGURE ON ODD PAGE
\else
\raggedleft    FIGURE ON EVEN PAGE
\fi
\caption{A figure}
\end{figure}

\lipsum[1]

\begin{figure}
\checkoddpage
\ifoddpage
    FIGURE ON ODD PAGE
\else
\raggedleft    FIGURE ON EVEN PAGE
\fi
\caption{A figure}
\end{figure}

\lipsum[1]

\begin{figure}
\checkoddpage
\ifoddpage
    FIGURE ON ODD PAGE
\else
\raggedleft    FIGURE ON EVEN PAGE
\fi
\caption{A figure}
\end{figure}

\lipsum[1]

\begin{figure}
\checkoddpage
\ifoddpage
    FIGURE ON ODD PAGE
\else
\raggedleft    FIGURE ON EVEN PAGE
\fi
\caption{A figure}
\end{figure}

\lipsum[1]

\begin{figure}
\checkoddpage
\ifoddpage
    FIGURE ON ODD PAGE
\else
 \raggedleft   FIGURE ON EVEN PAGE
\fi
\caption{A figure}
\end{figure}

\lipsum[1]

\begin{figure}
\checkoddpage
\ifoddpage
    FIGURE ON ODD PAGE
\else
\raggedleft    FIGURE ON EVEN PAGE
\fi
\caption{A figure}
\end{figure}

\lipsum[1]

\begin{figure}
\checkoddpage
\ifoddpage
\raggedright    FIGURE ON ODD PAGE
\else
\raggedleft    FIGURE ON EVEN PAGE
\fi
\caption{A figure}
\end{figure}

\lipsum[1]

\end{document}

On the first run through all figure are assumed to be on even pages. On the second run through the figures know on which pages they are printed and their contents are adjusted accordingly.

The values that your document takes for the lefthand margin depend on the class you are using and any packages that affect the page layout. You can use the layouts package to determine the margins if you don't know them otherwise.

You could define a macro along the lines of (less any typos and adding in extra bits):

\newlength{\mylength}
\newcommand*{\mymacro}{%
  \checkoddpage
  \ifoddpage
    \setlength{\mylength}{<oddleftmargin>}
  \else
    \setlength{\mylength}{<evenleftmargin>}
  \fi}

and use it like

\begin{figure}
\mymacro
% adjust the figure location by \mylength
%
\end{figure}

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.