miligithub / MinesThesisTemplate

Mines Thesis Template: A latex template for theses and dissertations at Colorado School of Mines.
5 stars 1 forks source link

Automatic figure referencing broken #2

Open Bebotron opened 4 years ago

Bebotron commented 4 years ago

In Chapter5.tex, there are examples showing how tables with \label{tab:name} can be used with \ref{tab:name} to reference. That seems to work perfectly fine, but there is no example of doing it with figures. If you include \label{fig:somefig} and \label{fig:somefig2} to both first figures, and try to use Figure~\ref{fig:somefig} and Figure~\ref{fig:somefig2} in the main text, both reference Figure 5.1, instead of the expected Figure 5.1 and Figure 5.2.

miligithub commented 4 years ago

In Chapter5.tex, there are examples showing how tables with \label{tab:name} can be used with \ref{tab:name} to reference. That seems to work perfectly fine, but there is no example of doing it with figures. If you include \label{fig:somefig} and \label{fig:somefig2} to both first figures, and try to use Figure~\ref{fig:somefig} and Figure~\ref{fig:somefig2} in the main text, both reference Figure 5.1, instead of the expected Figure 5.1 and Figure 5.2.

@Bebotron Did you put the \label{fig:name} directly after \caption{The caption of the figure.}?

I have tried the following piece of code:

Refer Figure~\ref{fig:first} and Figure~\ref{fig:second}

\begin{landscape} % Require pdflscape and everypage packadge
    \begin{figure}[h]
        \centering
        % will generate blank page if use full  \linewidth
        \includegraphics[width=.9\linewidth]{fig3} 
        \caption{Continues figures in landscape mode. (first)}
        \label{fig:first}
    \end{figure}    

    \begin{figure}[h]
        \centering
        \includegraphics[width=\linewidth]{fig4}
        \caption{Continues figures in landscape mode. (second)}
        \label{fig:second}
    \end{figure}
\end{landscape}

and it works properly.

Bebotron commented 4 years ago

Great that fixed it! Seems a bit like unexpected behavior, but it works like a charm! Thanks!

miligithub commented 4 years ago

@Bebotron
Actually, to reference figure/table number, \lable must occur after the \caption. When declared outside, it will give the section number. To be completely safe, the label for any picture or table can go within the \caption{} command, as follows:

\caption{Close-up of a gull\label{fig:gull}}

Source: https://en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing

I have met similar problems before. I'm glad I could help.

Bebotron commented 4 years ago

Ooohh gotcha, this will save a lot of headaches in the future. Thanks!