Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For small figures, I want for captions to go on the right or on the left depending on the page number, whether it is odd or even. To do that I define the command \row as follows:

\newcommand{\row}[2]{%
    \ifodd\value{page}
        #2 \hfil #1
    \else
        #1 \hfil #2
    \fi
}

Typically, it is used inside the figure environment, for example,

\begin{figure}
\row{%
  \begin{minipage}[c]{0.67\textwidth}
    \includegraphics[width=\textwidth]{2011-03-03}
  \end{minipage}%
}{%
  \begin{minipage}[c]{0.3\textwidth}
    \caption{The transition temperature vs. density of the hydrogen} 
    \label{fig:03-03}
  \end{minipage}}
\end{figure}

This works as desired in most cases, however, sometimes, placement of the caption goes wrong. I wonder why? And how to modify my code to avoid troubles?

share|improve this question
    
Please be a bit more specific about the circumstances under which "placement of the caption goes wrong." E.g., does it happen if there are multiple floats on a page? Does it only happen on verso (even-numbered) or on recto (odd-numbered) pages? –  Mico Apr 27 '12 at 13:30
    
@Igor I wrote a solution for this at tex.stackexchange.com/a/45855/963 –  Yiannis Lazarides Apr 27 '12 at 18:54
    
@Mico: unfortunetly I cannot at the moment specify condition when my code fails. –  Igor Kotelnikov Apr 28 '12 at 7:13

2 Answers 2

up vote 11 down vote accepted

You can use the refcount package:

\usepackage{refcount}
\newcounter{figureposcount}
\newcommand{\row}[2]{%
  \refstepcounter{figureposcount}\label{figurepos\thefigureposcount}%
  \ifodd\getpagerefnumber{figurepos\thefigureposcount}
    #2 \hfil #1%
  \else
    #1 \hfil #2%
  \fi
}

However you could also consider the sidecap package that does what you want without a special syntax (apart using SCfigure instead of figure).

share|improve this answer
    
Every answers given above are good. I have accepted this one because refcount package was already installed on my computer :) and because actually I expected something like this: set a label, convert \pageref to a number an so on. –  Igor Kotelnikov Apr 28 '12 at 8:20

Due to the asynchronous nature of the output routine, the page counter isn't reliable. Use, e.g., the scrextend package and its \ifthispageodd macro instead.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.