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

My figures are always off-center because the right axis is trimmed closer to the figure than the left. Do I have to manually extend the right axis by an adhoc amount every time?

enter image description here

\usepackage{pgfplots, pgfplotstable}

        %width  = 0.85*\textwidth,
        %height = 8cm,
        %major x tick style = transparent,
        bar width=20pt,
        %ymajorgrids = true,
        ylabel = {Deposition \%},
        symbolic x coords={{4  ac.h$^{-1}$},{6  ac.h$^{-1}$}},
        xtick = {{4  ac.h$^{-1}$},{6  ac.h$^{-1}$}},
        scaled y ticks = false,
        enlarge x limits=0.25,
        legend cell align=left,
        legend style={
                anchor=south east,
                column sep=1ex

        \addplot [fill=black, draw=black,bar shift=3pt] coordinates {({4  ac.h$^{-1}$},61.66779959)}; %\addlegendentry{4  ac.h$^{-1}$}
\addplot [fill=white, draw=black,bar shift=-3pt] coordinates {({6  ac.h$^{-1}$},65.77432124)};
%\addplot [fill=white, draw=black, bar shift=0.5ex] table [x=X, y=6ACH]  {\datatable}; \addlegendentry{6  ac.h$^{-1}$}


This doesn't seem to work for standalone document class pgfplots and figure centering

and this is adhoc: Centering a TikZ picture around an area Excel: 5 seconds but no Tex formatting and wrong fonts. enter image description here


Axis labels are cut off and part of the ytick enter image description here


\begin{tikzpicture}[trim axis left, trim axis right]

area legend,
scale only axis,
xticklabels={Equipment,Patient,{Hygiene products},Near-bed,Far-bed},
ytick={  0, 0.1, 0.2, 0.3, 0.4},
ylabel={Probability density},yticklabel style={/pgf/number format/fixed},
legend style={at={(0.143572984749455,0.733206590621038)},anchor=south west,draw=black,fill=white,legend cell align=left}
\addplot[ybar,bar width=0.282321428571429in,bar shift=-0.176450892857143in,fill=mycolor1,draw=black] plot coordinates{(1,0.163793103)

\addlegendentry{Smith et al.};

\addplot [
forget plot
table[row sep=crcr]{
0.5 0\\
5.5 0\\
\addplot[ybar,bar width=0.282321428571429in,bar shift=0.176450892857143in,fill=white,draw=black] plot coordinates{(1,0.165289256)

\addlegendentry{Adjusted YAB};

share|improve this question
Producing nonsense in 5 seconds is not better than making a decent plot with others :) So make a fair comparison. Don't underestimate the force... Don't forget to floss. :P tex.stackexchange.com/questions/109299/… – percusse Apr 19 '13 at 12:35
If you use \begin{tikzpicture}[trim axis left, trim axis right], the axis will be centered correctly. – Jake Apr 19 '13 at 12:40
@Jake That's what I thought. But it cuts off my ylabel – HCAI Apr 19 '13 at 12:44
@HCAI: Kind of, yes: It's no longer inside the bounding box, but it's still in the pdf. If you include the file in a document, the label will show up correctly. – Jake Apr 19 '13 at 12:45
@percusse Undoubtedly accurate on all accounts. So: Producing nonsense in 5 seconds is not better than making a decent plot in hours :) – HCAI Apr 19 '13 at 12:46

If you use \begin{tikzpicture}[trim axis left, trim axis right], the axis will be centered correctly.

share|improve this answer

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.