[Tex/LaTex] Referencing figure in adjustbox

adjustboxcross-referencing

I have rotated my figure to 90 degrees using adjustbox as follows:

\begin{figure}[ht]
  \begin{adjustbox}{addcode={\begin{minipage}{\width}}{\caption{%
      My caption
      }\end{minipage}},rotate=90,center}
      \includegraphics[scale=.60]{my_figure.PNG}%
  \end{adjustbox}
  \label{fig:my_figure}
\end{figure}

Now when I want to use this figure as reference like \ref{fig:my_figure}, I am seeing ?? as the reference. I will be thankful if anyone could help me with this.

Best Answer

The \label is too far from \caption; more precisely, the caption is set inside a minipage, which forms a group, so what LaTeX sets up for being remembered along with \label is forgotten at \end{minipage}.

\begin{figure}[ht]

\begin{adjustbox}{
  addcode=
    {\begin{minipage}{\width}}
    {\caption{My caption}\label{fig:my_figure}\end{minipage}},
  rotate=90,
  center
}
\includegraphics[scale=.60]{my_figure.PNG}
\end{adjustbox}

\end{figure}
Related Question