我有一些复杂的tikz
图片,我不想手动调整大小(因此tikzscale
) - 但将几张图片放在一个图中似乎不起作用\subcaptionbox
。它做一起使用subfigure
(也来自subcaption
包),但是如果每个标题的行数不同,则标题不会对齐。
对于 MWE,需要创建一个square.tikz
具有以下内容的文件(显然,这是为了说明问题而进行的简化;-))
\begin{tikzpicture}
\draw (-10,-10) rectangle (10,10);
\end{tikzpicture}
然后代码是
\documentclass{article}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage[justification=centering]{subcaption}
\begin{document}
\begin{figure}
\subcaptionbox{One-line caption}[0.5\textwidth]{\includegraphics[width=\textwidth]{square.tikz}}
\subcaptionbox{Two-line caption \\ is aligned}[0.5\textwidth]{\includegraphics[width=\textwidth]{square.tikz}}
\caption{With \texttt{subcaptionbox}}
\end{figure}
\begin{figure}
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=\textwidth]{square.tikz}
\caption{One-line caption}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=\textwidth]{square.tikz}
\caption{Two-line caption; \\ should be aligned with one-line caption}
\end{subfigure}
\caption{With \texttt{subfigure}}
\end{figure}
\end{document}
答案1
环境subfigure
实际上是一个重置为指定宽度的minipage
地方\textwidth
。但对于 则不然;如果您只希望它与内部对象具有相同的尺寸,则\subcaptionbox
的可选参数不是必需的。\subcaptionbox
\begin{filecontents*}{square.tikz}
\begin{tikzpicture}
\draw (-10,-10) rectangle (10,10);
\end{tikzpicture}
\end{filecontents*}
\documentclass{article}
\usepackage[english]{babel}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage[justification=centering]{subcaption}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{One-line caption}{%
\includegraphics[width=.45\textwidth]{square.tikz}%
}\hfill
\subcaptionbox{Two-line caption \\ is aligned}{%
\includegraphics[width=.45\textwidth]{square.tikz}%
}
\caption{With \texttt{subcaptionbox}}
\end{figure}
\end{document}