1

Please help me to set a straight line (horizontal) connector. Thank you in advance. enter image description here

\documentclass[a4paper,11pt]{article}
\usepackage[edges]{forest}
\usepackage{caption}

    % Source <------------- https://tex.stackexchange.com/questions/300373/saving-horizontal-space-in-tree-diagram

%Defining tikz classes for tree diagrams
\tikzset{parent/.style={align=center,text width=3cm,rounded corners=3pt},
    child/.style={align=center,text width=3cm,rounded corners=3pt}
}

\colorlet{col1}{white}
\colorlet{col2}{gray!20}
\colorlet{col3}{gray!40}
\colorlet{col4}{gray!60}

\begin{document}
    \begin{center}
        \resizebox*{.75\linewidth}{!}{%
            \begin{forest}
                forked edges,
                for tree={
                    grow'=east,
                    draw,
                    rounded corners,
                    text width=2.7cm,
                    node options={align=center},
                }       
                [TEXT, fill=col4, parent, s sep=1cm
                [TEXT TEXT, for tree={child, fill=col3}
                [TEXT\\ TEXT, for tree={child, fill=col2}
                [{TEXT\\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT}]]
                [TEXT \\ TEXT, for tree={child, fill=col2}
                [{TEXT \\ TEXT, TEXT \\ TEXT}]]
                [TEXT-\\TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXT, TEXT \\TEXT}]]
                [TEXT\\TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXTg, TEXT \\TEXT}]]
                [TEXT\\ TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXT, TEXT \\TEXT}]]
                ]
                [TEXT TEXT, for tree={child, fill=col3}
                [TEXT\\ TEXT, for tree={child, fill=col2}
                [{TEXT\\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT}]]
                [TEXT \\ TEXT, for tree={child, fill=col2}
                [{TEXT \\ TEXT, TEXT \\ TEXT}]]
                [TEXT-\\TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXT, TEXT \\TEXT}]]
                [TEXT\\TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXTg, TEXT \\TEXT}]]
                [TEXT\\ TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXT, TEXT \\TEXT}]]
                ]
                ]
                ]
                ]
        \end{forest}}
        \captionsetup{type=figure}
        \captionof{figure}{Caption.}
        \label{tikz:taxonomy}
    \end{center}
\end{document}
1
  • simply add anchor=parent to for tree=.......
    – js bibra
    May 30 '21 at 13:27
2

enter image description here

\documentclass[a4paper,11pt]{article}
\usepackage[edges]{forest}
\usepackage{caption}

    % Source <------------- https://tex.stackexchange.com/questions/300373/saving-horizontal-space-in-tree-diagram

%Defining tikz classes for tree diagrams
\tikzset{parent/.style={align=center,text width=3cm,rounded corners=3pt},
    child/.style={align=center,text width=3cm,rounded corners=3pt}
}

\colorlet{col1}{white}
\colorlet{col2}{gray!20}
\colorlet{col3}{gray!40}
\colorlet{col4}{gray!60}

\begin{document}
    \begin{center}
        \resizebox*{.75\linewidth}{!}{%
            \begin{forest}
                forked edges,
                for tree={
                    grow'=east,
                    draw,
                    rounded corners,
                    text width=2.7cm,
                    node options={align=center},anchor=parent
                }       
                [TEXT, fill=col4, parent, s sep=1cm
                [TEXT TEXT, for tree={child, fill=col3}
                [TEXT\\ TEXT, for tree={child, fill=col2}
                [{TEXT\\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT}]]
                [TEXT \\ TEXT, for tree={child, fill=col2}
                [{TEXT \\ TEXT, TEXT \\ TEXT}]]
                [TEXT-\\TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXT, TEXT \\TEXT}]]
                [TEXT\\TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXTg, TEXT \\TEXT}]]
                [TEXT\\ TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXT, TEXT \\TEXT}]]
                ]
                [TEXT TEXT, for tree={child, fill=col3}
                [TEXT\\ TEXT, for tree={child, fill=col2}
                [{TEXT\\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT, TEXT \\ TEXT}]]
                [TEXT \\ TEXT, for tree={child, fill=col2}
                [{TEXT \\ TEXT, TEXT \\ TEXT}]]
                [TEXT-\\TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXT, TEXT \\TEXT}]]
                [TEXT\\TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXTg, TEXT \\TEXT}]]
                [TEXT\\ TEXT, for tree={child, fill=col2}
                [{TEXT \\TEXT, TEXT \\TEXT}]]
                ]
                ]
                ]
                ]
        \end{forest}}
        \captionsetup{type=figure}
        \captionof{figure}{Caption.}
        \label{tikz:taxonomy}
    \end{center}
\end{document}
1
  • Worked like charm! Thank you @js bibra
    – relinquere
    May 30 '21 at 17:18

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.