I create a tikzpicture in standalone mode (see code below). Then import the resultant .pdf file into my document via \includegraphics (see pic). However the axis labels are cut off and part of the ytick when using [trim axis left, trim axis right]. If I don't use that command it looks fine but is not centered any more. Any thoughts?

PS this is a duplicate but perhaps more concise of this Pgfplot figure off-center because of axis label

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};


1 Answer 1


One thing you could do is (manually) increase the border around the graph. The standalone package allows the left and right borders to be set independently of the top and bottom borders. So, if you change



\documentclass[tikz,border={38pt 12pt}]{standalone}

then your y-axis labels will not be cropped, and your graph will remain centred. The only downside is that this is a bit of a dirty hack!

  • Very nice! thank you. By the way how did you decide on 38pt? ie how did you know teh graph would still be centered?
    – HCAI
    May 3, 2013 at 12:09
  • You're welcome. You had already centred the graph using your [trim axis left, trim axis right]. My border={38pt 12pt} then adds a 38pt border to the left and right equally, which keeps the graph centred, whichever numbers are used. I just came up with 38pt by trial and error. May 3, 2013 at 12:13
  • Ah I see! So is the 38pt graph size dependent?
    – HCAI
    May 3, 2013 at 12:32
  • Yes, it depends on the size of the labels and ticks to the left of your axis. In other words, my solution is not particularly elegant. May 3, 2013 at 16:39
  • 1
    Yes. Put xtick pos=left and ytick pos=left in your axis options. (The default is both.) May 4, 2013 at 7:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .