![改变边缘类型并添加](https://linux22.com/image/459184/%E6%94%B9%E5%8F%98%E8%BE%B9%E7%BC%98%E7%B1%BB%E5%9E%8B%E5%B9%B6%E6%B7%BB%E5%8A%A0.png)
我是 tex 新手,正在创建流程图。我能够基于找到的一些模板进行构建,但无法修改 3 个功能:
- 我希望边缘(线)是“分叉的”,而不是成角度的线。
- 我想在最后一列的末尾放置(花括号),但我创建的边缘从最后一列的中心而不是右侧突出。应该有两个这样的括号,第一个括号括前 8 个框,第二个括号括后 8 个框。我还想在括号上放置标签,写着“v1”或“v2”。
- 最后,我想摆脱线顶部的 v/X/Y/Z 之间的边缘。
以下是我想要的结果:
目前的代码如下:
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usepackage[edges]{forest}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{center}
\setlength\PreviewBorder{10pt}%
%%%>
\usetikzlibrary{shapes,arrows}
\usepackage{caption}
\newcommand*{\h}{\hspace{5pt}}% for indentation
\newcommand*{\hh}{\h\h}% double indentation
\begin{document}
\begin{center}
\captionof{figure}{Flowchart}
% setting the typeface to sans serif and the font size to small
% the scope local to the environment
\sffamily
\footnotesize
\begin{tikzpicture}[
% level distance = 1.6cm,
% level 1/.style={sibling distance =3.5cm},
% level 2/.style = {sibling distane 1cm},
block_title/.style ={rectangle, draw=none, thick, fill=white,
text width=5em, text centered},
block_assign/.style ={rectangle, draw=black, thick, fill=white,
text width=18em, text ragged, minimum height=3em, inner sep=6pt},
block_lost/.style ={rectangle, draw=black, thick, fill=white,
text width=16em, text ragged, minimum height=3em, inner sep=6pt},
line/.style ={draw, thick, -latex', shorten >=0pt}]
% outlining the flowchart using the PGF/TikZ matrix funtion
[edge from parent/.style= {thick, draw= cyan, edge from parent fork right},
sibling distance=10em,level distance=6em,
every node/.style={shape=rectangle,draw,align=center}, grow=right]
\tikzstyle{level 1}=[sibling distance=25mm]
\tikzstyle{level 2}=[sibling distance=15mm]
\tikzstyle{level 3}=[sibling distance=7mm]
\node[block_title]{v} [grow' =right, right]
child{node[block_title] {X}
child{node[block_title] {Y}
child{node[block_title] {Z}}}
};
\end{tikzpicture}
\begin{tikzpicture}[
block_center/.style ={rectangle, draw=black, thick, fill=white,
text width=5em, text centered,
%minimum height=4em,
},
block_left/.style ={rectangle, draw=black, thick, fill=white,
text width=16em, text ragged, minimum height=4em, inner sep=6pt},
block_noborder/.style ={rectangle, draw=none, thick, fill=none,
text width=18em, text centered, minimum height=1em},
block_assign/.style ={rectangle, draw=black, thick, fill=white,
text width=18em, text ragged, minimum height=3em, inner sep=6pt},
block_lost/.style ={rectangle, draw=black, thick, fill=white,
text width=16em, text ragged, minimum height=3em, inner sep=6pt},
line/.style ={draw, thick, -latex', shorten >=0pt}]
% outlining the flowchart using the PGF/TikZ matrix funtion
% [edge from parent/.style= {thick, draw= cyan, edge from parent fork right},
% sibling distance=10em,level distance=6em,
% every node/.style={shape=rectangle,draw,align=center}, grow=right]
\tikzstyle{level 1}=[sibling distance=25mm]
\tikzstyle{level 2}=[sibling distance=12mm]
\tikzstyle{level 3}=[sibling distance=6mm]
\node[block_center]{V1} [grow' =right, right]
child{node[block_center] {R}
child{node[block_center] {111}
child{node[block_center] (test1) {A}}
child{node[block_center] {B}}}
child{node[block_center] {222}
child{node[block_center] {A}}
child{node[block_center] {B}}}
% child{node[block_center] {ut - White 2 (n=xx)}}
}
child{node[block_center] {G}
child{node[block_center] (test2) {111}
child{node[block_center] {A}}
child{node[block_center] {B}}}
child{node[block_center] {222}
child{node[block_center] {A}}
child{node[block_center] (test2) {B}}}
};
\draw[red] (test1) to [bend left = 30](test2);
\end{tikzpicture}
\begin{tikzpicture}[
block_center/.style ={rectangle, draw=black, thick, fill=white,
text width=5em, text centered,
%minimum height=4em,
},
block_left/.style ={rectangle, draw=black, thick, fill=white,
text width=16em, text ragged, minimum height=4em, inner sep=6pt},
block_noborder/.style ={rectangle, draw=none, thick, fill=none,
text width=18em, text centered, minimum height=1em},
block_assign/.style ={rectangle, draw=black, thick, fill=white,
text width=18em, text ragged, minimum height=3em, inner sep=6pt},
block_lost/.style ={rectangle, draw=black, thick, fill=white,
text width=16em, text ragged, minimum height=3em, inner sep=6pt},
line/.style ={draw, thick, -latex', shorten >=0pt}]
% outlining the flowchart using the PGF/TikZ matrix funtion
% [edge from parent/.style= {thick, draw= cyan, edge from parent fork right},
% sibling distance=10em,level distance=6em,
% every node/.style={shape=rectangle,draw,align=center}, grow=right]
\tikzstyle{level 1}=[sibling distance=25mm]
\tikzstyle{level 2}=[sibling distance=12mm]
\tikzstyle{level 3}=[sibling distance=6mm]
\node[block_center]{V2} [grow' =right, right]
child{node[block_center] {R}
child{node[block_center] {111}
child{node[block_center] (test1) {A}}
child{node[block_center] {B}}}
child{node[block_center] {222}
child{node[block_center] {A}}
child{node[block_center] {B}}}
% child{node[block_center] {ut - White 2 (n=xx)}}
}
child{node[block_center] {G}
child{node[block_center] (test2) {111}
child{node[block_center] {A}}
child{node[block_center] {B}}}
child{node[block_center] {222}
child{node[block_center] {A}}
child{node[block_center] (test2) {B}}}
};
\draw[red] (test1) to [bend left = 30](test2);
\end{tikzpicture}
\end{center}
\end{document}
后续问题: 森林功能看起来很棒!我遇到一个问题,当我在框中输入较长的文本时,框的长度不一致,这会打乱树木的排列。
我如何指定矩形的大小,以便它们在不同的“兄弟级别”中保持一致?
\documentclass{article}
\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary {decorations.pathreplacing, calligraphy}
\tikzset{mybrace/.style={decorate, decoration={calligraphic brace, amplitude=2mm}, ultra thick, transform canvas={xshift=1mm}}}
\begin{document}
\begin{figure}
\centering
\caption{flowchart}
\medskip
\begin{forest}
for tree={grow'=east, minimum width=15mm}
[
[Versions, for tree={no edge, draw}[R1[sequence number[R2]]]
]
[V1, no edge, for tree={forked edge, draw}
[R[111[A, name=A1][B]][222[A][B]]]
[G[111[A][B]][222222222222[A][B, name=B1]]]
]
[V2, no edge, for tree={forked edge, draw}
[R[111[A, name=A2][B]][222[A][B]]]
[G[111[A][B]][222222222222[A][B, name=B2]]]
]
]
\draw[mybrace] (A1.north east)--node[right=2mm]{V1}(B1.south east);
\draw[mybrace] (A2.north east)--node[right=2mm]{V2}(B2.south east);
\end{forest}
\end{figure}
\end{document}
答案1
我认为使用 会更容易forest
。括号是最棘手的部分,需要decorations.pathreplacing
和 库。我为此calligraphy
制作了一个样式。然后可以使用它们以及节点的 s 来绘制它们。mybrace
\draw[mybrace]
name
\documentclass{article}
\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary {decorations.pathreplacing, calligraphy}
\tikzset{mybrace/.style={decorate, decoration={calligraphic brace, amplitude=2mm}, ultra thick, transform canvas={xshift=1mm}}}
\begin{document}
\begin{forest}
for tree={grow'=east, minimum width=15mm}
[
[V, for tree={no edge}[X[Y[Z]]]
]
[V1, no edge, for tree={forked edge, draw}
[R[111[A, name=A1][B]][222[A][B]]]
[G[111[A][B]][222[A][B, name=B1]]]
]
[V2, no edge, for tree={forked edge, draw}
[R[111[A, name=A2][B]][222[A][B]]]
[G[111[A][B]][222[A][B, name=B2]]]
]
]
\draw[mybrace] (A1.north east)--node[right=2mm]{V1}(B1.south east);
\draw[mybrace] (A2.north east)--node[right=2mm]{V2}(B2.south east);
\end{forest}
\end{document}