I want to have captions on the sides of figures. I am using the book document class and would like one side of the figure flush with the inner text margin, with the caption extending into the margin on the other side. I have found that the response to the question Caption on the side of a figure by Igor Kotelnikov is just about what I need:
\begin{figure}
\begin{minipage}[c]{0.67\textwidth}
\includegraphics[width=\textwidth]{2011-03-03}
\end{minipage}\hfill
\begin{minipage}[c]{0.3\textwidth}
\caption{
Температура перехода в ионизованное состояние
атомарного водорода в зависимости от плотности газа.
} \label{fig:03-03}
\end{minipage}
\end{figure}
but I would like a way to automate the process of figuring out if the figure is on an even or odd page and changing the order of the two minipages accordingly so that the caption is always on the outer side (left side on even pages and right side on odd pages). I tried using the \ifoddpage command from the changepage package, but found that it acted according the the page where the command was called from, not where the figure ended up being placed.
Does anybody have an idea how to go about this? Here is an MWE to demonstrate the effect I am going for:
\documentclass{book}
\usepackage{graphicx}
\usepackage{float}
\begin{document}
\begin{figure}[H]
\begin{minipage}[t]{0.8\textwidth}
\vspace{0pt}
\includegraphics[width=0.8\textwidth]{fig}
\end{minipage}%
\begin{minipage}[t]{0.5\textwidth}
\vspace{0pt}
\caption{This is the caption which appears on the right side of the figure}
\end{minipage}\hspace{-0.2cm}%
\end{figure}
\newpage
\begin{figure}[H]
\hspace{-\marginparwidth}
\begin{minipage}[t]{0.6\textwidth}
\vspace{0pt}
\caption{This is the caption which appears on the left side of the figure}
\end{minipage}
\begin{minipage}[t]{0.8\textwidth}
\vspace{0pt}
\includegraphics[width=0.8\textwidth]{fig}
\end{minipage}
\end{figure}
\end{document}
\ifthispageoddfrom packagescrextend. Or you can switch to KOMA-Script classscrbookand usecaptionbesideenvironment. – Schweinebacke Oct 20 '17 at 16:25changepageto know how to make strict page checks with\checkoddpage. – Schweinebacke Oct 20 '17 at 16:38