lunedì 26 ottobre 2015

Incorrect reference to figure: the role of caption and centering

Recently I wrote a document structured mostly as a bullet point and with a lot of figures.
Everything went fine except that occasionally the figures would be referred with the wrong number, altough no mistake was made in the code.
A part the already known problem of putting the label -after- the caption, it turned out that the responsable was also the \centering, by somehow messing up with the labeling system.
The solution is to use the center environment as a replacement of \centering (here demonstrated with multiple figures):

\begin{figure}[!ht]
\begin{center}
\subfigure[]{
\includegraphics[width = 0.4\textwidth]{figures/ImageA.JPG}}%
\subfigure[]{
\includegraphics[width = 0.4\textwidth]{figures/ImageB.JPG}}%
\\
\subfigure[]{
\includegraphics[width = 0.4\textwidth]{figures/ImageC.JPG}}%
\subfigure[]{
\includegraphics[width = 0.4\textwidth]{figures/ImageD.JPG}}%
\caption{Some caption.}
\end{center}
\label{SomeLabel}
\end{figure}

Problem solved!

Nessun commento:

Posta un commento

Il tuo commento sarà pubblicato appena il moderatore avrà accertato il suo contenuto

Grazie mille :)