TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
The straight-forward and manual way would be use negative spacing (via \hspace*{<hspace>}). But I guess you want something more robust. – Werner Aug 10 '11 at 18:01
Related question: Centering a TikZ picture around an area – Martin Scharrer Aug 10 '11 at 18:21
@Martin: I missed it. If I am correct, it is from May: is there something new? – pluton Aug 10 '11 at 19:41
up vote 5 down vote accepted

Using pgf 2.10, you can provide the arguments trim axis left and trim axis right to the tikzpicture environment:



\begin{tikzpicture}[trim axis left, trim axis right]
    \addplot {x^2};


\bigskip \bigskip

\begin{tikzpicture} % Example of leaving this out
    \addplot {x^2};




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

share|improve this answer
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 on trim left axis and trim right axis though! – 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 pgfplots manual, that refers to pgf 2.00: the relevant code has been incorporated into pgf 2.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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.