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.

I'm running into a problem when using cleveref to refer to marginfigures in memoir. The following code illustrates the problem (apologies for the somewhat long preamble, but I need the space in the margin to illustrate the problem):

\documentclass[a4paper,10pt]{memoir}
%%% formatting
\setstocksize{29.7cm}{21.0cm} % A4 stock
\settrimmedsize{27.94cm}{21.0cm}{*} % 27.94cm = 11in
\setlength{\trimtop}{0.0cm}
\setlength{\trimedge}{\stockwidth}
\addtolength{\trimedge}{-\paperwidth}
\settypeblocksize{23.94cm}{12.3cm}{*}
\setlrmargins{2.0cm}{*}{*}
\setulmargins{2.0cm}{*}{*}
\setmarginnotes{\onelineskip}{5.28cm}{\onelineskip}
\sidecapmargin{outer}
\setsidecaps{\onelineskip}{5.28cm} 
\setsidecappos{t}
%%% clever referencing (should be loaded last)
\usepackage{cleveref}
\crefname{equation}{equation}{equations}
\Crefname{equation}{Equation}{Equations}
\crefname{figure}{figure}{figures}
\Crefname{figure}{Figure}{Figures}
%%%  
\checkandfixthelayout   
%%%   
\begin{document}
\begin{equation}\label{eq:pyth}
  a^2 + b^2 = c^2
\end{equation}  
\Cref{eq:pyth} is known as Pythagoras' theorem. 
\begin{marginfigure}
  \rule{1.0cm}{1.0cm}
  \label{fig:dummyfig}
  \caption{dummyfig1}
\end{marginfigure}
This should be a reference to figure 1, but it comes out as 
\cref{fig:dummyfig}.
\begin{equation}\label{eq:circ}
  x^2 + y^2 = r^2
\end{equation}
\begin{equation}\label{eq:ell}
  \left(\frac{x}{a}\right)^2 + \left(\frac{y}{b}\right)^2 = 1
\end{equation}
\Cref{eq:circ} describes a circle, \cref{eq:ell} an ellipse. 
\begin{marginfigure}
  \rule{2.0cm}{2.0cm}
  \label{fig:dummyfig2}
  \caption{dummyfig2}
\end{marginfigure}
This should be a reference to figure 2, but it comes out as 
\cref{fig:dummyfig2}.
\end{document}

When you run this, the references to the figures turn out as references to the equations. Do I need to tell cleveref about the marginfigure environment in some way (I could not find anything in the newest manual) or is the marginfigure not supported yet by cleveref?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

The problem is simply that you have the \label before the \caption. Put the \label last of the two, and it works fine. See e.g., Where to put the \label on a figure environment?

share|improve this answer
    
Thanks for putting me straight. This was an oversight on my part. I've been using memoir with sidecaption for so long that I completely forgot about that when I tried marginfigure. (In memoir's sidecaption environment, the label is specified as an optional argument.) –  user1362373 Nov 26 '11 at 11:20
add comment

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.