我使用以下代码在一行中添加多个图形
\begin{figure}
\centering
\begin{tabular}[b]{c}
\includegraphics[width=0.20\linewidth]{image here} \\
\small (a) Figure 1
\end{tabular} \qquad
\begin{tabular}[b]{c}
\includegraphics[width=0.20\linewidth]{image here} \\
\small (b) Figure 2
\end{tabular} \qquad
\begin{tabular}[b]{c}
\includegraphics[width=0.20\linewidth]{image here} \\
\small (c) Figure 3
\end{tabular} \qquad
\begin{tabular}[b]{c}
\includegraphics[width=0.20\linewidth]{image here} \\
\small (a) Figure 4
\end{tabular} \qquad
代码可以很好地在每行添加两个图表,有人能帮忙添加 3、4 个图表吗?不幸的是,我不能使用子图表,它与期刊论文模板有些冲突
答案1
这使用了 tabular 不太为人熟知的堂兄 tabular* 和他的小朋友\extracolsep
。
\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}% alignment tool
\begin{document}
\begin{figure}
\tabcolsep=0pt
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}cccc}
\includegraphics[width=0.20\textwidth]{example-image-a} &
\includegraphics[width=0.20\linewidth]{example-image-b} &
\includegraphics[width=0.20\linewidth]{example-image-c} &
\includegraphics[width=0.20\linewidth]{example-image} \\
\small (a) Figure 1 &
\small (b) Figure 2 &
\small (c) Figure 3 &
\small (a) Figure 4
\end{tabular*}
\end{figure}
\end{document}
\tabcolsep
坦率地说,简单地计算需要加起来的数量\linewidth
(每列 2 个)更容易。
\documentclass{article}
\usepackage{graphicx}
\usepackage{showframe}% alignment tool
\begin{document}
\begin{figure}
\tabcolsep=0.2\linewidth
\divide\tabcolsep by 8
\begin{tabular}{cccc}
\includegraphics[width=0.20\linewidth]{example-image-a} &
\includegraphics[width=0.20\linewidth]{example-image-b} &
\includegraphics[width=0.20\linewidth]{example-image-c} &
\includegraphics[width=0.20\linewidth]{example-image} \\
\small (a) Figure 1 &
\small (b) Figure 2 &
\small (c) Figure 3 &
\small (d) Figure 4
\end{tabular}
\end{figure}
\end{document}
答案2
我的主要建议是省略 4 幅图像中的第 2 幅图像后的空白行。请记住,空白行(在许多但并非所有文本模式情况下)被解释为段落分隔符。因此建议省略空白行。
进一步的建议:省略
\centering
指令,省略最后的指令,并用\qquad
替换其他 3 个实例。\qquad
\hfill
最后,如果您有相当多这种类型的图形,可能值得创建一个定制的宏(
\myfig
在下面的代码中调用)以帮助简化子图形的创建。
\documentclass{article} % or some other suitable document class
\usepackage{array}
\usepackage[demo]{graphicx} % remove 'demo' option in real document
\newcommand\myfig[2]{%
\begin{tabular}[b]{>{\centering\arraybackslash}p{0.2\textwidth}}
\includegraphics[width=\linewidth]{#1} \\ \small #2 \end{tabular}}
\begin{document}
\begin{figure}
\myfig{image1}{(a) Figure 1}\hfill
\myfig{image2}{(b) Figure 2}\hfill
\myfig{image3}{(c) Figure 3}\hfill
\myfig{image4}{(d) Figure 4}%
\end{figure}
\end{document}
答案3
没有tabular
(或类似的表)环境,通过使用subloat
环境(如subcaption
包版本 1.3 中所定义)和键,Gin
您将获得最短、最简单的问题代码:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}[htb]
\setkeys{Gin}{width=0.24\linewidth}
%
\subfloat[Figure 1]{\includegraphics{example-image-duck}}\hfill
\subfloat[Figure 2]{\includegraphics{example-image-duck}}\hfill
\subfloat[Figure 3]{\includegraphics{example-image-duck}}\hfill
\subfloat[Figure 4]{\includegraphics{example-image-duck}}
\end{figure}
\end{document}