I'm searching for a way to make a TeX diagram with the forest package that looks like this Hierarchy provided by Thomas L. Saaty in his Analytic Hierarchy Process:
Asked
Active
Viewed 418 times
-1
-
1Hi mogelschrift, could you provide a MWE and/or explaing where you are struggeling? – user1729210 May 06 '20 at 08:46
-
I cannot connect "House A" to all the nodes in the second level of the hiearchy, how does this work? – mogelschrift May 06 '20 at 08:54
-
1This should help you to get started – Jojo May 06 '20 at 09:25
1 Answers
4
I think that you don't actually need the forest package.
A simple graph/diagram in TiKz would do.
See the comments in the following MWE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,backgrounds}
\usepackage{adjustbox}
\begin{document}
\begin{figure}[tb]
\centering
\begin{adjustbox}{width=\textwidth}
\begin{tikzpicture}[%
thick,
node distance = .9cm,
parameter/.style = {%
fill = white,
minimum size = 1.5cm,
text width = 1.8cm,
align = center,
draw,
},
house/.style = {%
fill = white,
minimum size = 1.5cm,
text width = 1.5cm,
align = center,
draw,
},
font=\scshape
]
% let's draw the nodes by placing them with the tools offered by 'positioning'
\node [parameter] (soh) {size of house};
\node [parameter] (tra) [right=of soh] {trans\-portation};
\node [parameter] (nei) [right=of tra] {neighbor\-hood};
\node [parameter] (aoh) [right=of nei] {age of house};
\node [parameter] (ys) [right=of aoh] {yard space};
\node [parameter] (mf) [right=of ys] {modern facilities};
\node [parameter] (gc) [right=of mf] {general condition};
\node [parameter] (fin) [right=of gc] {financing};
% let's now place the upper node using the features of 'calc'
\coordinate (CENTER) at ($(soh)!0.5!(fin)$); % this places a node exactly in the center, to provide a reference point for the remaining nodes -- https://tex.stackexchange.com/a/117085/177
\node [parameter,text width=2.2cm] (swh) [above=3cm of CENTER] {satisfaction with house};
% let's now place the lower nodes
\node [house] (hob) [below=3cm of CENTER] {house b};
\node [house] (hoa) [left=2cm of hob] {house a};
\node [house] (hoc) [right=2cm of hob] {house c};
% now the fun part using nested loops to draw the edges
\foreach \house in {hoa,hob,hoc}
\foreach \param in {soh,tra,nei,aoh,ys,mf,gc,fin}
\scoped[on background layer] % this is used to draw the connecting edges below the nodes - 'backgrounds' library
\draw (\house) -- (\param);
\foreach \param in {soh,tra,nei,aoh,ys,mf,gc,fin}
\scoped[on background layer]
\draw (\param) -- (swh);
\end{tikzpicture}
\end{adjustbox}
\caption{Decomposition of the problem into hierarchy}
\label{fig:dec-pro-hie}
\end{figure}
\end{document}
If you want to have the edges starting only at the top/bottom side of the nodes, get rid of \scoped[on background layer] and the backgrounds library, and use instead
\foreach \house in {hoa,hob,hoc}
\foreach \param in {soh,tra,nei,aoh,ys,mf,gc,fin}
\draw (\house.north) -- (\param.south);
\foreach \param in {soh,tra,nei,aoh,ys,mf,gc,fin}
\draw (\param.north) -- (swh.south);
Which gives the following result:
Alessandro Cuttin
- 6,963
-
-
You're welcome! There's no need to comment to say thanks you, btw: accepting and upvoting the answer is enoug ;) – Alessandro Cuttin May 11 '20 at 12:04


