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 am drawing an tikz picture using standalone class, but there is weird blank space on the left side. My code is





  gold/.style = {
    top color=gray!60, 
    bottom color=gray!20, 
    minimum width=0.25cm, 
    minimum height=2cm, 
  boron/.style = {
    top color=gray!80, 
    bottom color=gray!40,
    minimum width=1cm, 
    minimum height=2cm, 
  telescope/.style = {
    right color=black!70, 
    left color=black!20,
    minimum width=1.2cm,
    minimum height=.4cm,
  E/.style = {
     top color=black!80, 
     bottom color=black!40,
     minimum width=1.2cm,
     minimum height=1.4cm, 


  \coordinate (beam left) at (-5,0);
  \coordinate (beam right) at (2,0);

  % Incident Beam
  \draw[->, very thick] (beam left) -- (beam right);
  \node[above right] at (beam left) (proton) {$p^+$};

  % Target : Boron + Au
  \node[gold, label=95:$Au$] at (6,0) (gold) {};% Au
  \node[boron, right=0mm of gold, label=80:$^{nat}B$] (boron) {};

  \coordinate (hit) at (gold.west);

  % Telescopes
  \path (hit) -- +(170:8) 
        node[telescope, label=right:$6\mu m$] (telescope1) {$\Delta E$};
  \path (hit) -- +(-120:8)
        node[telescope, label=left:$22\mu m$] (telescope2) {$\Delta E$};
  \path (hit) -- +(170:9)
        node[E, label=20:$1000\mu m$] {$\mathbf{E}$};
  \path (hit) -- +(-120:9)
        node[E, label=left:$1000\mu m$]  {$\mathbf{E}$};

  % Angles
  \draw[dashed, gray, thick] (beam right) -- (hit);
  \draw[dashed, gray, thick] (hit) -- (telescope1);
  \draw[dashed, gray, thick] (hit) -- (telescope2);
  \draw[<->,thick] (hit)  +(180:2) arc (180:170:2);
  \path (hit) +(175:2) node[left] {$10^\circ$};
  \draw[<->,thick] (hit) +(180:2) arc (-180:-120:2);
  \path (hit) +(210:2) node[left] {$60^\circ$};


My output is the following

enter image description here

Any idea on why this is happening and how can it be fixed?

share|improve this question
\usetikzlibrary should go before \begin{document} –  egreg Jul 10 at 8:48
@egreg : You are right and that was the problem... Why did this happen? –  Thanos Jul 10 at 8:55
\usetikzlibrary takes up horizontal space I guess. –  1010011010 Jul 10 at 8:58

2 Answers 2

up vote 8 down vote accepted

Here's a minimalistic example:

\tikzset{} A

enter image description here

This shows that the space between \tikzset{} and A is not ignored. It would be the same for


So you have several of these spurious spaces, because tikzlibrarypositioning.code.tex starts with

\tikzset{above left/.code=\tikz@lib@place@handle@{#1}{south east}{-1}{1}{north west}{0.707106781}}

and so on for several lines.

The fact is that standalone puts TeX in LR mode (horizontal mode in proper TeX language), so spaces are not ignored.

You don't get any space if you add the varwidth option to standalone:


(but you get an overfull box warning, because of the picture size).

Load libraries and do \tikzset commands before \begin{document}.

share|improve this answer

If you put a \fbox{} around your tikzpicture you get:


Which shows that the extra space is not inside the tikzpicture. So it has to be produced by the code which is before it.

If you move \usetikzlibrary{positioning} to the preamble, as egreg suggested in a comment, you get now:


Which still has a (very small) gap to the left. This is due to the \tikzset settings, I'm not sure why (even removing all blank lines, this gap remains).

Moving \tikzset also to the preamble gives the desired result.

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.