如何在 TikZ 树或图表中向下和向右分叉

如何在 TikZ 树或图表中向下和向右分叉

我需要你帮我画一个图表,我想把叉子放在下面和右边来组织我的概念图。
如果有人有更好的解决方案,请给我一些建议。
代码如下:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
\begin{center}
\begin{tikzpicture}[
edge from parent fork down,
edge from parent/.style={black,thick,draw},
every node/.style={rectangle,draw,rounded corners},
every child node/.style={anchor=north},
par node/.style={
    text width=#1,
    align=left,
},
par node/.default=40mm,
parent anchor=south,
growth parent anchor=south,
]

\node[par node] (p) at (0,0) {
    \begin{center}\textbf{TITLE}\\\end{center}
    Long text long text long text long text long text long text
}[sibling distance=50mm]
child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}
    [sibling distance=27mm]
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
}
child {node [par node] {\textbf{Title}\\ Long text long text long text long text long text long text}[sibling distance=27mm]
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}}
    }
child {node [par node]{\textbf{Title}\\ Long text long text long text long text long text long text}
    [sibling distance=27mm]
    child {node[par node]{\textbf{Title}\\ Long text long text long text long text long text long text}
    }
};
\end{tikzpicture}
\end{center}
\end{document}

我想要这样的东西:

图像

答案1

这是 Forest 版本。它使用了版本 2,当第一次提出这个问题时,该版本尚未发布。

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage[edges]{forest}
\forestset{%
  dir tree switch forking/.style args={at #1}{%
    for tree={
      font=\sffamily,
      fit=rectangle,
    },
    where level=#1{
      for tree={
        folder,
        grow'=0,
      },
      delay={
        child anchor=north,
        !u.parent anchor=south,
        edge path'={(!u.parent anchor) -- ++(0,-\forestoption{fork sep}) -| (.child anchor)}
      },
    }{
      if={level()<(#1)}{
        forked edge,
        parent anchor=children,
        child anchor=parent,
      }{},
    },
    before typesetting nodes={
      for tree={
        content/.wrap value={\strut ##1},
      },
      if={isodd(n_children("!r"))}{
        for nodewalk/.wrap pgfmath arg={{fake=r,n=##1}{calign with current edge}}{int((n_children("!r")+1)/2)},
      }{},
    },
  },
  node title/.style={
    content={\textbf{#1}},
  },
  node descriptor/.style={content+={\\#1}},
  title splitter/.style={
    before typesetting nodes={
      split option={content}{:}{node title,node descriptor},
    },
  },
  title split/.style={
    for tree={title splitter},
  },
}
\begin{document}
\begin{forest}
  dir tree switch forking=at 1,
  title split,
  where level=0{align=center}{text width=30mm},
  for tree={draw},
  [Title:Long text long text long text long text long text long text
    [Title:Long text long text long text long text long text long text
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
    ]
    [Title:Long text long text long text long text long text long text
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
      [Title:Long text long text long text long text long text long text]
    ]
    [Title:Long text long text long text long text long text long text
      [Title:Long text long text long text long text long text long text]
    ]
  ]
\end{forest}
\end{document}

森林版

然后,我们可以非常直接地设置树的样式,例如,修改以下行

  for tree={draw},

让树更有趣一点

  for tree={draw=darkgray, thick, rounded corners, top color=gray!5, bottom color=gray!15, blur shadow, edge+={thick}},

森林树木,风格

答案2

这是我用来获取概念图的。但我不喜欢重叠的线条。

\documentclass{article}
\usepackage{tikz,array}
\usetikzlibrary{trees}

\begin{document}
\begin{tikzpicture}

 \draw (5,10.5) node (efectof) [draw,fill=black!15,rounded corners,align=left,text width=70mm]{\begin{tabular}{m{67mm}} \center\textbf{text}\\ text\\ \end{tabular} };

 \draw (0,7.9) node (efectoi1) [draw,rounded corners,align=left,text width=42mm]{ \textbf{text}\\ \small{text}};
 \draw (5,7.9) node (efectoi2) [draw,rounded corners,align=left,text width=42mm]{ \textbf{text}\\ \small{text}};
 \draw (10,7.9) node (efectoi3) [draw,rounded corners,align=left,text width=42mm]{ \textbf{text}\\ \small{text}};

\draw (efectof) --++(0,-16mm)-| (efectoi1);
\draw (efectof) -- (efectoi2);
\draw (efectof) --++(0,-16mm)-| (efectoi3);

 \draw (0,5.7) node (efectod1) [draw,rounded corners,align=left,text width=42mm]{ \textbf{text}\\ \small{text}};
 \draw (5,5.7) node (efectod2) [draw,rounded corners,align=left,text width=42mm]{ \textbf{text}\\ \small{text}};
 \draw (10,5.7) node (efectod3) [draw,rounded corners,align=left,text width=42mm]{ \textbf{text}\\ \small{text}};

\draw (efectod1) -- (efectoi1);
\draw (efectod2) -- (efectoi2);
\draw (efectod3) -- (efectoi3);

 \draw (5,3) node (problema) [draw,fill=black!15,rounded corners,align=left,text width=70mm]{\begin{tabular}{m{70mm}} \center\textbf{text}\\ text\\\end{tabular} };

\draw (problema) --++(0,15mm)-| (efectod1);
\draw (problema) -- (efectod2);
\draw (problema) --++(0,15mm)-| (efectod3);

 \draw (0,0) node (causa1) [draw,rounded corners,align=left,text width=40mm]{ \textbf{text}\\ \small{text}};
 \draw (5,0) node (causa2) [draw,rounded corners,align=left,text width=40mm]{ \textbf{text}\\ \small{text}};
 \draw (10,0) node (causa3) [draw,rounded corners,align=left,text width=40mm]{ \textbf{text}\\ \small{text}};

\draw (problema) --++(0,-16mm)-| (causa1);
\draw (problema) -- (causa2);
\draw (problema) --++(0,-16mm)-| (causa3);

 \draw (0,-2.2) node (indir1) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};
 \draw (0,-4.4) node (indir2) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};
 \draw (0,-6.6) node (indir3) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};
 \draw (0,-8.8) node (indir4) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};

\draw (causa1.west)--++(-5mm,0mm)|-(indir1.west);
\draw (causa1.west)--++(-5mm,0mm)|-(indir2.west);
\draw (causa1.west)--++(-5mm,0mm)|-(indir3.west);
\draw (causa1.west)--++(-5mm,0mm)|-(indir4.west);

 \draw (5,-2.2) node (indir5) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};
 \draw (5,-4.4) node (indir6) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};
 \draw (5,-6.6) node (indir7) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};
 \draw (5,-8.8) node (indir8) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};
 \draw (5,-10.5) node (indir9) [draw,rounded corners,align=left,text width=30mm]{\textbf{text}\\ \small{text}};

