我有两个带有 tikzpicture 的图,一个位于另一个上方。(它们有相当困难的文本文件作为源,所以我无法在此处显示它们)。
这些图的宽度相同,问题是图例的大小不同 - >一个图比另一个图更靠左)
我该怎么做才能使它们垂直对齐?
非常感谢 !!
答案1
以下建议仅当两张图片均位于中心时才有效。
您可以对两者使用选项trim axis left
(或可能) :trim axis right
tikzpicture
\begin{tikzpicture}[trim axis left]
代码:
\documentclass{scrartcl}
\usepackage{pgfplots}
\pgfplotsset{width=8cm,height=6cm}
\begin{document}
\begin{center}
\begin{tikzpicture}[trim axis left]
\begin{axis}[no marks]
\addplot {x};
\end{axis}
\end{tikzpicture}
\captionof{figure}{Fugue 1}
\vspace{2\baselineskip}
\begin{tikzpicture}[trim axis left]
\begin{axis}[ylabel = {$y(x)$},no marks]
\addplot {2*x};
\end{axis}
\end{tikzpicture}
\captionof{figure}{Figure 2}
\end{center}
\end{document}
\pgfresetboundingbox
另一种可能性是使用\useasboundingbox
\documentclass{scrartcl}
\usepackage{pgfplots}
\pgfplotsset{width=8cm,height=6cm}
\newcommand\myBoundingBox{
\pgfresetboundingbox
\path(current axis.below south west)rectangle (current axis.above north east);
}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[no marks]
\addplot {x};
\end{axis}
\myBoundingBox
\end{tikzpicture}
\captionof{figure}{Fugue 1}
\vspace{2\baselineskip}
\begin{tikzpicture}
\begin{axis}[ylabel = {$y(x)$},no marks]
\addplot {2*x};
\end{axis}
\myBoundingBox
\end{tikzpicture}
\captionof{figure}{Figure 2}
\end{center}
\end{document}
或者你可以使用环境pgfinterruptboundingbox
进行axis
\useasboundingbox
...
\begin{pgfinterruptboundingbox}
\begin{axis}[...
...
\end{axis}
\end{pgfinterruptboundingbox}
\useasboundingbox(current axis.below south west)rectangle (current axis.above north east);
...