Take the 2-minute tour ×
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.

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

1 Answer 1

up vote 4 down vote accepted

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

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

 
discard

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.