如何使特定节点的单行文本对齐?

如何使特定节点的单行文本对齐?

在下面的代码中,最后第二个矩形框包含的文本不在一行中,尽管存在很大的空间。

我该如何做才能不丢失另一个框中的文本?单线效果应该只出现在最后一秒的框中。

以下文本必须合并为一行:“映射和分类”

\documentclass[border=3.14mm,tikz]{standalone}
 \usetikzlibrary{chains,positioning,calc,shapes.geometric}
 \begin{document}
    \begin{center}
         \begin{tikzpicture}[font=\sffamily,boxed/.style={minimum width=1.7cm,minimum height=1cm,draw,thick,text width=1.9cm,text centered},node distance=.3cm] 
         \begin{scope}[local bounding box=upper]
          \begin{scope}[start chain=1 going below,every join/.style={-latex,thick},frm/.style={boxed,on chain=1,join}]
       \node[on chain=1](n0) {Training data};
       \node[frm](n1) {abc check check};
       \node[frm](n2) {abc check check };
       \node[frm](n3) {abc check check check};
       \node[frm](n4) {abc check check};
      \end{scope} 
      \node[boxed,right=2.2cm of n1] (n5) {check check abc}; 
      \node[boxed,right=3.5mm of n2] (n6) {abc check}; 
      \node at (n0-|n6) (n7) {Testing data};
      \node[boxed,right=1cm of n3] (n8) {check check checkabc}; 
      \end{scope}
      \draw let \p1=($(upper.east)-(upper.west)$) in 
       node[boxed,below=5mm of upper,minimum width=\x1] (n9) {mapping and classification};
      \node[below=3mm of n9,
        trapezium,trapezium left angle=60,trapezium right angle=120,
        minimum width=3cm,minimum height=1cm,draw,thick] (n10) {abc check};
      \begin{scope}[every edge/.style={draw,-latex,thick}]  
       \path (n7) edge (n6) (n6.-140) edge (n9.north-|n6.-140) 
       (n1) edge (n5) (n5) edge (n9.north-|n5.south)
       (n6.south-|n8) edge (n8) (n8) edge (n9.north-|n8.south)
       (n4) edge (n9.north-|n4) (n9) edge (n10);
      \end{scope}
    \end{tikzpicture}
    \end{center}
 \end{document}

下面的图就是上面的代码体现出来的。在此处输入图片描述

答案1

添加选项text width

\documentclass[border=3.14mm,tikz]{standalone}
 \usetikzlibrary{chains,positioning,calc,shapes.geometric}
 \begin{document}
         \begin{tikzpicture}[font=\sffamily,boxed/.style={minimum width=1.7cm,minimum height=1cm,draw,thick,text width=1.9cm,text centered},node distance=.3cm] 
         \begin{scope}[local bounding box=upper]
          \begin{scope}[start chain=1 going below,every join/.style={-latex,thick},frm/.style={boxed,on chain=1,join}]
       \node[on chain=1](n0) {Training data};
       \node[frm](n1) {abc check check};
       \node[frm](n2) {abc check check };
       \node[frm](n3) {abc check check check};
       \node[frm](n4) {abc check check};
      \end{scope} 
      \node[boxed,right=2.2cm of n1] (n5) {check check abc}; 
      \node[boxed,right=3.5mm of n2] (n6) {abc check}; 
      \node at (n0-|n6) (n7) {Testing data};
      \node[boxed,right=1cm of n3] (n8) {check check checkabc}; 
      \end{scope}
      \draw let \p1=($(upper.east)-(upper.west)$) in 
       node[boxed,below=5mm of upper,minimum width=\x1,text width=\x1] (n9) {mapping and classification};
      \node[below=3mm of n9,
        trapezium,trapezium left angle=60,trapezium right angle=120,
        minimum width=3cm,minimum height=1cm,draw,thick] (n10) {abc check};
      \begin{scope}[every edge/.style={draw,-latex,thick}]  
       \path (n7) edge (n6) (n6.-140) edge (n9.north-|n6.-140) 
       (n1) edge (n5) (n5) edge (n9.north-|n5.south)
       (n6.south-|n8) edge (n8) (n8) edge (n9.north-|n8.south)
       (n4) edge (n9.north-|n4) (n9) edge (n10);
      \end{scope}
    \end{tikzpicture}
 \end{document}

在此处输入图片描述

相关内容