# Easiest way to design Attack Trees in LaTeX (with 'and' nodes/arcs)?

I'm trying to make something akin to the below image in LaTeX. The closest I've come has been with the forest package, but it does not seem to certain desired capabilities — in particular, the arc around the three edges from the central node. Additionally, I cannot see how one would add the smaller edges below easily, however this is far less of a concern.

Are there any packages or tools available in LaTeX to help me design something similar? Or a way to do this with the forest package?

The below is the closest I have gotten it. The lack of arrows is fine, it is fundamentally the arc which I'd like.

\documentclass[11pt,a4paper]{article}

\usepackage{forest}

\begin{document}

\tiny
\begin{forest}
for tree={
draw,
minimum height=1cm,
anchor=north,
align=center,
child anchor=north
},
[{Get malicious code\\on the user device}, align=center, name=AD
[{Bypass the appstore}]
[{Exploit vulnerability in installed app}]
[{Sell/distribute\\malicious app in\\appstore}
[{Create malicious\\app}]
[{Cicumvent app\\review}]
[{Troll/falsify app\\reputation}]
]
]
\end{forest}
\end{document}


• Welcome to TeX.se. Instead of just posting an image of what you want, could you add a minimal compilable document that shows what you're tried with forest? (Although be aware that this isn't a tree, since some nodes have multiple parents.) – Alan Munn Apr 8 '18 at 18:30
• welcome to tex.se! what you try so far? locus you can draw with help of tikz library angles. – Zarko Apr 8 '18 at 18:31
• Thanks for adding some code. Can you wrap it in a complete compilable document, though. – Alan Munn Apr 8 '18 at 21:50
• I've added the closest I've managed, using forest. – Alex W Apr 8 '18 at 21:50
• Yep, sure thing. (sorry!) – Alex W Apr 8 '18 at 21:50

Here I have a code that works using brute force, but it does not evade suffering, but it was only to be able to declare texts in circles in a simple way; whatever the package you are using I did not find it appropriate since it is oriented for other things, I think ... but as you know the path of tikz requires a lot of pain and suffering, but when you master it with the basics you can achieve everything ... Analyze the code is partially explained under the MIT licensing parameters, trying to make it as simple and structured so that it is understood without saving anything for oneself ...

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% By J. Leon
%Use MIT licence BSO, BeerWare, whatever but free
\documentclass{article}

\usepackage[utf8]{inputenc} % Codificacion de entrada %,
\usepackage[active,tightpage,floats]{preview}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[scaled]{uarial} % font arial like...
\usepackage[T1]{fontenc} % Gliphs codificatio
\usepackage{tikz}
\usetikzlibrary{babel}
\PreviewEnvironment{tikzpicture}  %Used to conpile in TikzEdit (Semi WYSWYG IDE}
\setlength\PreviewBorder{1pt}%
\usetikzlibrary{calc} % Needed to calculate the points for arcs.
\renewcommand{\baselinestretch}{1} % Espaciado de lineas = 1
\renewcommand*\familydefault{\sfdefault} % Set font to serif family

\usetikzlibrary{arrows, decorations.markings,positioning,backgrounds,shapes}
\definecolor{WIRE}{HTML}{002FA7} % Klein Blue

\newcounter{col}

