0

I want caption justification to behave differently for even and odd pages in a twoside document.

Consider the following MWE where I use packages caption and floatrow to achieve figure captions in the page margin.

\documentclass[twoside]{article}
\usepackage[demo]{graphicx}
\usepackage{showframe}
\usepackage[singlelinecheck=false]{caption}
\usepackage{floatrow}
\usepackage[strict]{changepage}

\floatsetup{margins=hangoutside,capposition=beside,
capbesideposition={top,outside},floatwidth=\textwidth,facing=yes}

\newcommand\rightlast{\leftskip0ptplus1fil
\rightskip0ptplus-1fil\parfillskip0ptplus1fil}
\DeclareCaptionJustification{rightlast}{\rightlast}

\ifoddpage
\captionsetup[capbesidefigure]{labelsep=newline,labelfont=bf,justification=justified}
\else
\captionsetup[capbesidefigure]{labelsep=newline,labelfont=bf,justification=rightlast}
\fi

\begin{document}
\
\clearpage
\begin{figure}[h]
\caption{test1}
\includegraphics[]{demo}
\end{figure}
\clearpage
\begin{figure}[h]
\caption{test2}
\includegraphics[]{demo}
\end{figure}
\end{document}

The normal behaviour is justified so from the floatrow manual I used the newcommand rightlast to make the even(left) margin caption be next to the body text.

By using the changepage package I tried to check if a page is odd and use justified or even and use rightlast but it is not working like I expected.

I now get this: enter image description here

What I want is this: enter image description here

1
  • 1
    First of all, you need \checkoddpage and \ifoddpage in each float (especially if they actually float to a new page). OTOH, placing \captionsetup inside the float seems to have no effect (as opposed to the preamble). Mar 1, 2022 at 16:57

1 Answer 1

1

I moved the odd page check to inside \rightlast.

\documentclass[twoside]{article}
\usepackage[demo]{graphicx}
\usepackage{showframe}
\usepackage[singlelinecheck=false]{caption}
\usepackage{floatrow}
\usepackage[strict]{changepage}

\floatsetup{margins=hangoutside,capposition=beside,
capbesideposition={top,outside},floatwidth=\textwidth,facing=yes}

\newcommand\rightlast{\checkoddpage
\ifoddpage\else
  \leftskip0ptplus1fil
  \rightskip0ptplus-1fil\parfillskip0ptplus1fil
\fi}
\DeclareCaptionJustification{rightlast}{\rightlast}

\captionsetup[capbesidefigure]{labelsep=newline,labelfont=bf,justification=rightlast}

\begin{document}
\
\clearpage
\begin{figure}[h]
\caption{test1}
\includegraphics[]{demo}
\end{figure}
\clearpage
\begin{figure}[h]
\caption{test2}
\includegraphics[]{demo}
\end{figure}
\end{document}
1
  • Simple yet so hard to think of sometimes!
    – eliasf
    Mar 1, 2022 at 19:32

You must log in to answer this question.

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