[Tex/LaTex] Bounding box vs. xshift

bounding boxtikz-pgf

The xshift in the following figure breaks the bounding box:

\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, transform canvas={xshift=1cm}]
       \node(y2)[on chain, left=of x2, 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}

The output with the wrong bounding box is:
enter image description here

Best Answer

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}