Referencing a subfigure in LaTeX that doesn't have a caption

15.8k views Asked by At

I have 2 figure side by side in LaTeX using the recommended package subcaption.

\begin{figure}
  \centering
  \begin{subfigure}[b]{0.48\textwidth}
    \includegraphics[width=\textwidth]{events/pad_p2}
    \label{fig:pad_p2}
  \end{subfigure}
  ~
  \begin{subfigure}[b]{0.48\textwidth}
    \includegraphics[width=\textwidth]{events/pad_p8}
    \label{fig:pad_p8}
  \end{subfigure}

  \caption{Pads.}
\end{figure}

Then I try to reference them in the text using:

Look at figure~\ref{fig:pad_p8}

But I get an error when compiling the document that the reference doesn't exist.

If instead I put a caption in each subfigure then the error goes away, but that's not what I really want to do.

How do I solve the problem without adding the caption for each subfigure?

1

There are 1 answers

1
Atanu Kumar Biswas অতনু On

Use packages

    \usepackage{graphicx}
    \usepackage{caption}
    \usepackage{subcaption}
    \usepackage{subfigure}
    \usepackage{subfloat}
    \usepackage{float}

Write code like this in proper position * for multicolumn article (if no need then use figure.

 \begin{figure*}[ht!]
        \centering
            \subfigure[] 
            {
                \label{subfig:lab1}
                \includegraphics[width=.3\textwidth]{figures/1.pdf} % .png .jpg ... according to supported graphics files
            } 
            %
            \subfigure[] 
            {
                \label{subfig:lab2}
                \includegraphics[width=.3\textwidth]{figures/2.pdf} % .png .jpg ... according to supported graphics files
            }
            %
            \subfigure[] 
            {
                \label{subfig:lab3}
                \includegraphics[width=.3\textwidth]{figures/3.pdf} % .png .jpg ... according to supported graphics files
            }\\ % for new row or line of subfigures
            %
            \subfigure[Caption 4] 
            {
                \label{subfig:lab4}
                \includegraphics[width=.3\textwidth]{figures/4.pdf} % .png .jpg ... according to supported graphics files
            }
            %
            \subfigure[Caption 5] 
            {
                \label{subfig:lab6}
                \includegraphics[width=.3\textwidth]{figures/5.pdf} % .png .jpg ... according to supported graphics files
            }
            %
            \subfigure[Caption 6] 
            {
                \label{subfig:lab6}
                \includegraphics[width=.3\textwidth]{figures/6.pdf} % .png .jpg ... according to supported graphics files 
            }
            %
        \caption{Figure Caption}
        \label{fig:Figure ref}
        \end{figure*}

enter image description here

Use just ~\ref{subfig:lab1} is subref. will show like Use just 6(a) is subref. or like that according.