0

trying to refer to a whole figure results in ?? but referring to each individual subfigure works fine. How can I fix this? I wish to refer to fig. 1 in the example below. Example image

MWE:

\documentclass[12pt, a4paper]{article}
\usepackage{pgfplots}
\usepackage{psfrag}
\usepackage{subfig}
\pgfplotsset{compat=1.5}
\usepackage{cleveref}
\begin{document} 
\begin{figure}[hb]
    \centering
    \begin{tabular}{ccc}
        \multicolumn{3}{c}{\begin{tikzpicture}
            \begin{axis}[
            at={(-3,-0.5)},
            hide axis,
            scale only axis,
            height=0pt,
            width=15cm,
            colormap/jet,
            colorbar horizontal,
            colorbar style={ylabel=dB},
            point meta min=-20,
            point meta max=0,
            ]
            \end{axis}
            \end{tikzpicture}}\\
        \subfloat[][]{\label{fig:sub-a}\includegraphics[width=5cm]{example-image-a}}
        &
        \subfloat[][]{\label{fig:sub-b}\includegraphics[width=5cm]{example-image-b}}
        &
        \subfloat[][]{\label{fig:sub-c}\includegraphics[width=5cm]{example-image-c}}\\
    \end{tabular}
    \label{fig:subs}
    \caption{}
\end{figure}
\Cref{fig:subs} isn't working but \cref{fig:sub-a,fig:sub-b,fig:sub-c} is.
\end{document}
BenK-G
  • 77
  • I didn't realise that the issue was the placement of the \label command. Now that has been pointed out it is easier to see what the solution is. – BenK-G Jul 19 '16 at 08:24

1 Answers1

1

Place the \label{fig:subs} after \caption{} which will fix the problem.

\documentclass[12pt, a4paper]{article}
\usepackage{pgfplots}
\usepackage{psfrag}
\usepackage{subfig}
\pgfplotsset{compat=1.5}
\usepackage{cleveref}
\begin{document} 
\begin{figure}[hb]
    \centering
    \begin{tabular}{ccc}
        \multicolumn{3}{c}{\begin{tikzpicture}
            \begin{axis}[
            at={(-3,-0.5)},
            hide axis,
            scale only axis,
            height=0pt,
            width=15cm,
            colormap/jet,
            colorbar horizontal,
            colorbar style={ylabel=dB},
            point meta min=-20,
            point meta max=0,
            ]
            \end{axis}
            \end{tikzpicture}}\\
        \subfloat[][]{\label{fig:sub-a}\includegraphics[width=5cm]{example-image-a}}
        &
        \subfloat[][]{\label{fig:sub-b}\includegraphics[width=5cm]{example-image-b}}
        &
        \subfloat[][]{\label{fig:sub-c}\includegraphics[width=5cm]{example-image-c}}\\
    \end{tabular}
    \caption{}
    \label{fig:subs}
\end{figure}
\Cref{fig:subs} isn't working but \cref{fig:sub-a,fig:sub-b,fig:sub-c} is.
\end{document}
Jagath
  • 4,287