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 trying to insert a figure in a LaTeX file, but LaTeX always gives the reference number of this figure as figure 1 instead of 2, although there is already a figure 1 earlier in the document. I also can't reference this figure using ~\ref{fig:regress}. The figure number just doesn't print.

Here's the code I used to insert the image in LaTeX:

\documentclass[11pt]{article}
\usepackage{graphicx}    
\usepackage{caption}
\usepackage{subcaption}
\usepackage{chngcntr}

\begin{document}  

I'm trying to reference Figure~\ref{fig:regress} here...

\begin{figure}[htp]
        \centering
        \begin{subfigure}{0.8\textwidth}
                \centering
                \includegraphics[width=\textwidth]{im1.png}
                \caption{Scatter plot fitted with straight line}
                \label{fig:linfit}
        \end{subfigure}%

        \begin{subfigure}{0.8\textwidth}
                \centering
                \includegraphics[width=\textwidth]{im2.png}
                \caption{Scatter plot fitted with 2nd degree polynomial}
                \label{fig:quadfit}
        \end{subfigure}

\end{figure}

\newpage
\begin{figure}
\ContinuedFloat
\centering
        \begin{subfigure}{0.8\textwidth}
                \centering
                \includegraphics[width=\textwidth]{im3.png}
                \caption{Scatter plot fitted with 3rd degree polynomial} 
                \label{fig:cubicfit}
        \end{subfigure}

        \caption{Scatter plots of wavelength vs. pixel position for the spectrum from night 1, fitted with polynomials of orders 1-3.}   \label{fig:regress}
\end{figure}
\end{document}

I checked that I have \label and \caption in the right order. What's going on?

share|improve this question
    
Recently, there was a question about the very same concern. Can you look at the solution and see if it helps you? tex.stackexchange.com/a/85827/11002 –  tohecz Dec 8 '12 at 23:20
1  
Have you at least checked the log? It says ! Package caption Error: Continued `figure' after `??'. There’s no problem when adding a separate caption to the first figure environment or removing \ContinuedFloat from the second. In every instance, the second figure’s subfigure enumeration is still (c). –  Qrrbrbirlbel Dec 9 '12 at 0:28
    
I don't get that error when I run it. What confounds me even more is when I move the line \caption{Scatter plots of wavelength vs. pixel position for the spectrum from night 1, fitted with polynomials of orders 1-3.} \label{fig:regress} to just above the first subfigure, it works (except the caption is now on top of the figures). –  mcglashan Dec 9 '12 at 0:49
    
@myrthen You don’t get that because you have another figure/caption before that in your original code. –  Qrrbrbirlbel Dec 9 '12 at 1:01

1 Answer 1

up vote 7 down vote accepted

When compiling your MWE with pdflatex I get the error

! Package caption Error: Continued `figure' after `??'.

Whatever that means … (I have used neither caption nor subcaption before.)

Apparently caption is confused when you use \ContinuedFloat in a figure environment when the preceding one doesn’t had a \caption; which isn’t very surprising because there isn’t much to continue. To fix this, add a \phantomcaption to the first figure environment[See Axel Sommerfeldt's comment.]

If you do want to include a caption in the first figure environment, of course, you must not use \phantomcaption.

Code

Note that I have removed every reference to an external graphic because

  • I don’t have them.
  • I don’t need them.

I also removed \usepackage{caption}, it does get already loaded by subcaption.
The chngcntr package does not interfere with this MWE.


\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{chngcntr}
\begin{document}
\begin{figure}
  \caption{fig:before}\label{fig:before}
\end{figure}
Figure~\ref{fig:before}.

I'm trying to reference Figure~\ref{fig:regress}, subfigure~\ref{fig:linfit} and \ref{fig:quadfit} as well as \ref{fig:cubicfit} here.

\hrulefill
\begin{figure}[htp]
  \centering
  \begin{subfigure}{0.8\textwidth}
    \caption{Scatter plot fitted with straight line}
    \label{fig:linfit}
  \end{subfigure}%

  \begin{subfigure}{0.8\textwidth}
    \caption{Scatter plot fitted with 2nd degree polynomial}
    \label{fig:quadfit}
  \end{subfigure}
  \phantomcaption%                                                                                                                  either a phantom caption
%  \caption{Scatteru plots of wavelength vs. pixel position for the spectrum from night 1, fitted with polynomials of orders 1-3.}% or a real one
\end{figure}

\hrulefill
\begin{figure}[htp]
  \ContinuedFloat
  \centering
  \begin{subfigure}{0.8\textwidth}
    \caption{Scatter plot fitted with 3rd degree polynomial} 
    \label{fig:cubicfit}
  \end{subfigure}
  \caption{Scatteru plots of wavelength vs. pixel position for the spectrum from night 1, fitted with polynomials of orders 1-3.}   \label{fig:regress}
\end{figure}
\end{document}

Output

enter image description here

share|improve this answer
    
Thanks! Solved. –  mcglashan Dec 9 '12 at 3:28
1  
Unfortunately "you don’t need \ContinuedFloat" is wrong. There are some internals of the caption, subfig and subcaption package which actually will need this information, so other things can go wrong when you omit it. So better use \phantomcaption (without arguments) in the 1st figure and \ContinuedFloat in the 2nd one. (The need of \phantomcaption will be fixed in caption v3.3) –  Axel Sommerfeldt Dec 9 '12 at 8:51
    
@AxelSommerfeldt Thanks for the insight. As I wrote, I am no expert in (sub)caption and don’t know the internals. I’ve updates my answer, though. When will v3.3 come out? “The need of \phantomcaption will be fixed”? Does this mean that \ContinuedFloat works as OP expected or that it can be removed safely as in the previous revision of my answer? –  Qrrbrbirlbel Dec 10 '12 at 20:13
    
This means that \ContinuedFloat will work as the OP expected. Version v3.3 will hopefully be released within the next weeks, at least I'm just working again on it after a long pause. –  Axel Sommerfeldt Dec 11 '12 at 8:40

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.