前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >How to add subfigure in Latex

How to add subfigure in Latex

作者头像
marsggbo
发布2019-03-27 12:05:07
1.5K0
发布2019-03-27 12:05:07
举报

How to add subfigure in Latex

1 minute read

TABLE OF CONTENTS

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.

Add subfigures horizontally

The following code puts two subfigures in a figure portion-

代码语言:txt
复制
\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.

代码语言:txt
复制
\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-

Add multiple subfigures in multiple rows

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.

代码语言:txt
复制
\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 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • TABLE OF CONTENTS
  • Add subfigures horizontally
  • Add multiple subfigures in multiple rows
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档