5

I have the following script:

\documentclass[conference,compsoc]{IEEEtran}
\usepackage{tikz} %for the heirarchical tree

%for the hierarchical tree
\usetikzlibrary{arrows,shapes,positioning,shadows,trees} 
\tikzset{
  basic/.style  = {draw, text width=2cm, drop shadow, font=\sffamily, rectangle},
  root/.style   = {basic, rounded corners=2pt, thin, align=center,
                   fill=green!30},
  level 2/.style = {basic, rounded corners=6pt, thin,align=center, fill=green!60,
                   text width=8em},
  level 3/.style = {basic, thin, align=left, fill=pink!60, text width=6.5em}
}

\begin{document}

\begin{tikzpicture}
[-,thick,%
  every node/.style={shape=rectangle,inner sep=3pt,draw,thick}]
\footnotesize
\node {Parent} [edge from parent fork down]
[sibling distance=4cm]
child {node {Type}}
child {node {Title Here}
    [sibling distance=2cm]
    child {node {Two Words Long}}
    child {node {Two Word Long}}
    }
;
\end{tikzpicture}

\end{document}

That outputs the following figure: enter image description here

I need to get the childs to be squared similar to their parents and avoid intersection among any two nodes. How to do this?

6

This is simple: don't define node shapes with rounded corners and use appropriate large sibling distance. For rectangle shape of nodes:

\documentclass[conference,compsoc]{IEEEtran}
\usepackage{tikz} 
\usetikzlibrary{arrows, positioning, shadows, shapes, trees}

\begin{document}
    \begin{tikzpicture}[-,thick,%
every node/.style = {rectangle, draw, thick, fill=white,
                     drop shadow, font=\sffamily},
 sibling distance = 30mm 
                       ]
\node {Parent} [edge from parent fork down]
    child {node {Type}}
    child {node {Title Here}
        child {node {Two Words Long}}
        child {node {Two Word Long}}
            };
    \end{tikzpicture}
\end{document}

enter image description here

With forest is even simpler, there is not need to define sibling distance, suffice distance between nodes:

\documentclass[conference,compsoc]{IEEEtran}
\usepackage{tikz}   % for tikz trees
\usetikzlibrary{arrows, positioning, shadows, shapes, trees}
\usepackage[edges]{forest} % for forest tree

\begin{document}
   \begin{forest}
    for tree={              % style of tree nodes
      draw, semithick,
             font = \sffamily,
             fill = white, drop shadow,                            
             edge = {draw, semithick},
           anchor = north,
             grow = south,
                            % style of tree (edges, distances, direction)
    forked edge,            % for forked edge
            s sep = 8mm,    % sibling distance
            l sep = 8mm,    % level distance
         fork sep = 4mm,    % distance from parent to branching point
         tier/.option=level,
               }
     [Parent
      [Type]
      [Title Here
        [Two Words Long]
        [Two Words Long]
      ]
    ]
    \end{forest}
\end{document}

The result is almost the same:

enter image description here

To have square shapes for nodes is more tricky. I I suppose, that the length of text in real tree will be the same, than the text height can be calculates from defined text width:

\documentclass[conference,compsoc]{IEEEtran}
\usepackage{tikz}   % for tikz trees
\usetikzlibrary{arrows, positioning, shadows, shapes, trees}
\usepackage[edges]{forest} % for forest tree

\begin{document}

    \begin{tikzpicture}[-,thick,%
every node/.style = {rectangle, draw, thick, fill=white,
                     inner sep=2mm, text width=18mm, minimum height=18mm,
                     align=flush center,
                     drop shadow, font=\sffamily},
 sibling distance = 30mm,
   level distance = 30mm
]
\node {Parent} [edge from parent fork down]
    child {node {Type}}
    child {node {Title Here}
        child {node {Two Words Long}}
        child {node {Two Word Long}}
            };
    \end{tikzpicture}
\end{document}

As expected, result is ugly and convinced me, that you actually mean rectangle and not square shape (as I assumed in the first and the second example):

enter image description here

  • I'd also adjust the height in order to have all the squares of the same height with text vertically and horizontally centered, leave out "Long" from one of the two last node and you'll see what I mean... – CarLaTeX Feb 14 '17 at 14:27
  • @CarLaTeX, yes in title of question is square, not rectangle, but in mwe is used rectangle. This confuse me. Square can be tricky ... if the length of the text in node is not known ... I will add option for square shape too. But first a forest solution .-) – Zarko Feb 14 '17 at 14:37
  • Sorry, I wrote squares but intended rectangle (I think the OP, too)... my note was only about alignment :) – CarLaTeX Feb 14 '17 at 14:44
  • @CarLaTeX, for further "fine" tuning I will wait on OP response. I didn't measure image width, but over thumb I estimate that it can be placed in column width defined with IEEEtran document class. – Zarko Feb 14 '17 at 14:54
  • However, it looks better with square nodes :) – CarLaTeX Feb 14 '17 at 14:58

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.