我想绘制下图,但我无法以树状格式绘制它的箭头格式:
我的初学者方法:
\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
[ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
arrow/.style={->, >=stealth, semithick},
] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\draw[help lines] (0,0) grid (8,4);
[
>=latex,shorten >=2pt,shorten <=2pt,shape aspect=1,
% arrow/.style={->, >=stealth, very thick},
% arrow/.style={<->, >=stealth, semithick},
block/.style={}
every node/.style = {font=\footnotesize}
]
\node[
rectangle,
double=black,
double distance =0.5pt,
shape border rotate=90,
draw,
fill=white,
shape aspect=0.2,
font={\scriptsize\baselineskip=8pt},
inner xsep=3pt,
align=left,
] (A) at (1,4) {\scriptsize \$ gcc -g -c \\ \,\, -fPIC - Wall \\ \,\, mod1.c mod2.c mod3.c};
\node[circle,
shape border rotate=90,
inner xsep=0pt,
draw] (B) at (-0.9,4.3) {\tiny 1};
\node[
rectangle,
double=black,
double distance =0.5pt,
shape border rotate=90,
draw,
fill=white,
font={\scriptsize\baselineskip=8pt},
inner xsep=3pt,
align=left,
] (B) at (2,2) {mod1.o code};
\node[
rectangle,
double=black,
double distance =0.5pt,
shape border rotate=90,
draw,
fill=white,
font={\scriptsize\baselineskip=8pt},
inner xsep=3pt,
align=left,
] (C) at (2,1) {mod2.o code};
\node[
rectangle,
double=black,
double distance =0.5pt,
shape border rotate=90,
draw,
fill=white,
font={\scriptsize\baselineskip=8pt},
inner xsep=3pt,
align=left,
] (D) at (2,0) {mod3.o code};
\draw [arrow] (A.south) -- (B.west);
\draw [arrow] (A.south) -- (C.west);
\draw [arrow] (A.south) -- (D.west);
\end{tikzpicture}
\end{document}
这里我无法绘制如下树格式的箭头:
[*]
│
├──> [...]
├──> [...]
└──> [...]
答案1
像这样:
在下面的 MWE 中,节点彼此相对定位。还定义了节点的样式,从而使图片代码明显更短。对于箭头,使用正交坐标|-
(有关其使用的详细信息,请参阅 TikZ 和 PGF 手册,第 13.3.1 节垂直线的交点),如 @MS-SPO 评论中所建议:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 4mm and 8mm,
arr/.style = {-Stealth, semithick},
C/.style = {circle, draw, font=\footnotesize},
N/.style = {draw, very thick,
font=\small, align=left,
inner sep=5pt}
]
\draw[help lines] (0,0) grid (8,5);
%
\node (n1) [N] at (3,4) {\$ gcc -g -c \\
\hphantom{\$ } -fPIC - Wall \\
\hphantom{\$ } mod1.c mod2.c mod3.c};
\node[C, below left = 0 and 2mm of n1.north west] {1};
\node (n2) [N, below right=of n1.south] {mod1.o code};
\node (n3) [N, below=of n2] {mod2.o code};
\node (n4) [N, below=of n3] {mod3.o code};
%
\draw[arr] (n1) |- (n2);
\draw[arr] (n1 |- n2) |- (n3);
\draw[arr] (n1 |- n3) |- (n4);
\end{tikzpicture}
\end{document}
附录:
关于您的评论,您只需要更改C
节点的样式(仅在一定程度上)。例如:
...
\begin{tikzpicture}[
node distance = 4mm and 8mm,
arr/.style = {-Stealth, semithick},
C/.style = {circle, draw, inner sep=1pt}, % <--- text in node will be \normalsize
N/.style = {draw, very thick,
font=\small, align=left,
inner sep=5pt}
]
...
给出
圆圈内的字体越大,圆圈也会越大。