我正在使用 tikz 和环境 {figure} 在同一页上显示 4 个图表,但结果并不令人满意,我想使其更加居中(图形必须更靠左,并且它们之间的垂直空间必须更小,请参见屏幕)。 有命令可以执行此操作吗?
\begin{figure}
\begin{minipage}[c]{.46\linewidth}
\centering
\begin{tikzpicture}
....
\end{tikzpicture}
\end{minipage}\hfill
\begin{minipage}[c]{.46\linewidth}
\centering
\begin{tikzpicture}[baseline=(current bounding box.north)]
...
\end{tikzpicture}
\end{minipage}
\end{figure}
\begin{figure}
\begin{minipage}[c]{.46\linewidth}
\centering
\begin{tikzpicture}[baseline]
...
\end{tikzpicture}
\end{minipage}\hfill
\begin{minipage}[c]{.46\linewidth}
\centering
\begin{tikzpicture}[baseline]
...
\end{tikzpicture}
\end{minipage}
答案1
如果您想添加\subcaption
s,那么您将需要 minipages。否则,何必费心呢?
s\hfil
提供左侧、右侧和中间的相等间距。段落末尾有一个自动\hfil
(实际上是) 。\parfillskip
tikzpictures 默认为底部对齐。使用该baseline
选项将更改此设置。
\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}% generic text
\usepackage{showframe}% outline text area
\begin{document}
\begin{figure}
\hfil
\begin{tikzpicture}
\fill (0,0) rectangle (4,3);
\end{tikzpicture}
\hfil
\begin{tikzpicture}
\fill (0,0) rectangle (4,3);
\end{tikzpicture}
\hfil
\begin{tikzpicture}
\fill (0,0) rectangle (4,3);
\end{tikzpicture}
\hfil
\begin{tikzpicture}
\fill (0,0) rectangle (4,3);
\end{tikzpicture}
\end{figure}
\lipsum[1-3]
\end{document}
答案2
作为单独的图像:
使用tabularx
包:
\documentclass[12pt]{article}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepackage[showframe]{geometry}% option 'showframe' is only for show page layout ...
\begin{document}
\begin{figure}[htb]
\centering
\begin{tabularx}{\textwidth}{*{2}{>{\centering\arraybackslash}X}}
\begin{tikzpicture}
\begin{axis}[width=\linewidth,legend entries={$x$,$x^2$}]
\addplot {x};
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{}
& \begin{tikzpicture}
\begin{axis}[width=\linewidth,legend entries={$x$,$x^2$}]
\addplot {x};
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{} \\
\begin{tikzpicture}
\begin{axis}[width=\linewidth,legend entries={$x$,$x^2$}]
\addplot {x};
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{}
& \begin{tikzpicture}
\begin{axis}[width=\linewidth,legend entries={$x$,$x^2$}]
\addplot {x};
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\caption{}
\end{tabularx}
\end{figure}
\end{document}