Nevertheless, many LaTeX users are confused with the source codes and cannot add captions. Thus, we have written this tutorial to explain different ways to add a figure caption in LaTeX.
How To Add a Figure Caption in LaTeX
Let’s start with the simple example where we will add a caption to a figure that includes a 3D cube on the (x,y, z) axis. Here is the following source code:
\usepackage{graphicx}
\usepackage{caption}
\begin{document}
\begin{figure}
\centering
\includegraphics[scale= 0.2]{Images/3d_image.png}
\caption{3D cube in x, y, z axis}
\label{fig:my_label}
\end{figure}
\end{document}
Output
In the previous source code, we used the caption \usepackage and \centering on placing the figure in the center. You only need to add your text in the \caption{} to compile it as a figure caption. In case you don’t know how to add an image in LaTeX, you can check out this tutorial.
If you want to wrap the figure and its caption with the document text, please use the following source code:
\usepackage{graphicx}
\usepackage{blindtext}
\graphicspath{ {./images/} }
\usepackage{wrapfig}
\begin{document}
\blindtext
\begin{wrapfigure}{r}{0.4\textwidth}
\includegraphics[scale= 0.2]{Images/3d_image.png}
\caption{3D cube in x, y, z axis}
\label{fig:my_label}
\end{wrapfigure}
\blindtext
\blinddocument
\end{document}
Output
Additional Options for Figure Captions
You can change the text type of the figure through the following source code:
\usepackage{graphicx}
\usepackage{caption}
\DeclareCaptionFormat{custom}
{\textbf{#1 #2}\textit{\small #3}}
\captionsetup{format=custom}
\begin{document}
\begin{figure}
\centering
\includegraphics[scale= 0.2]{Images/3d_image.png}
\caption{3D cube in x, y, z axis}
\label{fig:my_label}
\end{figure}
\end{document}
Output
In the previous source code, #1 represents the caption label and #2 represents separator. Similarly, #3 means the text of the caption.
Conclusion
In this tutorial, we have explained various ways to add figure captions in LaTeX. A caption under an image helps a reader to get information about the visual representations. There are different methods to add captions but ensure you use the source codes properly. Otherwise, you may get errors while compiling the source code in LaTeX.