The code adds some completely useless invisible (or rather white) stuff. The lines
\clip(0pt,403pt) -- (389.957pt,403pt) -- (389.957pt,99.6166pt) -- (0pt,99.6166pt) -- (0pt,403pt);
\color[rgb]{1,1,1}
\fill(3.76406pt,399.236pt) -- (380.923pt,399.236pt) -- (380.923pt,253.19pt) -- (3.76406pt,253.19pt) -- (3.76406pt,399.236pt);
\fill(53.4497pt,394.719pt) -- (374.901pt,394.719pt) -- (374.901pt,289.325pt) -- (53.4497pt,289.325pt) -- (53.4497pt,394.719pt);
draw a white background that is larger than the actual picture. TikZ sees that and thinks it is part of the picture. Simply removing/uncommenting these lines removes most of the whitespace.
Near the end of the first scope,
\color[rgb]{1,1,1}
\fill(3.76406pt,249.426pt) -- (386.193pt,249.426pt) -- (386.193pt,103.381pt) -- (3.76406pt,103.381pt) -- (3.76406pt,249.426pt);
does the same.
Additionally (near the end of the second scope
),
\pgftext[center, base, at={\pgfpoint{220.95pt}{106.392pt}}]{\sffamily\fontsize{9}{0}\selectfont{\textbf{ }}}
adds a blank node below the picture, again enlarging the bounding box.
Removing all those lines gives a tight bounding box.
As far as I know, TikZ cannot do the cropping for you, as it can't know whether the white stuff is intentional or not (there might for example be a dark background behind the image so that white is visible).
It's not the xshift
, it's the transform canvas
that causes this behaviour. As it says in the pgfmanual
:
when you use canvas transformations pgf
loses track of positions of
nodes and of picture sizes since it does not take the effect of canvas
transformations into account when it computes coordinates of nodes
You should put the xshift
into the options for the y2
node instead:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{scopes}
\usetikzlibrary{chains}
\usetikzlibrary{backgrounds} % used only for testing with "framed"
\newcommand{\parlistrdeepseq}{
\begin{tikzpicture}
[start chain=going below,
every on chain/.append style={join},
every join/.style={->},
framed]
\node[on chain] { map f (28:28:28:28:[]) };
\node(x1)[on chain] { f 28 : (map f (28:28:28:[])) };
% \node(y1)[below=of \tikzchainprevious.south, xshift=-3cm] {|f 28|};
{ [start chain=t1 going below]
\node(y1)[on chain, left=of x1, yshift=-1cm] {f 28};
\node[on chain] {514229};
\path (x1.south west) edge[->] (y1);
}
\node(x2)[on chain] { y : f 28 : (map f (28:28:[])) };
{ [start chain=t2 going below]
\node(y2)[on chain, left=of x2, xshift=1cm, yshift=-1cm] {f 28};
\node[on chain] {514229};
\path (x2.south west) edge[->] (y2);
}
\node[on chain] { y : y : y : y []};
\end{tikzpicture}}
\begin{document}
\parlistrdeepseq
\end{document}
Best Answer
You need to set the
inner sep
to zero. It's the separation between the inner content and the outer frame (which is only visible if you usedraw
). There is alsoouter sep
which is by default half of the drawing line width (.5\pgflinewidth
) and places the anchors at the outer side of the frame lines, not it the middle. You might want to set it also to zero to get exactly the border of the image.See also the related question Drawing on an image with TikZ.