如何使用轴作为水平对齐的锚点?

如何使用轴作为水平对齐的锚点?

在此处输入图片描述

我希望这两个距离相等,当我添加 y 标签时,它会将轴“推”向右。有没有办法在 tikz/pgf 中固定轴?

\documentclass{article}
\usepackage{float}
\usepackage{pgfplots}

\pgfplotsset{compat=1.18} 

\begin{document}

\begin{figure}[H]
\centering
    \begin{tikzpicture}
    \centering
        \begin{axis}[
        ylabel = {something},
        ]
        \addplot{x^2};
        \end{axis}
    \end{tikzpicture}
\end{figure}

\end{document}

答案1

\documentclass{article}
\usepackage{float}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} 
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}[trim axis left, trim axis right]
\begin{axis}[
ylabel={something},
]
\addplot{x^2};
\end{axis}
\end{tikzpicture}
\end{figure}
\begin{tikzpicture}[remember picture, overlay]
\draw[dashed] (current page.north) -- (current page.south);
\end{tikzpicture}
\end{document}

页面居中图表

相关内容