[Tex/LaTex] pgfplots and figure centering

horizontal alignmentpgfplots

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?

Best 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

2 graphs, of which the first is centred ignoring a very wide y axis title

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).

Related Question