How to refer sub-figures without using captions
Asked Answered
S

4

6

Figure explaining what i want to do exactly

I am using the following code to add figures in main body of the text. I need to ref figures in main body like Fig 1a, Fig 2a. but i dont want to add caption of figure 1a when adding the figure in latex code.

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

\begin{figure}[!h]
\begin{subfigure}{0.5\textwidth}  
  \caption{``Conversation Starter'' of March}
  \label{fig:csmarch}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
  \caption{``Conversation Starter'' of April}
  \label{fig:csapril}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
  \caption{``Conversation Starter'' of May}
  \label{fig:csmay}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
  \caption{``Conversation Starter'' of June}
  \label{fig:csjune}
\end{subfigure} 
\begin{subfigure}{.5\textwidth}
  \caption{``Conversation Starter'' of July}
  \label{fig:csjuly}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
  \caption{``Conversation Starter'' of the \#NigeriaDecides}
  \label{fig:csds}
\end{subfigure}
Sapphira answered 3/2, 2018 at 8:43 Comment(0)
S
12

The subcaption package provides \phantomsubcaption for this kind of problem. From the manual:

If you don’t want to give a sub-figure a caption, because the picture itself already contains the caption, or for some other reason, you can use the command \phantomsubcaption instead of \subcaption, or – when inside a subfigure or subtable environment – \phantomcaption instead of \caption. \phantomsubcaption and \phantomcaption do not have any arguments, and they do not generate any output, but give you an anchor for a \label command which can be placed afterwards. Furthermore it increases the sub-figure resp. sub-table counter.

MWE:

\documentclass{article}
\usepackage{mwe}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}
    
    Hello world! I am referencing to figures \ref{fig:a}, \ref{fig:b}, \ref{fig:c} and \ref{fig:img}.
    
\begin{figure}
    \begin{subfigure}{0.45\textwidth}
        \centering
        \includegraphics[width=\linewidth]{example-image-a}
        \phantomsubcaption
        \label{fig:a}
    \end{subfigure}
\hfill
    \begin{subfigure}{.45\textwidth}
        \centering
        \includegraphics[width=\linewidth]{example-image-b}
        \phantomsubcaption
        \label{fig:b}
    \end{subfigure}
\\
    \begin{subfigure}{.45\textwidth}
        \centering
        \includegraphics[width=\linewidth]{example-image-c}
        \phantomsubcaption
        \label{fig:c}
    \end{subfigure}
\hfill
    \begin{subfigure}{.45\textwidth}
        \centering
        \includegraphics[width=\linewidth]{example-image}
        \phantomsubcaption
        \label{fig:img}
    \end{subfigure}
\end{figure}

\end{document}

See the output

Soldo answered 8/3, 2021 at 21:53 Comment(0)
S
1

Issue is resolved. I have changed the sub figure code with the following.

\captionsetup[subfigure]{labelformat=empty}
\begin{subfigure}{0pt}
\caption{\label{fig:csmarch}}
\end{subfigure}
Sapphira answered 8/2, 2018 at 6:35 Comment(0)
D
0

It might be interesting to know that, similarly to the answer above, to remove a caption, one can use the caption package, and use the command \phantomcaption.

Desdemona answered 18/4, 2024 at 10:30 Comment(0)
S
-1

Keep \subfigure like this will give output no caption and \subfigure[] ([] empty)will give output like (a) (b) & (c) and if you use any caption like my last 3 \subfigure then it will give output like (d) Caption 4 & (e) Caption 5 & (f) Caption 6.

Note: figure* is for the multicolumn article. You can use figure for the single-column article. [ht!] google it or here or here

Use proper packages

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

And then use code like this

 \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*}

Output: enter image description here

Stroup answered 27/7, 2021 at 0:27 Comment(1)
Mixing different subfigure packages is prone to cause problems. Decide if you want to use subfigure or subcaption, but not both.Kirov

© 2022 - 2025 — McMap. All rights reserved.