0

I have written this code. All right for the figure. The question is about the references to the subfigures.

\begin{figure*}[!t]
\normalsize
    \begin{subfigure}[b]{0.48\textwidth}
        \includegraphics[width=\textwidth]{img/sigma-v} \label{fig:Pv-sigma}
        \caption{$P(v)$ trend to the vary of pole $p$.}
        \label{fig:sigma}
    \end{subfigure}%
    ~
    \begin{subfigure}[b]{0.48\textwidth}
        \includegraphics[width=\textwidth]{img/gamma-v} \label{fig:Pv-gamma}
        \caption{$\gamma(v)$ trend to the vary of pole $p$.}
        \label{fig:gamma}
    \end{subfigure}
\vspace*{-2em}
\caption{Trend of model $P(v) = \hat{q} v^\gamma$ to the vary of pole $p$ and speed $v$.}\label{fig:Pv}
\vspace*{-8pt}
\hrulefill
\vspace*{-8pt}
\end{figure*}

The results is in Fig.~\ref{fig:Pv-sigma}, Fig.~\ref{fig:Pv-gamma} e Fig.~\ref{fig:Pv}.

I obtain:

Result

There is a way for refereeing directly the figure and subfigures without refer only figure and add, by hand, a, b, c...?

NOTE I use this packages:

\documentclass[conference,a4paper]{IEEEtran}
\usepackage{spconf,amsmath,graphicx,cite}
\usepackage{epstopdf,epsfig,mathtools,caption,subcaption,amsfonts}

MISTAKES I have used a double label (as you can see in the answer).

So, the problem is not in cross-references, but in this part of code:

        \includegraphics[width=\textwidth]{img/sigma-v} %\label{fig:Pv-sigma}
        \caption{$P(v)$ trend to the vary of pole $p$.}
        \label{fig:sigma}

Where the code remarked solve the problem.

  • 1
    Why no minimal example? You would have noticed within an instance, that the labels don't match. – Johannes_B May 09 '15 at 08:36
  • Btw, your figure is too wide. .5 + .5 adds up to one, plus the additional space is more than textwidth. – Johannes_B May 09 '15 at 08:38
  • @Johannes_B, Yes, the whole figure is a bit more large of textwidth, but at left and right has same white space. Now I have set .48 + .48. Thanks. The question is not about the figure, but about the references (or the sub-references). – Giacomo Alessandroni May 09 '15 at 08:45
  • Yeah, i already said it, that labels don't match. If you label something fig:gamma you have to ref fig:gamma. – Johannes_B May 09 '15 at 08:45
  • Ah, i accidently removed your first labels because there was no mwe and includegraphics was undefined. So this is a duplicate to Put labels behind captions. – Johannes_B May 09 '15 at 08:48
  • @Johannes_B I'm not sure about that. The OP did add the label after the caption. He probably thought another one was needed to do the actual referring. – Alenanno May 09 '15 at 08:56
  • @Alenanno Yes, but this one did not match (see me first comment), fixing that would be a typo and make the question off-topic. – Johannes_B May 09 '15 at 08:58

1 Answers1

2

You're adding extra (unneeded) labels in both of your subfigure environments. For example, you had:

\begin{subfigure}[b]{0.5\textwidth}
    \includegraphics[width=\textwidth]{img/sigma-v} \label{fig:Pv-sigma}
    \caption{$P(v)$ trend to the vary of pole $p$.}
    \label{fig:sigma}
\end{subfigure}%

Remove \label{fig:Pv-sigma} so you're left with one, which is \label{fig:sigma}. Then you can successfully refer to that. Same goes for the other label, of course.

So in the end you can write the following:

The results are in Fig.~\ref{fig:sigma}, Fig.~\ref{fig:gamma} and Fig.~\ref{fig:Pv}.

figure 1

Alenanno
  • 37,338
  • @GiacomoAlessandroni Ahah no problem. :D By the way, if your document is in English, take note of the changes I made. (It probably was in Italian and you switched to English for the question, though.) – Alenanno May 09 '15 at 08:55