
這兩個地塊看起來像是被「左衝」了。我怎麼能讓它們出現在中心或居中?
\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{positioning,arrows.meta,shadows.blur}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{center}
\begin{subfigure}{.6\textwidth}
\centering
\includegraphics[width=.9\linewidth]{insesgado_svd_100k}
\caption{Error }
\label{}
\end{subfigure}%
\begin{subfigure}{.6\textwidth}
\centering
\includegraphics[width=.9\linewidth]{sesgado_svd_1M_matlab}
\caption{Error}
\label{}
\end{subfigure}
\caption{ $\Lambda$ f $F$.}
\end{center}
\end{figure}
\end{document}
答案1
也許您正在尋找這樣的東西:
(紅線表示文字邊框)
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{.45\textwidth}
\includegraphics[width=\linewidth]{insesgado_svd_100k}
\caption{Error }
\label{fig:mysubfig1}
\end{subfigure}\hfil
\begin{subfigure}{.45\textwidth}
\includegraphics[width=\linewidth]{sesgado_svd_1M_matlab}
\caption{Error}
\label{fig:mysubfig2}
\end{subfigure}
\caption{ $\Lambda$ f $F$.}
\label{fig:myfig}
\end{figure}
\end{document}
透過比較我的和你們的 MWE 如下:
- 使用的是
article
文檔類,因為在standalone
類中您不能使用浮動(沒有選項varwidth
)並且在其中您看不到圖像是否在文字中水平居中。很快,您的 MWE 就不起作用了。 - 在
figure
環境中不使用\begin{center}
...\end{center}
環境,因為它在影像周圍插入額外的垂直空間。而不是使用它\centering
。 - s 寬度總和
subfigure
應等於或小於\textwidth
。否則它們會溢出到文字區域(甚至頁面)的右側。 subfigure
如果您使用 of 定義圖像寬度,即\includegraphics[width=\linewidth]{....}
,程式碼會更短。在這種情況下,您可以省略s\centering
內的指令subfigure
。