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?
1 Answer
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 axis
andtrim right axis
though!– Werner ♦Aug 10, 2011 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
pgfplots
manual, that refers topgf
2.00: the relevant code has been incorporated intopgf
2.10 so it should be pretty generally usable, I think.– AntAug 10, 2011 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, 2011 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?– plutonJun 15, 2012 at 13:47
\hspace*{<hspace>}
). But I guess you want something more robust.