边界框与 xshift

边界框与 xshift

下图中的xshift边界框被打破了:

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

带有错误边界框的输出是: 在此处输入图片描述

答案1

导致此行为的原因不是xshift,而是transform canvas。正如 中所述pgfmanual

使用画布变换时,pgf会丢失节点位置和图片大小的轨迹,因为它在计算节点坐标时没有考虑画布变换的影响

您应该将其放入节点xshift的选项y2中:

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

相关内容