[Tex/LaTex] How to reference figure*’s subfigure?

cross-referencingfloatssubfloats

I'm writing a paper to submit a conference.

However, I am having some problems fixing non-resolved references in latex.

\begin{figure*}[ht!]

\begin{subfigure}[b]{0.3\linewidth}

    \includegraphics[width=1\linewidth]{fig/toy}

    \vspace*{-1cm} % for cosmetic change

    \label{fig:toynetwork_example}

    \caption{A toy network}

\end{subfigure}%

\begin{subfigure}[b]{0.3\linewidth}

    \includegraphics[width=1\linewidth]{fig/exampleProcedure13}

    \vspace*{-1cm} % for cosmetic change

    \label{fig:firstIterationFin}

    \caption{After first iteration}

\end{subfigure}

\begin{subfigure}[b]{0.3\linewidth}

    \includegraphics[width=1\linewidth]{fig/proposed_adjacency_matrix}

    \vspace*{-0.4cm} % for cosmetic change

    \label{fig:proposed_adjacency_matrix}

    \caption{Adjacency matrix}

\end{subfigure}%

\begin{subfigure}[b]{0.3\linewidth}

    \includegraphics[width=1\linewidth]{fig/proposed_influence_matrix}

    \vspace*{-0.4cm} % for cosmetic change

    \label{fig:proposed_influence_matrix}

    \caption{Influence matrix}

\end{subfigure}%

    \hspace*{0.2cm}

\vspace*{0.3cm} % for cosmetic change

\begin{subfigure}[b]{0.3\linewidth}

    \includegraphics[width=1\linewidth]{fig/proposed_update_order}

    \vspace*{-0.4cm} % for cosmetic change

    \label{fig:proposed_update_order}

    \caption{Update order}

\end{subfigure}%

\caption{Example network}

\label{fig:example_network_procedure}

\end{figure*}

The PDF file shows ?? rather than the reference.

Can you help me?

enter image description here

Best Answer

The \label must go after or inside the \caption command. It cannot be placed before. This is because \caption increments the relevant counter, which is what \label hooks onto. If you put the \label first, there is nothing onto which it might hook.

For example, turning your code into a (semi-)Minimal Working Example by adding a preamble and substituting standard images:

labelled subfigures

Code:

\documentclass{article}
\usepackage{graphicx,subcaption}

\begin{document}

\ref{fig:example_network_procedure}
\ref{fig:firstIterationFin}
\ref{fig:proposed_adjacency_matrix}
\ref{fig:proposed_influence_matrix}
\ref{fig:proposed_update_order}
\ref{fig:toynetwork_example}

\begin{figure*}[ht!]
  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=1\linewidth]{example-image-a}

    \caption{A toy network\label{fig:toynetwork_example}}
  \end{subfigure}
  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=1\linewidth]{example-image-a}

    \caption{After first iteration}\label{fig:firstIterationFin}
  \end{subfigure}
  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=1\linewidth]{example-image-a}

    \caption{Adjacency matrix}\label{fig:proposed_adjacency_matrix}
  \end{subfigure}

  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=1\linewidth]{example-image-a}

    \caption{Influence matrix\label{fig:proposed_influence_matrix}}
  \end{subfigure}
  \begin{subfigure}[t]{0.3\linewidth}
    \includegraphics[width=1\linewidth]{example-image-a}

    \caption{Update order}\label{fig:proposed_update_order}
  \end{subfigure}

  \caption{Example network}
  \label{fig:example_network_procedure}
\end{figure*}

\end{document}
Related Question