This article is about writing or presenting more than one image in latex figure tab using subfigure package, this tag allows you to present your images side by side ( show figures in a table layout) in columns and rows, check the following example:
- Code:
\begin{figure}[hht]
\centering
\subfigure[Caption 1 Here]{
\includegraphics[totalheight=0.28\textheight,
width=0.5\textwidth]{images/1-1.jpg}
\includegraphics[totalheight=0.28\textheight,
width=0.5\textwidth]{images/1-2.jpg}
\label{fig:subfig1}
}
\subfigure[Caption 2 Here]{
\includegraphics[totalheight=0.28\textheight,
width=0.5\textwidth]{images/2-1.jpg}
\includegraphics[totalheight=0.28\textheight,
width=0.5\textwidth]{images/2-2.jpg}
\label{fig:subfig2}
}
\subfigure[Caption3 Here]{
\includegraphics[totalheight=0.28\textheight,
width=0.5\textwidth]{images/3-1.jpg}
\includegraphics[totalheight=0.28\textheight,
width=0.5\textwidth]{images/3-2.jpg}
\label{fig:subfig3}
}
\caption[Add caption here]{ }
\label{fig:labelHere}
\end{figure}
This code creates a figure using the LaTeX package. It includes the following components:
\begin{figure}[hht]: starts the figure environment with the options [hht], which stands for here, here, and top. These options determine the placement of the figure within the document.
\centering: centers the figure on the page
\subfigure[Caption 1 Here]: starts a subfigure, which is a small figure that is part of a more prominent figure, and includes a caption "Caption 1 Here"
\includegraphics[totalheight=0.28\textheight, width=0.5\textwidth]: include an image in the subfigure, with the options of totalheight=0.28\textheight, width=0.5\textwidth, these options determine the height and width of the image respectively.
\includegraphics[totalheight=0.28\textheight, width=0.5\textwidth]: includes another image in the subfigure, with the same options as the previous one.
\label{fig:subfig1}: assigns a label to the subfigure, which can be used to reference the subfigure in the text.
\subfigure[Caption 2 Here]: starts another subfigure, with a caption "Caption 2 Here" and including two images in the same format as the previous subfigure.
\label{fig:subfig2}: assigns a label to the subfigure, which can be used to reference the subfigure in the text.
\subfigure[Caption 3 Here]: starts another subfigure, with a caption "Caption 3 Here" and including two images in the same format as the previous subfigure.
\label{fig:subfig3}: assigns a label to the subfigure, which can be used to reference the subfigure in the text.
\caption[Add caption here]: adds a caption to the figure, which describes the entire figure.
\label{fig:labelHere}: assigns a label to the figure, which can be used to reference the figure in the text.
\end{figure}: ends the figure environment.
It creates a figure with three subfigures, each containing two images. Each subfigure has its caption, and each image has a reference label. The entire figure has a caption "Add caption here" and also a reference label. The images are located in the images folder with names 1-1.jpg, 1-2.jpg, 2-1.jpg, 2-2.jpg, 3-1.jpg, 3-2.jpg. In addition to what I've already mentioned, it's worth noting that the code is using the package "subfigure" which allows you to create multiple subfigures within a single figure, each with its own caption and label. This can be useful for organizing and grouping related images together, and for saving space in the document layout. It's also worth noting that the images are being loaded from a directory called "images" using the command "\includegraphics" and each image has its own dimensions specified by the options "totalheight=0.28\textheight" and "width=0.5\textwidth", these options determine the height and width of the image respectively. It is also possible to add additional formatting and styling to the figures, such as changing the font size, adding borders, and adjusting the spacing between the subfigures. You can use the package "subcaption" which provides additional options and customization for subfigures and subcaptions. The code uses the option [hht] for the figure environment. This option tells LaTeX to try placing the figure at the current position in the text (h), if it doesn't fit then place it at the top of the next page (t), and if it still doesn't fit, then place it at the end of document (b). It is also possible to use other placement options like "[htp]" or "[!htb]" depending on your layout needs and preferences. It's also worth noting that the option "totalheight=0.28\textheight" and "width=0.5\textwidth" are used to scale the images. you can adjust these values to fit the size of your images to the size of your text or page. You can also use the package "graphicx" and use the options "height" and "width" instead of "totalheight" and "width" It's also worth noting that the code uses the command "\label" to assign a label to the figures and subfigures, these labels are used to refer to the figures and subfigures in the text, using the command "\ref".
Finally, it's worth noting that the images are named in format "X-Y.jpg" where X is a number representing the subfigure and Y is a number representing the image in that subfigure.
Note that I am changing the side of images, including using these attributes :
- Code:
[totalheight=0.28\textheight,
width=0.5\textwidth]
And remember that like any package you need to use in latex you will have to include it before the beginning document :
- Code:
\usepackage{subfigure}
....
\begin{document}