latex subfigure with code examples

LaTeX is a high-quality typesetting system that is widely used in scientific and technical writing. One of the most important features of LaTeX is its ability to handle images and figures. In this article, we will focus on the use of LaTeX subfigures.

A subfigure is a small image or figure that is placed inside a larger figure or a table. This allows us to have multiple images or figures in one page, and each subfigure is labeled and referred to separately.

The package ‘subcaption’ is used to include subfigures in LaTeX documents. To use it, we need to include the following line in the preamble of our LaTeX document:

\usepackage{subcaption}

We can then create subfigures using the ‘subfigure’ environment. For example, to create two subfigures, side by side, we can use the following code:

\begin{figure}
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{image1.png}
  \caption{Image 1}
  \label{fig:image1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{image2.png}
  \caption{Image 2}
  \label{fig:image2}
\end{subfigure}
\caption{Example of subfigures}
\label{fig:subfigures}
\end{figure}

In the above code, the \begin{subfigure} environment creates each subfigure, and the \centering command centers the image within the subfigure. The \includegraphics command includes the image, and the \caption and \label commands provide the caption and label for each subfigure, respectively.

We can also create subfigures in a row by using the ‘subfigure’ environment multiple times. For example, to create three subfigures, one below the other, we can use the following code:

\begin{figure}
\begin{subfigure}{\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{image1.png}
  \caption{Image 1}
  \label{fig:image1}
\end{subfigure}

\begin{subfigure}{\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{image2.png}
  \caption{Image 2}
  \label{fig:image2}
\end{subfigure}

\begin{subfigure}{\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{image3.png}
  \caption{Image 3}
  \label{fig:image3}
\end{subfigure}
\caption{Example of subfigures}
\label{fig:subfigures}
\end{figure}

In the above code, we have used the ‘subfigure’ environment multiple times to create three subfigures
There are several other important aspects related to the use of subfigures in LaTeX that we should be aware of.

  1. Customizing subfigure captions: We can customize the subfigure captions by using the \subcaption command. For example, to change the font size of the subfigure captions, we can use the following code:
\captionsetup[subfigure]{font=small}
  1. Cross-referencing subfigures: In some cases, we may want to refer to a specific subfigure in the text. To do this, we can use the \ref command in combination with the subfigure’s label. For example:
As can be seen in Figure \ref{fig:subfigures}(a), the image shows…
  1. Resizing subfigures: We can also adjust the size of the subfigures by changing the width of the subfigure environment. For example, to make the subfigure width half the text width, we can use the following code:
\begin{subfigure}{.5\textwidth}
  1. Vertical alignment of subfigures: By default, subfigures are vertically centered within the subfigure environment. However, we can change this by using the valign option. For example, to align the top of the subfigure with the top of the subfigure environment, we can use the following code:
\begin{subfigure}[t]{.5\textwidth}

In conclusion, the use of subfigures in LaTeX is a powerful tool that enables us to include multiple images or figures in one page, each with its own label and caption. By understanding the various options and commands available, we can customize our subfigures to suit our specific needs.

Popular questions

  1. What is a subfigure in LaTeX?

A subfigure in LaTeX is a figure that is included within another figure or table. Subfigures are useful for presenting multiple images or figures within a single page, and each subfigure can have its own caption and label.

  1. How do we create subfigures in LaTeX?

To create subfigures in LaTeX, we use the \subfigure command within the figure environment. For example:

\begin{figure}
  \begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[width=.8\linewidth]{image1.png}
    \caption{Image 1}
    \label{fig:image1}
  \end{subfigure}%
  \begin{subfigure}{.5\textwidth}
    \centering
    \includegraphics[width=.8\linewidth]{image2.png}
    \caption{Image 2}
    \label{fig:image2}
  \end{subfigure}
  \caption{Subfigures}
  \label{fig:subfigures}
\end{figure}
  1. What is the purpose of a subfigure caption and label?

A subfigure caption is a brief description of the image or figure that the subfigure represents. The subfigure caption is displayed below the subfigure. The subfigure label is used to reference the subfigure in the text, either to refer to the subfigure itself or to refer to specific elements within the subfigure.

  1. Can subfigures be resized in LaTeX?

Yes, subfigures can be resized in LaTeX by changing the width of the subfigure environment. For example, to make the subfigure width half the text width, we can use the following code:

\begin{subfigure}{.5\textwidth}
  1. How do we reference subfigures in the text?

To reference a subfigure in the text, we use the \ref command in combination with the subfigure’s label. For example:

As can be seen in Figure \ref{fig:subfigures}(a), the image shows…

Tag

LaTeX

Posts created 2498

Leave a Reply

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

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top