How do you add references to figures and subfigures in LaTeX?

When you’re reading a document, it’s super helpful to easily find the figures talked about in the text. That’s where adding cross-references to figures in LaTeX. It’s like making your document easier to navigate.

If you’re new to LaTeX or need a quick refresher on linking your text to pictures, this guide is for you.

We’ll show you simple steps to connect your words with the right images, making your document neat and organized.

Simple Method: Using \label and \ref commands

In LaTeX, the easiest way to reference a figure is by using \label{} and \ref{} commands. First, you label your figure, and then you refer to this label wherever need in your text.

This method automatically updates figure numbers, so you don’t have to manually change them if you add or remove figures.

\begin{figure}
 \includegraphics{figure path}
 \caption{An Example Image}
 \label{fig:my_image}
\end{figure}

.... figure~\ref{fig:my_image} ...
\documentclass[12pt]{article}
\usepackage[top=1.5cm]{geometry}
\usepackage{graphicx,lipsum,xcolor} 
\begin{document}
\pagecolor{red!10}
\lipsum[1][4-7]

\begin{figure}[htb]
\centering
\includegraphics[width=.5\textwidth]{fig_physics_2.jpg}
\caption{An Example Image}
\label{fig:my_image}
\end{figure}

Literature review in figure \ref{fig:my_image} summarizes previous findings, while figure~\ref{fig:my_image} delves into theoretical frameworks that underpin our research.

\end{document}

Output :

In this code, \label{fig:my_image} assigns a label to the figure, and \ref{fig:my_image} references it. The tilde ~ ensures that the figure number is never separated from the word “figure” by a line break.

Use parentheses around ref command

To reference a figure within parentheses, simply put \ref{} command inside parentheses.

Figure~(\ref{fig:label})
\documentclass[12pt]{article}
\usepackage{graphicx,xcolor,lipsum} % For including figures
\usepackage[top=1.5cm]{geometry}
\begin{document}
\pagecolor{green!10}
In our study, we refer to various impactful visual aids. Figures(\ref{fig:geophysics}) provide a geographical overview and statistical data, respectively, illustrating significant trends.

\begin{figure}[htb]
\centering
\includegraphics[width=0.5\textwidth]{fig_physics_1.jpg}
\caption{Geographical Overview}
\label{fig:geophysics}
\end{figure}

\lipsum[4]

\end{document}

Output :

Highlighting figure references by adding style

We can add different styles to highlight. For example, changing font style of text and changing the color of reference number, etc.

Also, we can add more than one style together. Below are some commands that many of us are familiar with. Because these commands will be used later.

\textbf{arg}
\textit{arg}
\textcolor{arg}{arg}
\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{xcolor,lipsum}
\usepackage[top=1.5cm]{geometry}
\usepackage{cleveref}

