1

I've found this code here and I need to know if someone knows how can I label all the figures to be able to make a reference to them in the text and to appear for example: "In figure 1A..."

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{float}

\begin{document}

\begin{figure} [H] \centering \begin{tabular}{cccc} \includegraphics[width=0.3\textwidth]{example-image-a} & \includegraphics[width=0.3\textwidth]{example-image-b} & \includegraphics[width=0.3\textwidth]{example-image-c} \ \textbf{(a)} & \textbf{(b)} & \textbf{(c)} \[6pt] \end{tabular} \begin{tabular}{cccc} \includegraphics[width=0.3\textwidth]{example-image-a} & \includegraphics[width=0.3\textwidth]{example-image-b} \ \textbf{(d)} & \textbf{(e)} \[6pt] \end{tabular} \caption{ \textbf{(a)} Some text \textbf{(b)} Some text \textbf{(c)} Some text \textbf{(d)} Some text \textbf{(e)} Some text} \label{fig:Name} \end{figure}

\end{document}

gernot
  • 49,614

2 Answers2

3

If you have control over the pictures and their labels, then you should definitely use the approach described in the answers to the question How does one create, caption, label and refer to a subfigure?.

If the five images and their captions are a single image that you do not want to dissect, you can define a command \extralabel{labelname}{subnumber} in the preamble:

\makeatletter
\newcommand\extralabel[2]{{\edef\@currentlabel{\@currentlabel#2}\label{#1}}}
\makeatother

and later can reference labelname with \ref.

\documentclass{article}
\makeatletter
\newcommand\extralabel[2]{{\edef\@currentlabel{\@currentlabel#2}\label{#1}}}
\makeatother
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\begin{tabular}{cccc}
\includegraphics[width=0.3\textwidth]{example-image-a} &
\includegraphics[width=0.3\textwidth]{example-image-b} &
\includegraphics[width=0.3\textwidth]{example-image-c} \\
\textbf{(a)}  & \textbf{(b)} & \textbf{(c)}  \\[6pt]
\end{tabular}
\begin{tabular}{cccc}
\includegraphics[width=0.3\textwidth]{example-image-a} &
\includegraphics[width=0.3\textwidth]{example-image-b} \\
\textbf{(d)}  & \textbf{(e)}  \\[6pt]
\end{tabular}
\caption{ \textbf{(a)} Some text
\textbf{(b)} Some text
\textbf{(c)} Some text
\textbf{(d)} Some text
\textbf{(e)} Some text}
\label{fig:Name}
\extralabel{fig:Name:a}{(a)}
\extralabel{fig:Name:b}{(b)}
\extralabel{fig:Name:c}{(c)}
\extralabel{fig:Name:d}{(d)}
\extralabel{fig:Name:e}{(e)}
\end{figure}

See subfigures \ref{fig:Name:a}, \ref{fig:Name:b}, \ref{fig:Name:c}, \ref{fig:Name:d}, \ref{fig:Name:e}.

\end{document}

enter image description here

gernot
  • 49,614
3

If you have control over the five pictures and their captions, then you can let the subcaption package handle the subcaptions and sublabes.

\documentclass{article}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
  \centering  
\begin{tabular}{ccc}
  \subcaptionbox{\label{fig:Name:a}}{\includegraphics[width=0.3\textwidth]{example-image-a}} &
  \subcaptionbox{\label{fig:Name:b}}{\includegraphics[width=0.3\textwidth]{example-image-b}} &
  \subcaptionbox{\label{fig:Name:c}}{\includegraphics[width=0.3\textwidth]{example-image-c}}
\end{tabular}
\medskip

\begin{tabular}{cc} \subcaptionbox{\label{fig:Name:d}}{\includegraphics[width=0.3\textwidth]{example-image-a}} & \subcaptionbox{\label{fig:Name:e}}{\includegraphics[width=0.3\textwidth]{example-image-c}} \end{tabular} \medskip

\caption{ \textbf{(a)} Some text \ref{fig:Name:b} \textbf{(b)} Some text \textbf{(c)} Some text \textbf{(d)} Some text \textbf{(e)} Some text} \label{fig:Name} \end{figure}

See subfigures \ref{fig:Name:a}, \ref{fig:Name:b}, \ref{fig:Name:c}, \ref{fig:Name:d}, \ref{fig:Name:e}.

\end{document}

enter image description here

gernot
  • 49,614