\newcommand\setrow[3]{
\setcounter{col}{0}
\foreach \n in {#1} {
\edef\x{#3-\value{col}*.7}
\node[CR node] (HR) at (#2,\x) {\n};
\stepcounter{col}
}
}

\begin{document}
\begin{tikzpicture}[
background rectangle/.style={%Seting the background styles
rectangle,
rounded corners,
top color=black!3,
bottom color=black!3!black!3,
draw=black!40!black!60,dashed,
},
show background rectangle, % Indicates to activate the background.
Arrow node/.style={% Style for arrows
thin,
->,
>= triangle 60,
%   WIRE,
black,
line width=1pt,
},
AO node/.style={% Style for boxes.
rectangle,
anchor=center,
align=center,
minimum width=2cm,
font=\scriptsize,
text width=2.2cm,
minimum height=1.3cm,
%   rounded corners,
top color= white,
bottom color=black!15,
thin,
%   fill=orange!10!yellow!50,
draw=black,
},
CR node/.style={
circle,
fill=black!10,
draw,
font=\small\bfseries,
inner sep = 1.5pt
},
] % yeah that is all the configuration for tickzpicture xD

% This is an objet with 6 coordinates
% CT: Center Top,  LT: Left Top, RT: Right Top
% CB: Center Bottom, LB: Left Bottom, RB: Right Bottom.
% Variables 1:Position, 2: Identifier, 3: Text content.
\def\TextBoxTree(#1)#2#3{%
\begin{scope}[shift={(#1)}]
\draw (0,0.65) coordinate (#2 CT);
\draw (-0.8,0.65) coordinate (#2 LT);
\draw (0.8,0.65) coordinate (#2 RT);
\node[AO node] (dm) at (0,0) {#3}; % Node predefined
\draw (0,-0.65) coordinate (#2 CB);
\draw (-0.8,-0.65) coordinate (#2 LB);
\draw (0.8,-0.65) coordinate (#2 RB);
\end{scope}
}

% This objet is used to draw the angle like symbol.
% Variables:  1: distance from the "axis" could be a dimmension in cm or a factor from 0 to 1.
%2:coordinate left arrow initial 3:coordinate left arrow end
%4:coordinate right arrow initial 5:coordinate right arrow end
\def\ArrowArc(#1)#2#3#4#5{%
\coordinate (a) at (#2);
\coordinate (b) at (#3);
\coordinate (c) at (#4);
\coordinate (d) at (#5);
\coordinate (e) at ($(a)!{#1}!(b)$); %e is a point separated #1 in the line a-b
\coordinate (f) at ($(c)!{#1}!(d)$); %f is a point separated #1 in the line c-d
\coordinate (g) at ($(e)!.5!(f)$); % g is the middle distante between e and f.
\coordinate (h) at ($(g)!-.5cm!90:(f)$); % g is 5cm separated orthogonal from midpoint line e-f
\draw[Arrow node, -] plot [smooth, tension=1] coordinates { (e) (h) (f)} ; %draw the arc.
}

% Start drawing

\TextBoxTree(0,0.5){1}{Get malicious code on the user device }; %identifier 1
\TextBoxTree(-6,-5.5){2}{Bypass the appstore}; %identifier 2
\TextBoxTree(-3,-5.5){3}{Exploit vulnerability in installed app}; %...

\TextBoxTree(3,-2.5){4}{Self/distribute malicuous app in appstore};
\TextBoxTree(0,-5.5){5}{Create malicious app};
\TextBoxTree(3,-5.5){6}{Circumvent app review};
\TextBoxTree(6,-5.5){7}{Troll/falsify app reputation};

\TextBoxTree(8.5,1.5){8}{Keep malicious code on the user device};
\TextBoxTree(9,-2.5){9}{Prevent detection by device user};

% Drwawing the conectións using the coordinate labels (identifier coordinate)
\draw[Arrow node] (1 LB) -- (2 CT);
\draw[Arrow node] (1 CB) -- (3 CT);
\draw[Arrow node] (1 RB) -- (4 LT);

\draw[Arrow node] (4 LB) -- (5 RT);
\draw[Arrow node] (4 CB) -- (6 CT);
\draw[Arrow node, color=blue] (4 RB) -- (7 LT); % you can change the color.

\draw[Arrow node] (8 LB) -- (7 RT);
\draw[Arrow node] (8 CB) -- (9 CT);
\draw[Arrow node] (8 RB) -- (10 LT);

% Drawing the arcs
%\ArrowArc(0.25){1 LB}{2 CT}{1 RB}{4 LT}
\ArrowArc(1cm){8 LB}{7 RT}{8 RB}{10 LT} %for test
\ArrowArc(.5cm){4 LB}{5 RT}{4 RB}{7 LT}

%To avoid to white lot of code, its incomplete function...
%need to be improved, you must declare all the coordinates in x manually.
\setrow{T28,T29}{-6.5}{-6.5};
\setrow{T51,T55}{-5.5}{-6.5};

\setrow{T51,T55, T51}{-3.7}{-6.5};
\setrow{T51,T55, T51}{-3}{-6.5};
\setrow{T51,T55, T51, T22}{-2.3}{-6.5};

\setrow{T51,T55, T51,T55,T51}{11.4}{-3.5};
\setrow{T51,T55, T51,T55,T51,T55}{12.1}{-3.5};
\setrow{T51,T55, T51,T55,T51}{12.8}{-3.5};

%\node[CR node] (HR) at (8.5,-3.5) {T28}; %used to get the cordinates in TikzEdt
\end{tikzpicture}
\end{document}


All that paraphernalia to generate this ..., if someone can improve it, I will also be grateful.

Here's one way to add arcs to a Forest tree. If you want to do this without adjusting things for different cases, consider setting a common parent anchor for all children (e.g. parent anchor=children). Otherwise, the size of the nodes will require adjusting the arcs' radii and angles.

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\forestset{%
angle below/.style={
tikz+={%
\draw ($(!1.child anchor)!.35!(.parent anchor)$) [bend right=15] to ($(.parent anchor)!.65!(!l.child anchor)$);
},
},
}
\begin{document}

\begin{forest}
for tree={
draw,
minimum height=1cm,
anchor=parent,
align=center,
child anchor=parent
},
[{Get malicious code\\on the user device}, name=AD
[{Bypass the appstore}]
[{Exploit vulnerability in installed app}]
[{Sell/distribute\\malicious app in\\appstore}, angle below
[{Create malicious\\app}]
[{Cicumvent app\\review}]
[{Troll/falsify app\\reputation}]
]
]
\end{forest}
\end{document}