我需要一些关于 tikzpictures 对齐的帮助,请参阅示例。要将 pgf 图与相同的 x 轴对齐,我使用“修剪左轴”。这对于具有单个 y 轴的图表很有效。现在其中一个图表有第二个 y 轴,那么它们对齐得就不好了。我想对齐它们并将它们放在页面的中心。
有任何想法吗?
安德烈亚斯
\documentclass[a4paper,12pt]{scrreprt}
\usepackage{lmodern}
\usepackage{pifont}
\usepackage[german]{babel}
\selectlanguage{german}
\usepackage[T1]{fontenc}
\usepackage{float}
\usepackage[hang,font=singlespacing]{caption}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{/pgf/number format/use comma, compat=newest}
\usetikzlibrary{patterns}
\usepackage{subfig}
\begin{document}
\begin{figure}
\begin{center}
\subfloat[Plot1]{
\begin{tikzpicture}[trim axis left]
\begin{axis}[width=0.8\textwidth,height=0.35\textheight,
grid,
xlabel near ticks,
ylabel near ticks,
xmin=0,
xmax=6,
xlabel={t}]
\addplot coordinates {(1,6.45)(2,3.4)(3,4.8)(4,4.1)(5,4.4)};
\end{axis}
\begin{axis}[width=0.8\textwidth,height=0.35\textheight,
axis y line*=right,
grid,
xmin=0,
xmax=6,
xlabel near ticks,
ylabel near ticks]
\addplot coordinates {(1,66.4)(2,43.4)(3,4.8)(4,4.1)(5,9.4)};
\end{axis}
\end{tikzpicture}
}
\subfloat[Plot2]{
\begin{tikzpicture}[trim axis left]
\begin{axis}[width=0.8\textwidth,height=0.3\textheight,
grid,
xmin=0,
xmax=6,
xlabel={t},
legend pos=north east]
\addplot coordinates {(1,6666.4)(2,433.4)(3,4.8)(4,4.1)(5,9.4)};
\end{axis}
\end{tikzpicture}
}
\caption{Figure 1}
\end{center}
\end{figure}
\end{document}
答案1
对右侧使用相同的选项:
\begin{tikzpicture}[trim axis left,trim axis right]
代码:
\documentclass[a4paper,12pt]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{pifont}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}% loads also tikz
\pgfplotsset{
/pgf/number format/use comma,
compat=1.12% current version
}
\usepackage{subfig}
\begin{document}
\begin{figure}
\begin{center}
\subfloat[Plot1]{
\begin{tikzpicture}[trim axis left,trim axis right]
\begin{axis}[width=0.8\textwidth,height=0.35\textheight,
axis y line*=left,
grid,
%xlabel near ticks,
%ylabel near ticks,
xmin=0,
xmax=6,
xlabel={t}]
\addplot coordinates {(1,6.45)(2,3.4)(3,4.8)(4,4.1)(5,4.4)};
\end{axis}
%
\begin{axis}[width=0.8\textwidth,height=0.35\textheight,
axis y line*=right,
axis x line=none,
ymajorgrids,
xmin=0,
xmax=6,
%xlabel near ticks,
%ylabel near ticks
]
\addplot coordinates {(1,66.4)(2,43.4)(3,4.8)(4,4.1)(5,9.4)};
\end{axis}
\end{tikzpicture}
}
\subfloat[Plot2]{
\begin{tikzpicture}[trim axis left,trim axis right]
\begin{axis}[width=0.8\textwidth,height=0.3\textheight,
grid,
xmin=0,
xmax=6,
xlabel={t},
legend pos=north east]
\addplot coordinates {(1,6666.4)(2,433.4)(3,4.8)(4,4.1)(5,9.4)};
\end{axis}
\end{tikzpicture}
}
\caption{Schöner Mist}
\end{center}
\end{figure}
\end{document}