3

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?

jbssm
  • 6,861
  • 13
  • 54
  • 81
  • 1
    First of all, it's not a compilation *error*. It's just a *warning* that the `\ref`erence doesn't exist. What would have expected the `\ref`erence to return anyway? Note that the reader wouldn't be able to find any corresponding numbering if it doesn't exist... so it seems weird to request something when you don't put it there in the first place. – Werner May 27 '16 at 09:24
  • I expected it to return the reference to the all figure construct. So instead of 5b for the right side figure, it would just refer to 5. I know I can do that just by putting a label in the figure construct, but if later I need to change anything it becomes complicated that way. – jbssm May 27 '16 at 10:51
  • If your structure is such that you will *never* use numbered subfigures, then one can update the way `\label` works inside a `subfigure` environment. The only way you can get the correct reference, is if you place content *after* a `\caption`, as the `\caption` steps the associated counter and sets the correct reference. – Werner May 27 '16 at 18:09
  • Will http://tex.stackexchange.com/questions/16625/subfigure-how-to-eliminate-a-b help... though you need to use different package. – novice Jun 03 '16 at 13:25
  • You should at least put an empty caption – Cyriac Antony Jul 21 '19 at 09:01

1 Answers1

-1

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.