% Define custom format
\newcommand{\figref}[1]{\textbf{\textcolor{red}{\cref{#1}}}}

\newcommand{\figrefitalic}[1]{\textit{\cref{#1}}}

\newcommand{\figrefcolor}[1]{\textcolor{blue}{\cref{#1}}}

\begin{document}
\pagecolor{pink!10}

The results, depicted in \textbf{figures \ref{fig:example}} and \textit{fig.\ref{fig:example}}, highlight key outcomes of our investigation.

\begin{figure}[htbp]
    \centering
    \includegraphics[width=0.5\textwidth]{figure_human_01.png}
    \caption{Example Figure}
    \label{fig:example}
\end{figure}

Here, we reference \figref{fig:example}, \figrefitalic{fig:example}, and \figrefcolor{fig:example}.\\

\lipsum[5][5-9]
\end{document}

Output :

Using cleveref package

The cleveref package simplifies the process of referencing by automatically adding type of object in front of reference number with a single command.

\usepackage{cleveref}
---------------------
\cref{label}
\Cref{label}

cref and Cref commands are part of cleveref package. Although both commands have the same syntax, they are considered separate commands because LaTeX is a case-sensitive markup language.

Moreover, there is a significant difference between them in terms of functionality, which affects their outcomes.

cref : This command adds “fig.” as a reference name, which is printed in lowercase. It is usually used between sentences or where uppercase letters are not needed.

Cref : This command prints the first letter of reference name in capital letters, such as “Figure”. It is usually used at the beginning of sentences or where you want to emphasize.

\documentclass[12pt]{article}
\usepackage{graphicx,lipsum}
\usepackage{cleveref}
\usepackage[top=1.5cm]{geometry}
\usepackage{xcolor}
\definecolor{grayx}{HTML}{f6f8fa}
\begin{document}
\pagecolor{grax}

\begin{figure}[ht]
    \centering
    \includegraphics[width=0.4\textwidth]{fig_physics_2.jpg}
    \caption{A sample figure}
    \label{figure:example}
\end{figure}

To conclude, our research, supported by visual representations in \textcolor{red}{\cref{figure:example}} and \textcolor{blue}{\Cref{figure:example}}, brings forward new insights into the study field. \\

\lipsum[2][3-9]

\end{document}

Output :

Here, cref{label} will print “fig. 1” and \Cref{fig:example} will print “Figure 1”.

Customize reference name

Another special advantage of this package is that you can customize the prefix or reference name.

That is, you can set the name as you like. For example, if you want to use “image” instead of “fig.” and “Image” instead of “figure”, you can execute it very easily, customized code with syntax is provided below.

\crefname{type}{singular}{plural}
\Crefname{type}{Singular}{Plural}

\crefname : This command sets the singular and pleural names for a specific type. For example, if you wanted to set “image” as the singular name for figure type object and “images” as the pleural name, you would use crefname{figure}{image}{images}}. It uses lower-case labels during cross-reference.

\Crefname: It’s similar to crefname, but it capitalizes the first letter of the singular and plural name. For example, crefname{Figure}{Image}{Images}}.

\documentclass[12pt]{article}
\usepackage{graphicx,xcolor}
\usepackage{cleveref}
\usepackage[top=1.6cm]{geometry}

\begin{document}
\pagecolor{cyan!10}
\section*{Without change prefix}

In discussing our findings, we refer back to the methodologies outlined in \textcolor{red}{\cref{fig:example1}} and \textcolor{red}{\Cref{fig:example1}} to correlate our processes with the achieved results.

\begin{figure}[htbp]
    \centering
   \includegraphics[width=0.4\textwidth]{fig_physics_2.jpg}
    \caption{An example figure}
    \label{fig:example1}
\end{figure}

{
\crefname{figure}{image}{images} % lowercase form
\Crefname{figure}{Image}{Images} % uppercase form

\section*{Change with prefix}

Our methodology, as outlined in  \textcolor{blue}{\cref{fig:example}} and \textcolor{blue}{\Cref{fig:example}}, employs a multi-faceted approach to data collection and analysis.


\begin{figure}[htbp]
    \centering    
    \includegraphics[width=0.4\textwidth]{fig_physics_1.jpg}
    \caption{An example figure}
    \label{fig:example}
\end{figure}

}

\end{document}

Output :

Add a reference to subfigure like 1a, 1b, 1c

For documents with subfigures labeled as 1a, 1b, etc., the subcaption package is very useful. Use \begin{subfigure} to create subfigures, each with its own \label{arg}.

\documentclass[12pt]{article}
\usepackage{graphicx,xcolor}
\usepackage{subcaption}
\usepackage[margin=2.8cm]{geometry}

\begin{document}
\pagecolor{yellow!30}

Shows three side-by-side figures. \textcolor{red}{Figure \ref{fig:subfig1}} illustrates ..., \textcolor{red}{Figure \ref{fig:subfig2}} demonstrates ..., and \textcolor{red}{Figure \ref{fig:subfig3}} presents ....

\begin{figure}[htbp]
    \centering
    \begin{minipage}[b]{0.3\textwidth}
        \centering        \includegraphics[width=\textwidth]{example-image-a}
        \captionof{figure}{Image A}
        \label{fig:subfig1}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.3\textwidth}
        \centering       \includegraphics[width=\textwidth]{example-image-b}
       \captionof{figure}{Image B}
        \label{fig:subfig2}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.3\textwidth}
        \centering        \includegraphics[width=\textwidth]{example-image-c}
        \captionof{figure}{Image C}
        \label{fig:subfig3}
    \end{minipage}

\end{figure}


\section*{Ref. like 1a, 1b, 1c}

Figure \textbf{\ref{fig:main}} shows three side-by-side figures. Figure \textcolor{blue}{(\ref{fig:sub1})} illustrates ..., Figure \textcolor{blue}{(\ref{fig:sub2})} demonstrates ..., and Figure \textcolor{blue}{(\ref{fig:sub3})} presents ....

\begin{figure}[htb]
    \centering
    \begin{subfigure}{0.3\textwidth}
        \centering        \includegraphics[width=\textwidth]{example-image-a}
        \caption{Caption for Figure 1}
        \label{fig:sub1}
    \end{subfigure}
    \hfill
    \begin{subfigure}{0.3\textwidth}
        \centering
        \includegraphics[width=\textwidth]{example-image-b}
        \caption{Caption for Figure 2}
        \label{fig:sub2}
    \end{subfigure}
    \hfill
    \begin{subfigure}{0.3\textwidth}
        \centering        
        \includegraphics[width=\textwidth]{example-image-c}
        \caption{Caption for Figure 3}
        \label{fig:sub3}
    \end{subfigure}
    \caption{Main Caption}
    \label{fig:sub3}
\end{figure}
\end{document}

Output :

Then, reference them using \ref{fig:sub1} for individual subfigures, resulting in outputs like “4a”, “4b”, and “4c” with cleveref.

Add reference range

Referencing a range of figures, like 1-3, becomes easier with cleveref. Using \crefrange{fig:first}{fig:last}, you can reference a continuous range of figures.

This command simplifies the process, automatically inserting the correct range, like “Figures 1 to 3,” into your text.

\documentclass[12pt]{article}
\usepackage{graphicx,subfigure}
\usepackage{cleveref}
\usepackage[margin=1.5cm]{geometry}
\begin{document}

\begin{figure}[ht]
    \centering
    \begin{minipage}[b]{0.3\textwidth}     
  \includegraphics[width=\textwidth]{figure_human_01.png}
        \caption{First Image}
        \label{fig:image1}
    \end{minipage}
    \hfill % This adds a space between the minipages if needed
    \begin{minipage}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{fig_physics_1.jpg}
        \caption{Second Image}
        \label{fig:image2}
    \end{minipage}
    \hfill % This adds a space between the minipages if needed
    \begin{minipage}[b]{0.3\textwidth}
        \includegraphics[width=\textwidth]{fig_physics_2.jpg}
        \caption{Third Image}
        \label{fig:image3}
    \end{minipage}
\end{figure}

\noindent As illustrated in \textbf{\Crefrange{fig:image1}{fig:image3}}, the series of figures... Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\\

\noindent You can add figure ranges manually. For example \textbf{Figures {\ref{fig:image1} to \ref{fig:image3}}}.

\end{document}

Output :

Add a clickable reference link

LaTeX makes it easy to add clickable figure references to a document. To do this process you must first add hyperref package to the preamble of your LaTeX document. And where you want to link images with text, you can do so using \ref{label} or \autoref{label}.

\documentclass[12pt]{article}
\usepackage{hyperref,xcolor,graphicx,lipsum}
\usepackage{cleveref}
\usepackage[margin=1.5cm]{geometry}
\begin{document}
\pagecolor{yellow!30}
\lipsum[3][1-5]

\begin{figure}[htb]
\centering
\includegraphics[width=.5\textwidth]{figure_human_01.png}
\caption{An Example Image}
\label{fig:my_image3}
\end{figure}

\lipsum[1]

\vspace{.5cm}

\lipsum[2]

\vspace{.5cm}

\lipsum[3]

\vspace{.5cm}

As shown in \textit{figure~\textcolor{red}{\ref{fig:my_image3}}}, ... \\

In this example, assign a label to the figure. The \textcolor{blue}{\textbf{\Cref{fig:my_image3}}} command is used in the text to this figure. The tilde creates a non-breaking space, ensuring \textbf{Figure} and the number stay together. \\

\autoref{fig:my_image3}

\end{document}

Output :

Instead of ref and autoref, you can use cref or Cref command, which becomes clickable due to hyperref package.

Conclusion

In this tutorial, complete guidance is provided and step-by-step solutions are provided so that you will deal with the reference very easily.

Cleveref package is very interesting. Which is the role of this package is very important in sub-figure, range, multi-reference, and many more cases.

Md Jidan Mondal

LaTeX expert with over 10 years of experience in document preparation and typesetting. Specializes in creating professional documents, reports, and presentations using LaTeX.

Leave a Comment

Your email address will not be published. Required fields are marked *