\draw (causa2.west)--++(-5mm,0mm)|-(indir5.west);
\draw (causa2.west)--++(-5mm,0mm)|-(indir6.west);
\draw (causa2.west)--++(-5mm,0mm)|-(indir7.west);
\draw (causa2.west)--++(-5mm,0mm)|-(indir8.west);
\draw (causa2.west)--++(-5mm,0mm)|-(indir9.west);

 \draw (10,-2.2) node (indir10) [draw,rounded corners,align=left,text width=30mm]{\small{\textbf{text}\\ text}};

\draw (causa3.east)--++(4mm,0mm)|-(indir10.east);

\end{tikzpicture}

\end{document}

概念图

答案3

这是另一种解决方案。

\documentclass[10pt]{memoir}
\input{outline}

\begin{document}
\begin{Outline}
\node [nroot] {root} [godown,sidi=1.80in]
    child {node[nsec] {one}}
    child {node[nsec] {two}}
    child [xshift=-0.80in,yshift=0.20in]{
        child [godownc=1.00] {node[nsec,yshift=-0.25in] {Text 1}}
        child [godownc=1.00] {node[nsec,yshift=-0.75in] {Text 2}}
        child [godownc=1.00] {node[nsec,yshift=-1.25in] {Text 3}}
    }
;
\end{Outline}
\end{document}

使用以下内容outline.tex

