4

Here's the LaTeX for a figure I'm working on:

\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}

This is how it renders:

example

I would like to apply my breakarrow style to the edge between my node labelled bin/ and its parent. However, if I just write edge from parent [breakarrow] after node {bin/}, I get unwanted behaviour - the same style starts applying to the parent edges for nodes cat and tac as well as node borders.

Could someone please help me find a way to apply my style to only the arrow between bin/ and its parent?

  • Thanks for the edit, @epR8GaYuh. – airbornemihir Oct 9 '19 at 7:55
5

There are easier ways to draw trees, but if you wish to stick to TikZ's verbosity, you can override the style with another.

\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}

override one style with another

I would instead do the following:

\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}

Forest solution

Then you don't have to override anything and can apply styles precisely to the edges and nodes you want.

0

cfr's answer has a handy pointer to forest and does a good job bringing up simpler alternatives to TikZ, but I noticed that his TikZ-based answer caused certain cell borders to become dashed lines. Eventually I ended up figuring out how to get the nodes and edges to display correctly in 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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.