如何在-22後面加上-23-24-25而不增加更多子項?

如何在-22後面加上-23-24-25而不增加更多子項?
%%%use PDFLATEX
\documentclass{article}


\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning}




\tikzset{edge from parent/.style=
{draw,
edge from parent path={(\tikzparentnode.east)
-- +(14pt,0)
|- (\tikzchildnode)}}}






\begin{document}\large




\vspace{1cm}


\begin{tikzpicture}
\tikzset{grow'=right,level distance=100pt}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west}}


\Tree
[.\node(yawei){yawei};
 [.\node(muqiu){muqiu}; ]
 ]


 \begin{scope}[every node/.style={align=center, anchor=center, font=\normalsize\sffamily\bfseries,rectangle,draw,text width=1.4cm,}]
 \node[above= 2mm of muqiu ] (thenode) {22};
 \node[at =(thenode-|yawei)] {21};
\end{scope}
\end{tikzpicture}








\end{document}

我想要這個風格

在此輸入影像描述

答案1

不確定你想做什麼,但為什麼不像你已經開始做的那樣添加更多的孩子呢?

% arara: pdflatex

\documentclass[tikz, border=5]{standalone}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning}

\begin{document}\large      
\begin{tikzpicture}
    \tikzset{grow'=right,level distance=100pt}
    \tikzset{execute at begin node=\strut}
    \tikzset{every tree node/.style={anchor=base west}} 

    \Tree
    [.\node(yawei){yawei};
    [.\node(muqiu){muqiu}; 
    [.\node(1){1}; [.\node(2){2}; [.\node(3){3}; [.\node(4){4}; ]]]]
    ]   
    ]   

    \begin{scope}[every node/.style={align=center, anchor=center, font=\normalsize\sffamily\bfseries,rectangle,draw,text width=1.4cm,}]
    \foreach \x/\y in {yawei/21, muqiu/22, 1/23, 2/24, 3/25, 4/26}{%
    \node[above= 2mm of \x ] (the\x) {\y};
}
    \end{scope}
\end{tikzpicture}   
\end{document}

在此輸入影像描述

答案2

將節點添加到當前程式碼的最簡單方法可能是將它們簡單地放置在 22 的右側:

\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{tikz-qtree}
\usetikzlibrary{positioning}
\tikzset{%
  edge from parent/.style={%
    draw,
    edge from parent path={(\tikzparentnode.east) -- +(14pt,0) |- (\tikzchildnode)},
  },
}
\begin{document}\large
\begin{tikzpicture}
  [
    grow'=right,
    level distance=100pt,
    execute at begin node=\strut,
    every tree node/.style={anchor=base west},
  ]
  \Tree
  [.\node(yawei){yawei};
    [.\node(muqiu){muqiu}; ]
  ]
  \begin{scope}[every node/.style={align=center, anchor=center, font=\normalsize\sffamily\bfseries, rectangle, draw, text width=1.4cm,}]
    \node [above=2mm of muqiu] (thenode) {22};
    \node at (thenode-|yawei) {21};
    \node (next) [right=of thenode] {23};
    \node (one after) [right=of next] {24};
    \node [right=of one after] {25};
  \end{scope}
\end{tikzpicture}
\end{document}

更多節點

如果圖表實際上沒有分支,則將節點放置在網格上或使用chains庫可能會更容易。然而,這將涉及重寫現有程式碼,如果只需要少量添加,這可能會帶來更多麻煩。

相關內容