3

I am looking for a command or environment that flushes / aligns what follows towards the inner side of the page. (Of course, this only makes sense for double-sided documents.) More specifically, I'd like to align my figures at the inner edge of the side.

Does such a command or environment exist?

MWE:

\documentclass[a4paper, draft]{scrbook}
\usepackage{todonotes}

\begin{document}
    
    \begin{figure}
        %\begin{flushinner} ??
            \missingfigure[figwidth=6cm, figheight=15cm]{}
        %\end{flushinner}
        \caption{This figure should be aligned to the left because it is on a "right page"}
    \end{figure}
    
    \begin{figure}
        %\begin{flushinner} ??
            \missingfigure[figwidth=6cm, figheight=15cm]{}
        %\end{flushinner}
        \caption{This figure should be aligned to the right because it is on a "left page"}
    \end{figure}

\end{document}
4
  • This is not directly possible as the figure is typeset before it is known which page it is on. but you can test if a \pageref to the figure is odd or even so choose left or right alignment on a later run Commented Dec 3, 2021 at 14:52
  • Well, KoMa classes have a \ifthispageodd check but this won't work in this case because \missingfigure starts a new paragraph. In fact, nothing will work with \missingfigure, but it should work with real figures.
    – campa
    Commented Dec 3, 2021 at 15:09
  • @campa Haha thanks, I was just beginning to struggle with the \missingfigure ^_^
    – Eike P.
    Commented Dec 3, 2021 at 15:16
  • See also the ifoddpage package. Commented Dec 3, 2021 at 16:23

2 Answers 2

1

The KoMa classes provide \ifthispageodd (it uses labels, so it requires multiple runs to work).

\documentclass[a4paper,draft]{scrbook}

\usepackage{graphicx}

\begin{document}
    
    \begin{figure}
    \ifthispageodd{\ignorespaces}{\hfill}
    \includegraphics[width=6cm,height=15cm]{example-image-a}
    \caption{This figure should be aligned to the left because it is on a recto page. Text text text.}
    \end{figure}
    
    \begin{figure}
    \ifthispageodd{\ignorespaces}{\hfill}
    \includegraphics[width=6cm,height=15cm]{example-image-b}
    \caption{This figure should be aligned to the right because it is on a verso page. Text text text.}
    \end{figure}

\end{document}

enter image description here

1
  • Thanks! \hfill / \ignorespaces also seems more elegant than flushright / flushleft. :-)
    – Eike P.
    Commented Dec 3, 2021 at 15:21
0

Thanks to David Carlisle and campa, here's a working solution:

\documentclass[a4paper]{scrbook}
\usepackage{graphicx}

\newenvironment{flushinner}{
        \ifthispageodd{
            \begin{flushleft}
        }{
            \begin{flushright}
        }
    }{
        \ifthispageodd{
            \end{flushleft}
        }{
            \end{flushright}
        }
}

\begin{document}
    
    \begin{figure}
        \begin{flushinner}
            \includegraphics[height=15cm]{some-figure}
        \end{flushinner}
        \caption{This figure should be aligned to the left} 
    \end{figure}
    
    \begin{figure}
        \begin{flushinner}
            \includegraphics[height=15cm]{some-figure}
        \end{flushinner}
        \caption{This figure should be aligned to the right}
    \end{figure}

\end{document}

You must log in to answer this question.

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