这是我正在处理的图表的 LaTeX:
\documentclass[sigplan,10pt,anonymous,review]{acmart}\settopmatter{printfolios=true,printccs=false,printacmref=false}
\usepackage{subcaption}
\usepackage{tikz}
\begin{document}
\tikzset{
breakarrow/.style={->, dashed},
varnode/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=red!20, bottom color=white}
}
\begin{figure*}
\centering
\begin{subfigure}[b]{0.45\textwidth}
\begin{tikzpicture}[sibling distance=6em,
every node/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=violet!20}]
\node {/}
child { node {tmp/}}
child { node {initrd.img}}
child { node {usr/}
child { node {local/}}
child { node {lib/}}
child { node [varnode] {$\alpha_{/usr}$} edge from parent [breakarrow]}};
\end{tikzpicture}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.35\textwidth}
\begin{tikzpicture}[sibling distance=6em,
every node/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=violet!20}]
\node [varnode] {$\alpha_{/usr}$}
child { node {share/} edge from parent [breakarrow]}
child { node {bin/}
child { node {cat}}
child { node [varnode] {$\beta_{/usr/bin}$} edge from parent [breakarrow]}
child { node {tac}}};
\end{tikzpicture}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.1\textwidth}
%% \caption{A directory tree with a deleted file}
%% \label{directory-tree-1}
\begin{tikzpicture}[sibling distance=6em,
every node/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=violet!20}]
\node [varnode] {$\beta_{/usr/bin}$}
child { node {col} edge from parent [breakarrow]};
\end{tikzpicture}
\end{subfigure}
\caption{A filesystem instrumented with body addresses.}
\label{fig:body-addresses-col}
\end{figure*}
\end{document}
它的渲染方式如下:
我想将我的样式应用于我的节点标记与其父节点breakarrow
之间的边缘。但是,如果我在之后写入,我就会得到不想要的行为 - 相同的样式开始应用于节点和的父边缘以及节点边界。bin/
edge from parent [breakarrow]
node {bin/}
cat
tac
有人可以帮我找到一种方法,将我的风格仅应用于bin/
其父级之间的箭头吗?
答案1
有更简单的方法来绘制树木,但如果您希望坚持 TikZ 的详细程度,您可以用另一种样式覆盖该样式。
\documentclass[border=9pt]{standalone}
\usepackage[]{tikz}
\begin{document}
\tikzset{
breakarrow/.style={->, dashed},
myarrow/.style={solid, -},
varnode/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=red!20, bottom color=white}
}
\begin{tikzpicture}[sibling distance=6em, every node/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=violet!20}]
\node {/}
child { node {tmp/}}
child { node {initrd.img}}
child { node {usr/}
child { node {local/}}
child { node {lib/}}
child { node [varnode] {$\alpha_{/usr}$} edge from parent [breakarrow]}};
\end{tikzpicture}
\begin{tikzpicture}[sibling distance=6em, every node/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=violet!20}]
\node [varnode] {$\alpha_{/usr}$}
child { node {share/} edge from parent [breakarrow]}
child { node {bin/} edge from parent [breakarrow]
child { node {cat} edge from parent [myarrow]}
child { node [varnode] {$\beta_{/usr/bin}$} edge from parent [breakarrow]}
child { node {tac} edge from parent [myarrow]}};
\end{tikzpicture}
\begin{tikzpicture}[sibling distance=6em, every node/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=violet!20}]
\node [varnode] {$\beta_{/usr/bin}$}
child { node {col} edge from parent [breakarrow]};
\end{tikzpicture}
\end{document}
我会做以下事情:
\documentclass[border=9pt]{standalone}
\usepackage[]{forest}
\begin{document}
\forestset{
break arrow/.style={edge+={->, dashed}},
my base node/.style={rounded corners, draw, align=center,},
var node/.style = {my base node, top color=red!20, bottom color=white},
my node/.style={my base node, top color=white, bottom color=violet!20,},
}
\begin{forest}
for tree={my node, s sep'=3em, l sep'+=1em, }
[$\alpha_{/usr}$, var node
[share/]
[bin/, break arrow
[cat]
[$\beta_{/usr/bin}$, var node, break arrow]
[tac]
]
]
\end{forest}
\end{document}
然后,您不需要覆盖任何内容,就可以将样式精确地应用到您想要的边和节点。
答案2
cfr 的答案有一个方便的森林指针,并很好地提出了比 TikZ 更简单的替代方案,但我注意到他基于 TikZ 的答案导致某些单元格边框变成虚线。最终我终于弄清楚了如何让节点和边缘在 TikZ 中正确显示。
\documentclass[sigplan,10pt,anonymous,review]{acmart}\settopmatter{printfolios=true,printccs=false,printacmref=false}
\usepackage{subcaption}
\usepackage{tikz}
\begin{document}
\tikzset{
breakarrow/.style={->, dashed},
varnode/.style = {solid, shape=rectangle, rounded corners,
draw, align=center,
top color=red!20, bottom color=white}
}
\begin{figure*}
\centering
\begin{subfigure}[b]{0.45\textwidth}
\begin{tikzpicture}[sibling distance=6em,
every node/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=violet!20}]
\node {/}
child { node {tmp/}}
child { node {initrd.img}}
child { node {usr/}
child { node {local/}}
child { node {lib/}}
child { node [varnode] {$\alpha_{/usr}$} edge from parent [breakarrow]}};
\end{tikzpicture}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.35\textwidth}
%% \caption{A directory tree with a deleted file}
%% \label{directory-tree-1}
\begin{tikzpicture}[sibling distance=6em,
every node/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=violet!20}]
\node [varnode] {$\alpha_{/usr}$}
child { node {share/} edge from parent [breakarrow]}
child { node {bin/} edge from parent [breakarrow]
child { node [solid] {cat} edge from parent [solid,-]}
child { node [varnode] {$\beta_{/usr/bin}$} edge from parent [breakarrow]}
child { node [solid] {tac} edge from parent [solid,-]}};
\end{tikzpicture}
\end{subfigure}
\quad
\begin{subfigure}[b]{0.1\textwidth}
%% \caption{A directory tree with a deleted file}
%% \label{directory-tree-1}
\begin{tikzpicture}[sibling distance=6em,
every node/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=violet!20}]
\node [varnode] {$\beta_{/usr/bin}$}
child { node {col} edge from parent [breakarrow]};
\end{tikzpicture}
\end{subfigure}
\caption{A filesystem instrumented with body addresses.}
\label{fig:body-addresses-col}
\end{figure*}
\end{document}