How to add subfigure in Latex
1 minute read
In research articles, we need to add subfigures often. To create subfigure in latex, you can use both \begin{minipage}...\end{minipage}
and \begin{subfigure}...\end{subfigure}
block to insert subfigures or sub-images. Subfigurs are generally inserted horizontally in one or multiple rows. Here, some example codes with output screenshots are provided in the following.
The following code puts two subfigures in a figure portion-
\usepackage{subcaption}
\begin{figure}[ht]
\begin{subfigure}{.5\textwidth}
\centering
% include first image
\includegraphics[width=.8\linewidth]{image_file_name}
\caption{Put your sub-caption here}
\label{fig:sub-first}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
\centering
% include second image
\includegraphics[width=.8\linewidth]{image_file_name}
\caption{Put your sub-caption here}
\label{fig:sub-second}
\end{subfigure}
\caption{Put your caption here}
\label{fig:fig}
\end{figure}
So, applying the code the output should look like this -
Here is another code to do the same. Only difference is, this time we are using \begin{minipage}...\end{minipage}
instead of \begin{subfigure}...\end{subfigure}
block.
\begin{figure}[ht]
\subfloat[Percentage storage utilization]{
\begin{minipage}[c][1\width]{
0.3\textwidth}
\centering
\includegraphics[width=1\textwidth]{image_file_name}
\end{minipage}}
\hfill
\subfloat[standard deviation]{
\begin{minipage}[c][1\width]{
0.3\textwidth}
\centering
\includegraphics[width=1.1\textwidth]{image_file_name}
\end{minipage}}
\hfill
\subfloat[execution time]{
\begin{minipage}[c][1\width]{
0.3\textwidth}
\centering
\includegraphics[width=1.2\textwidth]{image_file_name}
\end{minipage}}
\caption{}
\end{figure}
So, applying the code the output should look like this-
Multiple subfigures can be put in multiple rows by adding a \newline
after one row is complete. For example, if you have four figures and you want to put them in 2x2 style, put \newline
after two subfigures which will be placed in the first rwo. The command will create a new row for rest of the subfigures.
\begin{document}
\begin{figure}
\begin{subfigure}{.5\textwidth}
\centering
% include first image
\includegraphics[width=.8\linewidth]{log_demo1.png}
\caption{Put your sub-caption here}
\label{fig:sub-first}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
\centering
% include second image
\includegraphics[width=.8\linewidth]{log_demo2.png}
\caption{Put your sub-caption here}
\label{fig:sub-second}
\end{subfigure}
\newline
\begin{subfigure}{.5\textwidth}
\centering
% include third image
\includegraphics[width=.8\linewidth]{log_demo1.png}
\caption{Put your sub-caption here}
\label{fig:sub-third}
\end{subfigure}
\begin{subfigure}{.5\textwidth}
\centering
% include fourth image
\includegraphics[width=.8\linewidth]{log_demo2.png}
\caption{Put your sub-caption here}
\label{fig:sub-fourth}
\end{subfigure}
\caption{Put your caption here}
\label{fig:fig}
\end{figure}
So, applying the code the output should look like this-
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。