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.
\begin{figure}
 \begin{adjustbox}{addcode={\begin{minipage}{\width}}{\caption[bla]
{%
bla ..., fig. \protect\ref{fig:fig1}, ...bla.
  }
\end{minipage}}}
\includegraphics[scale=1]{figure.png}
\end{adjustbox}
\label{fig:fig2}
\end{figure}

For some reason the referencing to \ref{fig.fig1} does not work inside the caption of fig.2

share|improve this question

migrated from stackoverflow.com Oct 20 '12 at 16:54

This question came from our site for professional and enthusiast programmers.

2 Answers 2

The caption package allows you to specify a \caption width (using \captionsetup{width=<len>}), rather than including it in an adjustbox-minipage the way you're doing at the moment. Here's a small example:

enter image description here

\documentclass{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
\usepackage{caption}% http://ctan.org/pkg/caption
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\begin{figure}
  \centering\includegraphics[width=.5\textwidth]{example-image-a}% http://ctan.org/pkg/mwe
  \caption{\protect\lipsum*[66]}
\end{figure}
\captionsetup{width=.7\textwidth}
\begin{figure}
  \centering\includegraphics[width=.5\textwidth]{example-image-b}% http://ctan.org/pkg/mwe
  \caption{\protect\lipsum*[66]}
\end{figure}
\end{document}
share|improve this answer

Not discussing your adjustbox/minipage solution here, Werner already mentioned

[T]he caption package allows you to specify a \caption width (using \captionsetup{width=<len>}), rather than including it in an adjustbox minipage the way you're doing at the moment.

Either way, here is a solution, that does work. Also provided is the usage of \newenvironment to make your life a little bit easier.

Minimal working example (MWE) I

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{adjustbox}
\begin{document}
\begin{figure}
 \begin{adjustbox}{addcode={%
  \begin{minipage}{\width}
 }{
  \caption[Short Caption]{Similar to Figure \ref{fig:fig2}}\label{fig:fig1}
  \end{minipage}
 }
 }
\includegraphics[scale=1]{figure.png}
\end{adjustbox}
\end{figure}
\begin{figure}
 \begin{adjustbox}{addcode={%
  \begin{minipage}{\width}
 }{
  \caption[Short Caption]{Similar to Figure \ref{fig:fig1}}\label{fig:fig2}
  \end{minipage}
 }
 }
\includegraphics[scale=1]{figure.png}
\end{adjustbox}
\end{figure}
\end{document}

MWE II

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{adjustbox}

\newenvironment{adjustboxwithstuff}[1]{\begin{adjustbox}{addcode={\minipage{\width}}{#1\endminipage}}}{\end{adjustbox}}

\begin{document}
\begin{figure}
    \begin{adjustboxwithstuff}{\caption[Short Caption]{Similar to Figure \ref{fig:fig2}}\label{fig:fig1}}
        \includegraphics[scale=1]{figure.png}
    \end{adjustboxwithstuff}
\end{figure}

\begin{figure}
    \begin{adjustboxwithstuff}{\caption[Short Caption]{Similar to Figure \ref{fig:fig1}}\label{fig:fig2}}
        \includegraphics[scale=1]{figure.png}
    \end{adjustboxwithstuff}
\end{figure}

Output

Output

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.