%========================================================================== 
% Outline
% This template provides a simplified way to create tree-like mindmaps,
% which could be diagrams for handouts. 
% Thursday, November 17, 2016  
%
% Styles defined:
% ledi       = 'level distance', defaults to 2.0
% sidi       = 'sibling distance', defaults to 2.0
% goright    = grows right, becoming a straight line when needed
% goup       = grows up, straight
% godown     = grows down, straight
% nroot      = style for root
% nsec       = style for main concept
% nsubsec    = style for subconcept
% nsubsubsec = style for subconcept
% ntext      = text without frame
%
% Note:
% The parameters need to have double # because they are defined and
% used within an environment definition.
% ====================================================================
\usepackage{tikz}
\usetikzlibrary{calc,trees,arrows,arrows.meta,positioning,shapes.geometric}
%
%
\newenvironment{Outline}{%
\begin{center}%
\begin{tikzpicture}
[
% level and sibling distance defaults
% level 1/.style={level distance=0.80in,sibling distance=0.50in},
% level 2/.style={level distance=1.00in,sibling distance=0.40in},
% level 3/.style={level distance=1.20in,sibling distance=0.30in},
% goright
goright/.style={
    level distance=##1 in,
    edge from parent fork right,
    grow'=right,
    edge from parent path=
    {(\tikzparentnode.east)
    .. controls +(1,0) and +(-1,0)..
     (\tikzchildnode.west)}
},
goright/.default=1.00,
godown/.style={
    level distance=##1 in,
    edge from parent fork down,
    grow'=down,
    edge from parent path=
    {(\tikzparentnode.south)
    .. controls +(0,-1) and +(0,1)..
     (\tikzchildnode.north)}
},
godown/.default=1.00,
godownc/.style={
    level distance=##1 in,
    edge from parent fork down,
    grow'=right,
    edge from parent path=
    {(\tikzparentnode.south)
    .. controls +(0,-1) and +(-1,0)..
     (\tikzchildnode.west)}
},
godownc/.default=1.00,
goup/.style={
    level distance=##1 in,
    edge from parent fork up,
    grow'=up,
    edge from parent path=
    {(\tikzparentnode.north)
    .. controls +(0,1) and +(0,-1)..
     (\tikzchildnode.south)}
},
goup/.default=1.00,
goupc/.style={
    level distance=##1 in,
    edge from parent fork up,
    grow'=right,
    edge from parent path=
    {(\tikzparentnode.north)
    .. controls +(0,1) and +(-1,0)..
     (\tikzchildnode.west)}
},
goupc/.default=1.00,
sidi/.style={
    sibling distance=##1
},
ledi/.style={
    level distance=##1
},
% root node with a text width defined by the argument 
nroot/.style   ={
    inner sep      =0.50em,
    minimum size   =0.50in,
    rectangle,
    rounded corners=0.2in,
    draw           =black,
    text width     =##1 in,
    align          =center,
    font={\Large\scshape \openup -0.65em}
    },
nroot/.default =1.2,
% node - section
nsec/.style   ={
    inner sep      =0.50em,
    minimum size   =0.25in,
    rectangle,
    rounded corners=0.10in,
    line width     =0.50pt,
    draw           =black,
    solid,
    text width     =##1 in,
    align          =center,
    font={\large \openup -0.35em}
    },
nsec/.default=1.1,
% node - subsection
nsubsec/.style   ={
    inner sep      =0.06in,
    minimum size   =0.20in,
    rectangle,
    rounded corners=0.05in,
    line width     =0.50pt,
    draw           =black,
    text width     =##1 in,
    align          =center,
    font={\openup -0.45em}
    },
nsubsec/.default =1.0,
% node - subsubsection
nsubsubsec/.style   ={
    inner sep      =0.05in,
    minimum size   =0.20in,
    rectangle,
    rounded corners=0.01in,
    line width     =0.40pt,
    draw           =black,
    text width     =##1 in,
    align          =center,
    font={\openup -0.65em}
    },
nsubsubsec/.default =1.0,
% node - text
ntext/.style   ={
    sibling distance=0.18in,
    inner sep      =0.10in,
    minimum size   =0.40in,
    text width     =##1 in,
    font={\small \openup -0.20em}
    },
ntext/.default =3.0,
node distance     =0.45in and 0.45in,
scale             =1.00,
every node/.style ={scale=1.00},
remember picture
]}
%
{%
\end{tikzpicture}
\end{center}
}
%====================================================================== EOF

其结果为:

PDF

相关内容