\documentclass[11pt]{book}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{trees,graphs,calc,arrows.meta,positioning,decorations.pathreplacing,bending,decorations.markings,matrix,fit,patterns}
\usepackage{pgfplots}
\usepackage{xepersian}
\settextfont[Scale=1]{Tahoma}
\setlatintextfont[Scale=1]{Times New Roman}
\setdigitfont[Scale=1]{Tahoma}
\begin{document}
\begin{figure}
\centering
\tikzset{
solid node/.style={circle,draw,inner sep=1.2,fill=black},}
\begin{tikzpicture}
\tikzset{
level 1/.style={level distance=12mm,sibling distance=20mm},
level 2/.style={level distance=12mm,sibling distance=12mm},
level 3/.style={level distance=12mm,sibling distance=6mm},
}
\node (r) [solid node, label = above: {$r\,$\rl{(ریشه)}}]{}
child{node[solid node, label= left: {$a_{1}$}]{}
child[edge from parent/.style={draw, line width=0.7mm}]{node[solid node, label = left: {$b_{1}$}]{}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
}}
child{node[solid node, label = left:{$a_{2}$}]{}
child[edge from parent/.style={draw, line width=0.7mm}]{node[solid node, label = left:{$b_{2}$}]{}
child[missing]
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
}
}
child{node (a3) [solid node, label = left:{$a_{3}$}]{}
child[edge from parent/.style={draw, line width=0.7mm}]{node (b3)[solid node, label = left:{$b_{3}$}]{}
child[missing]}
}
child{node (aq)[solid node, label = right:{$a_{q}$}]{}
child[edge from parent/.style={draw, line width=0.7mm}]{node (bq) [solid node, label = right:{$b_{q}$}]{}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
}
}
;
\path (a3.east) -- (aq.west) node [midway] {$\cdots$};
\path (b3.east) -- (bq.west) node [midway] {$\cdots$};
\tikzset{
solid node/.style={circle,draw,inner sep=1.2,fill=black},
no edge from this parent/.style={
every child/.append style={
edge from parent/.style={draw=none}}},
level 3/.style={yshift=5cm},
level 4/.style={level distance=10mm} }
\node[right = 5 of r,align=right] {\rl{سطح $0$ (بیرونی)}} [no edge from this parent]
child{node {\rl{سطح $1$ (درونی)}}[no edge from this parent]
child{node {\rl{سطح $2$ (بیرونی)}} [no edge from this parent]
child{node {\rl{سطح $3$ (درونی)}}}
}};
\end{tikzpicture}
\caption{درخت تناوبی.}
\label{fig:3-33}
\end{figure}
\end{document}
答案1
从节点样式的定义中删除draw
或包含标准line width
。由于您solid node
在具有不同线宽的路径上使用该样式,因此这些节点的绘制边框具有不同的线宽,其中一些看起来比其他的更大。
line width=0.4pt
以下是最小化您的示例并添加定义的结果。
使用诸如tikz-qtree
或 之类的包是明智之举forest
,但加载而不使用则毫无用处。同样,问题并不依赖于非拉丁文字的使用,并且代码不需要在序言中加载的大多数库。
\documentclass[11pt]{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\tikzset{
solid node/.style={circle,draw,line width=0.4pt,inner sep=1.2,fill=black},}
\begin{tikzpicture}
\tikzset{
level 1/.style={level distance=12mm,sibling distance=20mm},
level 2/.style={level distance=12mm,sibling distance=12mm},
level 3/.style={level distance=12mm,sibling distance=6mm},
}
\node (r) [solid node, label = above: {$r\,$xxx}]{}
child{node[solid node, label= left: {$a_{1}$}]{}
child[edge from parent/.style={draw, line width=0.7mm}]{node[solid node, label = left: {$b_{1}$}]{}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
}}
child{node[solid node, label = left:{$a_{2}$}]{}
child[edge from parent/.style={draw, line width=0.7mm}]{node[solid node, label = left:{$b_{2}$}]{}
child[missing]
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
}
}
child{node (a3) [solid node, label = left:{$a_{3}$}]{}
child[edge from parent/.style={draw, line width=0.7mm}]{node (b3)[solid node, label = left:{$b_{3}$}]{}
child[missing]}
}
child{node (aq)[solid node, label = right:{$a_{q}$}]{}
child[edge from parent/.style={draw, line width=0.7mm}]{node (bq) [solid node, label = right:{$b_{q}$}]{}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
child[edge from parent/.style={draw, thin}]{node[solid node]{}}
}
}
;
\path (a3.east) -- (aq.west) node [midway] {$\cdots$};
\path (b3.east) -- (bq.west) node [midway] {$\cdots$};
\tikzset{
solid node/.style={circle,draw,inner sep=1.2,fill=black},
no edge from this parent/.style={
every child/.append style={
edge from parent/.style={draw=none}}},
level 3/.style={yshift=5cm},
level 4/.style={level distance=10mm} }
\node[right = 5 of r,align=right] {xxx} [no edge from this parent]
child{node {xxx}[no edge from this parent]
child{node {xxx} [no edge from this parent]
child{node {xxx}}
}};
\end{tikzpicture}
\end{document}
forest
(甚至tikz-qtree
)将使您能够使用更简洁的语法和更强大的自定义功能,包括更高的自动化程度。即使只是styles
使用普通的 Ti进行定义和应用钾Z 会让你的代码更清晰、更灵活。
例如,
\documentclass[11pt]{book}
\usepackage{forest}
\usetikzlibrary{positioning}
% ateb: https://tex.stackexchange.com/a/705271/ addaswyd o gwestiwn Arian: https://tex.stackexchange.com/q/705249/
\newcounter{forlevel}
\renewcommand* \theforlevel{\alph{forlevel}}
\forestset{%
declare toks={level label}{},
last level label/.style={label={right:{${#1}_{q}$}}},
other level label/.style 2 args={label={left:{${#1}_{#2}$}}},
fancy tree/.style={%
for tree={
solid node,
tier/.option=level,
fit=band,
},
before typesetting nodes={
for nodewalk={%
fake=root,
last leaf,
branch'={%
while={%
>On>{level}{1}%
}{%
parent,
TeX={\setcounter{forlevel}{\foresteoption{level}}},
level label/.expanded=\theforlevel,
last level label/.option=level label,
tikz+={\path () -- (!previous on tier) node [midway] {$\cdots$};}%
},
while nodewalk valid={previous on tier}{%
previous on tier,
TeX={\setcounter{forlevel}{\foresteoption{level}}},
level label/.expanded=\theforlevel,
other level label/.process={OO{level label}{n}}
}%
}%
}{},
},
before packing={%
tempdima/.max={> OO OO w4+d {s}{!u1.s} {s sep}{!u.n children} {(##1-##2)+##3*(##4-1)} }{leaves},
for children={minimum width=\foresteregister{tempdima},typeset node},
},
before drawing tree={%
for children={minimum width=0pt,typeset node},
},
},
}
\tikzset{
solid node/.style={circle,draw,line width=0.4pt,inner sep=1.2,fill=black},}
\begin{document}
\begin{forest}
fancy tree,
[,label={above:{${r}$ xxx}}
[[[][][][]]]
[[[,phantom][][]]]
[[]]
[[[][][]]]
]
\coordinate (e) at (current bounding box.east);
\foreach \i/\j in {!r/xxx,!rl/xxx,!rll/xxx,!rlll/xxx}
\node [anchor=west,xshift=10pt] at (\i -| e) {\j};
\end{forest}
\end{document}