在 pgfplots 中,如何使具有辅助 y 轴的图形与没有辅助 y 轴的图形宽度相同?我已经指定了相同的宽度,但在输出中显然它们的宽度不同。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
% 1st graph
\begin{tikzpicture}
\centering
\pgfplotsset{set layers}
\begin{axis}\[
width = 0.8\textwidth,
scale only axis,
axis y line* = left,
title = {1st Graph},
\]
\end{axis}
\begin{axis}\[
width = 0.8\textwidth,
scale only axis,
axis y line* = right,
axis x line = none,
\]
\end{axis}
\end{tikzpicture}
% 2nd graph
\begin{tikzpicture}
\centering
\begin{axis}\[
width = 0.8\textwidth,
title = {2nd Graph},
\]
\end{axis}
\end{tikzpicture}
\end{document}
答案1
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=0.8\textwidth,
scale only axis,
axis y line*=left,
title={1st Graph},
]
\end{axis}
\begin{axis}[
width=0.8\textwidth,
scale only axis,
axis y line*=right,
axis x line=none,
]
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
width=0.8\textwidth,
scale only axis,
title={2nd Graph},
]
\end{axis}
\end{tikzpicture}
\end{document}