TransWikia.com

Query left margin of page

TeX - LaTeX Asked by H. Weirauch on April 4, 2021

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, ifoddthepage, 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.

One Answer

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}

Answered by Peter Wilson on April 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP