假设你有一个 2x2 tikz 图形矩阵,并且你决定使用subfloat
s。代码
\documentclass{report}
\usepackage{subfig}
\usepackage{tikz}
\begin{document}
\begin{figure}[ht!]
\center
\subfloat[Figure 1]{
\begin{tikzpicture}
\filldraw (0,0) rectangle (1,1);
\end{tikzpicture}
} \quad
\subfloat[Figure 2]{
\begin{tikzpicture}
\filldraw (0,0) rectangle (3,3);
\end{tikzpicture}
} \\
\subfloat[Figure 3]{
\begin{tikzpicture}
\filldraw (0,0) rectangle (2,2);
\end{tikzpicture}
} \quad
\subfloat[Figure 4]{
\begin{tikzpicture}
\filldraw (0,0) rectangle (5,5);
\end{tikzpicture}
}
\caption{Test}
\label{test}
\end{figure}
\end{document}
给出结果
现在如何才能获得行和列的对称对齐,如下所示?我想这是一个标准问题,应该有一个简单的解决方案,但到目前为止,我只找到了以下方法
答案1
使用来tabularx
定位图像及其标题:
\documentclass{report}
\usepackage[skip=1ex]{caption}
\usepackage{tabularx}
\newcolumntype{C}[1]{>{\centering\arraybackslash\hsize=#1\hsize}X}
\usepackage{tikz}
\begin{document}
\begin{figure}[htp!]
\centering
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{tabularx}{0.8\linewidth}{C{0.8}C{1.2}}
\tikz\filldraw (0,0) rectangle (1,1);
& \tikz\filldraw (0,0) rectangle (3,3); \\
\caption{Figure 1}
& \caption{Figure 2} \\
\tikz\filldraw (0,0) rectangle (2,2);
& \tikz\filldraw (0,0) rectangle (5,5); \\
\caption{Figure 3}
& \caption{Figure 4} \\[-2ex]
\end{tabularx}
\caption{Test}
\label{test}
\end{figure}
\end{document}
答案2
可能不是最优雅的代码,但下面的代码应该会产生接近预期的输出。
\documentclass{report}
\usepackage{subcaption}
\usepackage{tikz}
\begin{document}
\begin{figure}[ht!]
\centering
\begin{subfigure}{0.2\textwidth}
\centering
\begin{tikzpicture}
\filldraw (0,0) rectangle (1,1);
\end{tikzpicture}
\end{subfigure}\quad
\begin{subfigure}{0.45\textwidth}
\centering
\begin{tikzpicture}
\filldraw (0,0) rectangle (3,3);
\end{tikzpicture}
\end{subfigure}
\smallskip
\begin{subfigure}{0.2\textwidth}
\caption{Figure 1}
\end{subfigure}\quad
\begin{subfigure}{0.45\textwidth}
\caption{Figure 2}
\end{subfigure}
\bigskip
\begin{subfigure}{0.2\textwidth}
\centering
\begin{tikzpicture}
\filldraw (0,0) rectangle (2,2);
\end{tikzpicture}
\end{subfigure}\quad
\begin{subfigure}{0.45\textwidth}
\centering
\begin{tikzpicture}
\filldraw (0,0) rectangle (5,5);
\end{tikzpicture}
\end{subfigure}
\smallskip
\begin{subfigure}{0.2\textwidth}
\caption{Figure 3}
\end{subfigure}\quad
\begin{subfigure}{0.45\textwidth}
\caption{Figure 4}
\end{subfigure}
\caption{Test}
\label{test}
\end{figure}
\end{document}
答案3
如果你没有太多这样的结构,你可以作弊。
\documentclass{report}
\usepackage{subfig}
\usepackage{tikz}
\begin{document}
\begin{figure}[htp!]
\centering
\begin{tabular}{cc}
\begin{tabular}{@{}c@{}}
\begin{tikzpicture}
\filldraw (0,0) rectangle (1,1);
\end{tikzpicture}
\end{tabular}
&
\begin{tabular}{@{}c@{}}
\begin{tikzpicture}
\filldraw (0,0) rectangle (3,3);
\end{tikzpicture}
\end{tabular}
\\[-2ex]
\subfloat[Figure 1]{\hspace{3cm}}
&
\subfloat[Figure 2]{\hspace{3cm}}
\\[6ex]
\begin{tabular}{@{}c@{}}
\begin{tikzpicture}
\filldraw (0,0) rectangle (2,2);
\end{tikzpicture}
\end{tabular}
&
\begin{tabular}{@{}c@{}}
\begin{tikzpicture}
\filldraw (0,0) rectangle (5,5);
\end{tikzpicture}
\end{tabular}
\\[-2ex]
\subfloat[Figure 3]{\hspace{3cm}}
&
\subfloat[Figure 4]{\hspace{3cm}}
\end{tabular}
\caption{Test}
\label{test}
\end{figure}
\end{document}