我正在尝试构建某种树,但我想在其节点中放置一个框架框而不是符号。此外,在那个框架框中的特定位置,我想要另一个框架框。虽然我找不到使用 latex 中现有的树结构来做到这一点的方法,但我开始将框架框放在我想要的位置。因此,我构建了以下内容,但现在我不知道如何绘制一条将每个 bi 连接到 s 的线。
\begin{figure}
\setlength{\unitlength}{0.06in}
\centering
\begin{picture}(70,50)
\put(25,35){\framebox(14,10){\Large server} }
\put(0,5){\framebox(14,10){\Large browser 1}}
\put(25,5){\framebox(14,10){\Large browser 2}}
\put(50,5){\framebox(14,10){\Large browser 3}}
\put(30.5,35){\framebox(3,3){s}}
\put(5.5,12){\framebox(3,3){$b_1$}}
\put(30.5,12){\framebox(3,3){$b_2$}}
\put(55.5,12) {\framebox(3,3){$b_3$}}
\end{picture}
\end{figure}
答案1
像这样?
使用forest
节点的标签很简单:
\documentclass[border=1cm]{standalone}
\usepackage[edges]{forest}
\tikzset{every label/.append style = {draw, inner sep=2pt}}
\begin{document}
\begin{forest}
for tree = {
draw,
text width=22mm, minimum height=16mm,
font=\Large,
text centered,
parent anchor=south,
child anchor=north,
%
l sep=8mm,
s sep=6mm,
}
[server, label={[anchor=south]below:s}
[browser 1, label={[anchor=north]:$b_1$}]
[browser 2, label={[anchor=north]:$b_2$}]
[browser 3, label={[anchor=north]:$b_3$}]
]
\end{forest}
\end{document}
答案2
您pict2e
可以轻松绘制指定其端点的线段。
\documentclass{article}
\usepackage{pict2e}
\begin{document}
\begin{figure}
\setlength{\unitlength}{0.06in}
\centering
\begin{picture}(70,50)
\put(25,35){\framebox(14,10){\Large server} }
\put(0,5){\framebox(14,10){\Large browser 1}}
\put(25,5){\framebox(14,10){\Large browser 2}}
\put(50,5){\framebox(14,10){\Large browser 3}}
\put(30.5,35){\framebox(3,3){s}}
\put(5.5,12){\framebox(3,3){$b_1$}}
\put(30.5,12){\framebox(3,3){$b_2$}}
\put(55.5,12) {\framebox(3,3){$b_3$}}
\Line(7,15)(32,35)
\Line(32,15)(32,35)
\Line(57,15)(32,35)
\end{picture}
\end{figure}
\end{document}