2

I want to refer to the subfigures. Let's say that I have one figure with three subfigures to it. To refer those subfigures I want to write Fig. 1 (a)-(c) instead of Fig. 1a, 1b, and 1c. I have pasted the code and the output for your reference.

       \documentclass{article}
    \usepackage{graphicx} % Required for inserting images
    \usepackage{caption}
    \usepackage{subcaption}
    \title{}
    \author{}
    \date{}
    
    \begin{document}
    
    \maketitle
    \begin{figure}[ht]
         \centering
         \begin{subfigure}[b]{0.3\textwidth}
             \centering
             \includegraphics[width=\textwidth]{Picture1.png}
             \caption{}
             \label{fig: First figure}
         \end{subfigure}
         \hfill
         \begin{subfigure}[b]{0.3\textwidth}
             \centering
             \includegraphics[width=\textwidth]{Picture2.png}
             \caption{}
             \label{fig: Second figure}
         \end{subfigure}
         \hfill
         \begin{subfigure}[b]{0.3\textwidth}
             \centering
             \includegraphics[width=\textwidth]{Picture3.png}
             \caption{}
             \label{fig: Third figure}
         \end{subfigure}
            \caption{Three figures}
            \label{fig: All figures}
    \end{figure}

I want to write as Fig. \ref{fig: All figures} (a)-(c) instead of Fig. \ref{fig: First figure}, \ref{fig: Second figure}, and \ref{fig: Third figure}.



\end{document}

0.pngenter image description here

1 Answer 1

1

In adaption of the example in section 7 of the subcaption manual, you could, e.g., use:

\documentclass{article}
\usepackage{mwe}
% The old way:
%\usepackage[labelformat=simple]{subcaption}
%\makeatletter
%\renewcommand*{\thesubfigure}{(\alph{subfigure})}
%\renewcommand*{\p@subfigure}{}
%\makeatother
% The new way:
\usepackage{subcaption}
\labelformat{subfigure}{(#1)}% see ltnews30.pdf

\begin{document}

\begin{figure}[ht]
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-a}
    \caption{}
    \label{fig: First figure}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-b}
    \caption{}
    \label{fig: Second figure}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-c}
    \caption{}
    \label{fig: Third figure}
  \end{subfigure}
  \caption{Three figures}
  \label{fig: All figures}
\end{figure}

I want to write as Fig. \ref{fig: All figures} \ref{fig: First
  figure}-\ref{fig: Third figure}.

\end{document}

to get

I want to write as Fig. 1 (a)-(c).

Alternatively, if you don't want to change the result of \ref{…}, you can use \subref{…} as shown in section 7.1 of the subcaption manual:

\documentclass{article}
\usepackage{mwe}
\usepackage{subcaption}
\captionsetup{subrefformat=parens}

\begin{document}

\begin{figure}[ht]
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-a}
    \caption{}
    \label{fig: First figure}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-b}
    \caption{}
    \label{fig: Second figure}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-c}
    \caption{}
    \label{fig: Third figure}
  \end{subfigure}
  \caption{Three figures}
  \label{fig: All figures}
\end{figure}

I want to write as Fig. \ref{fig: All figures} \subref{fig: First
  figure}-\subref{fig: Third figure}.

\end{document}

The result would be the same as shown above.

Another alternative would be to use package cleveref to automatize the range:

\documentclass{article}
\usepackage{mwe}
\usepackage[labelformat=simple]{subcaption}
\renewcommand*{\thesubfigure}{(\alph{subfigure})}
\captionsetup{subrefformat=parens}
\usepackage[capitalize]{cleveref}


\crefrangelabelformat{subfigure}{#3#1#4--#5(\crefstripprefix{#1}{#2}#6}

\begin{document}

\begin{figure}[ht]
  \centering
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-a}
    \caption{}
    \label{fig: First figure}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-b}
    \caption{}
    \label{fig: Second figure}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\textwidth}
    \centering
    \includegraphics[width=\textwidth]{example-image-c}
    \caption{}
    \label{fig: Third figure}
  \end{subfigure}
  \caption{Three figures}
  \label{fig: All figures}
\end{figure}

I want to write as \cref{fig: First figure,fig: Second figure,fig: Third figure}.

\end{document}

I want to write Figs. 1(a)-(c).

1
  • 1
    +1 for the cleveref-based solution.
    – Mico
    Commented Apr 26, 2023 at 9:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .