当我添加 Y 轴标签时,当我尝试将其居中时,pgf 图生成的轴会错位。当我在它前面有一个表格时,这种情况会变得更加明显。如何才能使轴居中而不让 Y 轴将图形“推”到右侧。
\documentclass[11pt, a4paper]{article}
\usepackage{tikz}
\usepackage{float}
\usepackage{pgfplots}
\usepackage{booktabs}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{@{}lllll@{}}
\toprule
bla bla & bla bla & bla bla & bla bla & bla bla \\ \midrule
0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\ \bottomrule
\end{tabular}
\end{table}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\begin{axis}[
ylabel={something}
]
\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}