I'm wondering about a way to exclude the axis labels and axis graduation from how latex will center the figure with respect to the caption. Labels and graduation along the y-axis (assuming it lies on the left of the figure) will tend to move the rest of the content to the right. I feel like it looks better when only the "main" content serves for centering purposes. Is such feature available?
Asked
Active
Viewed 5,288 times
8
1 Answers
12
Using pgf 2.10, you can provide the arguments trim axis left and trim axis right to the tikzpicture environment:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\centering
\begin{tikzpicture}[trim axis left, trim axis right]
\begin{axis}[ylabel={$y$},
xlabel={$x$}]
\addplot {x^2};
\end{axis}
\end{tikzpicture}
(a)
\bigskip \bigskip
\begin{tikzpicture} % Example of leaving this out
\begin{axis}[ylabel={$y$},
xlabel={$x$}]
\addplot {x^2};
\end{axis}
\end{tikzpicture}
(a)
\end{document}
gives

This works without disturbing the bounding box for the purposes of image externalisation and so forth (avoiding some of the problems discussed in @Martin's earlier question).
-
I've updated your code and image to more clearly highlight the experimental feature of
pgfplots. The wide y-axis label distracted from the horizontal alignment, since there was no context (like a label(a), say, that I've added). Feel free to rollback if this is unwanted. Good find ontrim left axisandtrim right axisthough! – Werner Aug 10 '11 at 20:47 -
oh, I see - yes, this is a better way of demonstrating the centering than artificially broadening the y-axis label and needing to show the page margins. Thanks! Incidentally, although this is marked as experimental in the
pgfplotsmanual, that refers topgf2.00: the relevant code has been incorporated intopgf2.10 so it should be pretty generally usable, I think. – Ant Aug 10 '11 at 21:04 -
You're right - I was looking at an older version of the manual. Actually, much older than 2.00. – Werner Aug 10 '11 at 21:05
-
I've tried the provided code in a externalization setting, and the margins are not updated, meaning there is no centering. Is there something else that can be done then? – pluton Jun 15 '12 at 13:47
\hspace*{<hspace>}). But I guess you want something more robust. – Werner Aug 10 '11 at 18:01