\begin{figure}[h] % figure will span both columns in article
\centering
\setkeys{Gin}{width=\linewidth} % common settings of images widths
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/a.png}
\caption{cap1}
\label{1}
\end{subfigure}%
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/s.png}
\caption{cap2}
\label{2}
\end{subfigure}%
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/d.png}
\caption{cap3}
\label{3}
\end{subfigure}%
\hfill
\centering
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/f.png}
\caption{cap4}
\label{4}
\end{subfigure}%
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/g.png}
\caption{cap5}
\label{5}
\end{subfigure}%
\caption{figure}
\label{total}
\end{figure}
我想要每個子圖的標題和標籤,此程式碼的唯一缺陷是第二行中的 2 個子圖未居中,它們通過形成一個大空間來填充整行謝謝!
答案1
一些建議:
消除兩個都
\centering
指示。第一個沒有做任何有用的事情,第二個與您在帖子標題中所說的想要實現的目標背道而馳,即。,「第二行不居中」。更換最後的
\hfill
指令與\hspace{0.05\textwidth}%
;符號%
很重要。為什麼0.05\textwidth
?在第 1 行中,三個圖佔據0.9\textwidth
;這留下了0.1\textwidth
兩個圖間空白間隙。一半0.1\textwidth
是0.05\textwidth
.將倒數第二條指令替換
\hfill
為空白行和一條\bigskip
指令。
\documentclass[demo]{article} % remove 'demo' option in final document
\usepackage{graphicx,subcaption}
\begin{document}
\begin{figure}[h] % figure will span both columns in article % really?
%%\centering % <-- no need to use \centering
\setkeys{Gin}{width=\linewidth} % common settings of images widths
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/a.png}
\caption{cap1}
\label{1}
\end{subfigure}%
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/s.png}
\caption{cap2}
\label{2}
\end{subfigure}%
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/d.png}
\caption{cap3}
\label{3}
\end{subfigure}
\bigskip % <-- leave a blank line (to cause a line break) and '\bigskip'
%% \centering % <-- this instruction is counterproductive
\begin{subfigure}{0.3\linewidth}% <-- the "%" symbol is needed
\includegraphics{./Figures/f.png}
\caption{cap4}
\label{4}
\end{subfigure}%
\hspace{0.05\textwidth}% <-- instead of '\hfill'
\begin{subfigure}{0.3\linewidth}
\includegraphics{./Figures/g.png}
\caption{cap5}
\label{5}
\end{subfigure}
\caption{A figure with five subfigures}
\label{fig:total}
\end{figure}
\end{document}