绘制层次结构图/图形

绘制层次结构图/图形

我正在寻找一种方法来使用森林包制作 TeX 图表,该图表看起来像 Thomas L. Saaty 在他的层次分析法

在此处输入图片描述

答案1

我认为您实际上并不需要该forest包。 TiKz 中的简单图形/图表即可。请参阅以下 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}

在此处输入图片描述

如果您希望边缘仅从节点的顶部/底部开始,请摆脱\scoped[on background layer]backgrounds,而改用

\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);

结果如下:

在此处输入图片描述

相关内容