[Tex/LaTex] How to put level 2 concept mindmap nodes alongside a rectangle

mindmapstikz-trees

What I have done:

  1. I have looked in to the pgf manual.

  2. I have searched on this site for mindmap and did not find a solution.

I have a mindmap with many nodes at level 2 and eight nodes at level 1. I figured it would be nice to have the level 2 nodes be along the sides of a (large) rectangle, while the level 1 nodes would still be arranged along a circle with center at the root node; this would guarantee that the paths from level 1 nodes to level 2 nodes to not cross. How can I achieve such a design ?

So far I have achieved this:

enter image description here

This is a mindmap with a minimal amount of manual intervention (changed starting angle for the parents V and VIII). I had to drop the children from parents II and IV for obvious reasons. If I could arrange the level 2 nodes along a rectangle, nothing would have to be left aside.

Here is a source for the image above. Ultimately this has to be on a4paper, alongside some text. The stuff is actually produced automatically from the actual headings of the document, but I have extracted here for convenience.

\documentclass[11pt,a4paper]{article}
\usepackage[margin=.2cm]{geometry}
\usepackage{xspace}
\usepackage[dvipsnames]{xcolor}
\usepackage{hyperref}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}

\newcommand\etoc{\textcolor{joli}{\ttfamily\bfseries etoc}\xspace}

\DeclareRobustCommand\csa [1] {{\ttfamily\hyphenchar\font45 \char`\\ #1}}


\usepackage{tikz}
\usetikzlibrary{mindmap}
\begin{document}
\noindent
\resizebox{.9\paperwidth}{!}
{\begin{tikzpicture}[grow cyclic, 
                    text width=2cm, 
                    align=flush center, 
                    every node/.style=concept, 
                    concept color=orange!60,
                    level 1/.style={level distance=6cm,sibling angle=45},
                    level 2/.style={level distance=8cm,sibling angle=25}
                    ]
\node {\textbf {The \etoc documentation}} child [concept color = teal!60]{node {I. Overview} child [concept color = teal!30]{node {3 Do I need to be a geek to use {\color {joli}\ttfamily \bfseries etoc}\xspace ?}} child [concept color = teal!30]{node {4 Line styles and toc display style}} child [concept color = teal!30]{node {5 A first example}} child [concept color = teal!30]{node {6 A second example}} child [concept color = teal!30]{node {7 Linked list of the main package commands}}} child [concept color = yellow!80]{node {II. Arbitrarily many TOCs, and local ones too}} child [concept color = green!50]{node {III. Surprising uses of {\color {joli}\ttfamily \bfseries etoc}\xspace } child [concept color = green!30]{node {15 The TOC of TOCs}} child [concept color = green!30]{node {16 Arbitrary ``Lists Of...'', \csa {etoctoccontentsline}}} child [concept color = green!30]{node {17 A TOC with a fancy layout}} child [concept color = green!30]{node {18 Another compatibility mode}} child [concept color = green!30]{node {19 The TOC as a tree}} child [concept color = green!30]{node {20 The TOC as a molecule}} child [concept color = green!30]{node {21 The TOC as a TikZ Mindmap}} child [concept color = green!30]{node {22 The TOC as a table}}} child [concept color = teal!60]{node {IV. Commands for the toc line styles}} child [concept color = yellow!80]{node {V. Commands for the toc display style} [counterclockwise from =-40] child [concept color = yellow!40]{node {27 Specifying the toc display style}} child [concept color = yellow!40]{node {28 Starred variants of the \csa {tableofcontents} etc... commands}} child [concept color = yellow!40]{node {29 Table of contents for this part}}} child [concept color = green!50]{node {VI. Using and customizing {\color {joli}\ttfamily \bfseries etoc}\xspace } child [concept color = green!30]{node {30 Summary of the main style commands}} child [concept color = green!30]{node {31 The package default line styles: \csa {etocdefaultlines}}} child [concept color = green!30]{node {32 Customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }} child [concept color = green!30]{node {33 One more example of colored TOC layout}}} child [concept color = teal!60]{node {VII. Tips} child [concept color = teal!30]{node {34 ... and tricks}}} child [concept color = yellow!80]{node {VIII. The code}[counterclockwise from =-50] child [concept color = yellow!40]{node {35 Timestamp}} child [concept color = yellow!40]{node {36 Change history}} child [concept color = yellow!40]{node {37 Implementation}}} ;
\end{tikzpicture}}
\end{document}

Here is the data for parents and children in a more legible display with linebreaks and spaces, for the gentle people who copy/paste for testing :

\node {\textbf {The \etoc documentation}}
       child [concept color = teal!60]
       {node {I. Overview}
              child [concept color = teal!30]{node {3 Do I need to be a geek to use {\color {joli}\ttfamily \bfseries etoc}\xspace ?}}
              child [concept color = teal!30]{node {4 Line styles and toc display style}}
              child [concept color = teal!30]{node {5 A first example}}
              child [concept color = teal!30]{node {6 A second example}}
              child [concept color = teal!30]{node {7 Linked list of the main package commands}}
              }
       child [concept color = yellow!80]{node {II. Arbitrarily many TOCs, and local ones too}}
       child [concept color = green!50]
       {node {III. Surprising uses of {\color {joli}\ttfamily \bfseries etoc}\xspace }
              child [concept color = green!30]{node {15 The TOC of TOCs}}
              child [concept color = green!30]{node {16 Arbitrary ``Lists Of...'', \csa {etoctoccontentsline}}}
              child [concept color = green!30]{node {17 A TOC with a fancy layout}}
              child [concept color = green!30]{node {18 Another compatibility mode}}
              child [concept color = green!30]{node {19 The TOC as a tree}}
              child [concept color = green!30]{node {20 The TOC as a molecule}}
              child [concept color = green!30]{node {21 The TOC as a TikZ Mindmap}}
              child [concept color = green!30]{node {22 The TOC as a table}}
              }
       child [concept color = teal!60]
       {node {IV. Commands for the toc line styles}}
       child [concept color = yellow!80]
       {node {V. Commands for the toc display style} [counterclockwise from =-40]
              child [concept color = yellow!40]{node {27 Specifying the toc display style}}
              child [concept color = yellow!40]{node {28 Starred variants of the \csa {tableofcontents} etc... commands}}
              child [concept color = yellow!40]{node {29 Table of contents for this part}}
              }
       child [concept color = green!50]
       {node {VI. Using and customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }
              child [concept color = green!30]{node {30 Summary of the main style commands}}
              child [concept color = green!30]{node {31 The package default line styles: \csa {etocdefaultlines}}}
              child [concept color = green!30]{node {32 Customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }}
              child [concept color = green!30]{node {33 One more example of colored TOC layout}}
              }
       child [concept color = teal!60]
       {node {VII. Tips}
              child [concept color = teal!30]{node {34 ... and tricks}}
              }
       child [concept color = yellow!80]
       {node {VIII. The code}[counterclockwise from =-50]
              child [concept color = yellow!40]{node {35 Timestamp}}
              child [concept color = yellow!40]{node {36 Change history}}
              child [concept color = yellow!40]{node {37 Implementation}}
              } ;

Thanks to this answer below I got some starting code to play width. I have not tried the rectangular thing, I know what needs to be done, but it is too complicated for me at this time, not only because it is quite mathematical, but also because it would need knowing doing calculations with TikZ in a better way than I currently know (which is nil). But I learned from the answer how to position the grand children on a circle. Thus I could add the missing sections and here is what I get at this time:

enter image description here

This will make a perfect title page.

\documentclass[tikz,border=9]{standalone}
\usetikzlibrary{mindmap}
\usepackage{xspace}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\newcommand\etoc{\textcolor{joli}{\ttfamily\bfseries etoc}\xspace}
\DeclareRobustCommand\csa[1]{{\ttfamily\hyphenchar\font45 \char`\\ #1}}

\newcount\tikznumberofcurrentgrandchild

\def\tikzmycustomgrowth {%
  \pgftransformreset
  \ifnum\tikztreelevel=1
    \pgftransformrotate {(\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentchild-1)}%
  \fi
  \ifnum\tikztreelevel=2
    \pgftransformrotate {(\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentgrandchild-4)}%
    \global\advance\tikznumberofcurrentgrandchild by 1
 \fi
 \pgftransformxshift {\the\tikzleveldistance}%
}
\tikzset{
    branch color/.style={
        concept color=#1!white,
        every child/.append style={concept color=#1!white!30!white},
    }
}

\begin{document}
\begin{tikzpicture}[mindmap,
                    growth function=\tikzmycustomgrowth,
                    nodes={concept},
                    concept color=orange!60,
                    root concept/.append style={font=\huge, minimum size=5.5cm},
                    level 1/.append style={level distance=6.5cm, sibling angle=360/8},
                    level 1 concept/.append style={font=\Large,minimum size=4cm},
                    level 2/.append style={level distance=12.5cm, sibling angle=360/35},
                    % distance par rapport au CENTRE ! (avec le code tel qu'en ce moment)
                   ]
\tikznumberofcurrentgrandchild=0
\node [root concept]{The \etoc package} 
child [branch color=teal!60]{node {I Overview} 
child {node {3 Do I need to be a geek to use {\color {joli}\ttfamily \bfseries etoc}\xspace ?}} 
child {node {4 Line styles and toc display style}} 
child {node {5 A first example}} 
child {node {6 A second example}} 
child {node {7 Linked list of the main package commands}}} 
child [branch color=yellow!80]{node {II Arbitrarily many TOCs, and local ones too} 
child {node {8 Labeling and reusing elsewhere}} 
child {node {9 A powerful functionality of {\color {joli}\ttfamily \bfseries etoc}\xspace : the re-assignment of levels with \csa {etocsetlevel}}} 
child {node {10 The \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}toc\discretionary {-}{}{}depth} and \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}next\discretionary {-}{}{}toc\discretionary {-}{}{}depth} commands}} 
child {node {11 The command \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}toc\discretionary {-}{}{}dep\discretionary {-}{}{}th.toc}}} 
child {node {12 The commands \csa {etoc\discretionary {-}{}{}depth\discretionary {-}{}{}tag.toc} and \csa {etocsettagdepth}}} 
child {node {13 Adding commands to the \texttt {.toc} file}} 
child {node {14 Two Examples}}} 
child [branch color=green!50]{node {III Surprising uses of {\color {joli}\ttfamily \bfseries etoc}\xspace } 
child {node {15 The TOC of TOCs}} 
child {node {16 Arbitrary ``Lists Of...'', \csa {etoctoccontentsline}}} 
child {node {17 A TOC with a fancy layout}} 
child {node {18 Another compatibility mode}} 
child {node {19 The TOC as a tree}} 
child {node {20 The TOC as a molecule}} 
child {node {21 The TOC as a TikZ Mindmap}} 
child {node {22 The TOC as a table}}} 
child [branch color=teal!60]{node {IV Commands for the toc line styles} 
child {node {23 The \csa {etocsetstyle} command}} 
child {node {24 The \csa {etocsetlevel} command}} 
child {node {25 Scope of commands added to the \texttt {.toc} file}} 
child {node {26 Am I also red?}}} 
child [branch color=yellow!80]{node {V Commands for the toc display style} 
child {node {27 Specifying the toc display style}} 
child {node {28 Starred variants of the \csa {tableofcontents} etc... commands}} 
child {node {29 Table of contents for this part}}} 
child [branch color=green!50]{node {VI Using and customizing {\color {joli}\ttfamily \bfseries etoc}\xspace } 
child {node {30 Summary of the main style commands}} 
child {node {31 The package default line styles: \csa {etocdefaultlines}}} 
child {node {32 Customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }} 
child {node {33 One more example of colored TOC layout}}} 
child [branch color=teal!60]{node {VII Tips} 
child {node {34 ... and tricks}}} 
child [branch color=yellow!80]{node {VIII The code} 
child {node {35 Timestamp}} 
child {node {36 Change history}} 
child {node {37 Implementation}}} ;
\end{tikzpicture}
\end{document}

Best Answer

Edit

The answer is (again) YES as long as you bring enough \if with you.

\documentclass[tikz,border=9]{standalone}
\usetikzlibrary{mindmap}
\usepackage{xspace}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\newcommand\etoc{\textcolor{joli}{\ttfamily\bfseries etoc}\xspace}
\DeclareRobustCommand\csa[1]{{\ttfamily\hyphenchar\font45 \char`\\ #1}}

\newcount\tikznumberofcurrentgrandchild

\def\tikzretangulargroth{%
    \pgftransformreset
    \ifnum\tikztreelevel=1
        \pgftransformrotate{55+((\pgfkeysvalueof{/tikz/sibling angle})*(\tikznumberofcurrentchild)}%
        \pgftransformxshift{\the\tikzleveldistance}%
    \fi
    \ifnum\tikztreelevel=2
        \pgfmathsetmacro\tikzoffsetofcurrentchild{(\tikzsiblingdistance)*(\tikznumberofcurrentgrandchild)}%
        \ifdim\tikzoffsetofcurrentchild pt<\tikzlevelwidth pt
            \pgftransformxshift{\tikzlevelwidth/2-\tikzoffsetofcurrentchild}
            \pgftransformyshift{\tikzlevelheight/2}
        \else
        \pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelwidth}%
        \ifdim\tikzoffsetofcurrentchild pt<\tikzlevelheight pt
            \pgftransformxshift{-\tikzlevelwidth/2}
            \pgftransformyshift{\tikzlevelheight/2-\tikzoffsetofcurrentchild}
        \else
        \pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelheight}%
        \ifdim\tikzoffsetofcurrentchild pt<\tikzlevelwidth pt
            \pgftransformxshift{-\tikzlevelwidth/2+\tikzoffsetofcurrentchild}
            \pgftransformyshift{-\tikzlevelheight/2}
        \else
        \pgfmathsetmacro\tikzoffsetofcurrentchild{\tikzoffsetofcurrentchild-\tikzlevelwidth}%
        \ifdim\tikzoffsetofcurrentchild pt<\tikzlevelheight pt
            \pgftransformxshift{\tikzlevelwidth/2}
            \pgftransformyshift{-\tikzlevelheight/2+\tikzoffsetofcurrentchild}
        \fi\fi\fi\fi
        \global\advance\tikznumberofcurrentgrandchild by1
    \fi
}
\tikzset{
    branch color/.style={
        concept color=#1!white,
        every child/.append style={concept color=#1!white!30!white},
    },
    level width/.store in=\tikzlevelwidth,
    level height/.store in=\tikzlevelheight
}
\begin{document}
\tikznumberofcurrentgrandchild=0
\begin{tikzpicture}[
        mindmap,
        growth function=\tikzretangulargroth,
        nodes={concept},
        concept color=orange!60,
        root concept/.append style={font=\huge, minimum size=5.5cm},
        level 1/.append style={level distance=6.5cm, sibling angle=360/8},
        level 1 concept/.append style={font=\Large,minimum size=4cm},
        level 2/.append style={level width=20cm,level height=28.7cm, sibling distance=2.77cm},
                                          % A4 paper with margin=.5cm
    ]
    \node [root concept]{The \etoc package} 
        child [branch color=teal!60]{node {I Overview} 
            child {node {3 Do I need to be a geek to use {\color {joli}\ttfamily \bfseries etoc}\xspace ?}} 
            child {node {4 Line styles and toc display style}} 
            child {node {5 A first example}} 
            child {node {6 A second example}} 
            child {node {7 Linked list of the main package commands}}
        } 
        child [branch color=yellow!80]{node {II Arbitrarily many TOCs, and local ones too} 
            child {node {8 Labeling and reusing elsewhere}} 
            child {node {9 A powerful functionality of {\color {joli}\ttfamily \bfseries etoc}\xspace : the re-assignment of levels with \csa {etocsetlevel}}} 
            child {node {10 The \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}toc\discretionary {-}{}{}depth} and \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}next\discretionary {-}{}{}toc\discretionary {-}{}{}depth} commands}} 
            child {node {11 The command \csa {etoc\discretionary {-}{}{}set\discretionary {-}{}{}toc\discretionary {-}{}{}dep\discretionary {-}{}{}th.toc}}} 
            child {node {12 The commands \csa {etoc\discretionary {-}{}{}depth\discretionary {-}{}{}tag.toc} and \csa {etocsettagdepth}}} 
            child {node {13 Adding commands to the \texttt {.toc} file}} 
            child {node {14 Two Examples}}
        } 
        child [branch color=green!50]{node {III Surprising uses of {\color {joli}\ttfamily \bfseries etoc}\xspace } 
            child {node {15 The TOC of TOCs}} 
            child {node {16 Arbitrary ``Lists Of...'', \csa {etoctoccontentsline}}} 
            child {node {17 A TOC with a fancy layout}} 
            child {node {18 Another compatibility mode}} 
            child {node {19 The TOC as a tree}} 
            child {node {20 The TOC as a molecule}} 
            child {node {21 The TOC as a TikZ Mindmap}} 
            child {node {22 The TOC as a table}}
        } 
        child [branch color=teal!60]{node {IV Commands for the toc line styles} 
            child {node {23 The \csa {etocsetstyle} command}} 
            child {node {24 The \csa {etocsetlevel} command}} 
            child {node {25 Scope of commands added to the \texttt {.toc} file}} 
            child {node {26 Am I also red?}}
        } 
        child [branch color=yellow!80]{node {V Commands for the toc display style} 
            child {node {27 Specifying the toc display style}} 
            child {node {28 Starred variants of the \csa {tableofcontents} etc... commands}} 
            child {node {29 Table of contents for this part}}
        } 
        child [branch color=green!50]{node {VI Using and customizing {\color {joli}\ttfamily \bfseries etoc}\xspace } 
            child {node {30 Summary of the main style commands}} 
            child {node {31 The package default line styles: \csa {etocdefaultlines}}} 
            child {node {32 Customizing {\color {joli}\ttfamily \bfseries etoc}\xspace }} 
            child {node {33 One more example of colored TOC layout}}
        } 
        child [branch color=teal!60]{node {VII Tips} 
            child {node {34 ... and tricks}}
        } 
        child [branch color=yellow!80]{node {VIII The code} 
            child {node {35 Timestamp}} 
            child {node {36 Change history}} 
            child {node {37 Implementation}}
        }
    ;
\end{tikzpicture}
\end{document}

Old Answer

The answer is YES as long as you write your own growth function. The following example, though not rectangular, illustrates some ideas.

  • \tikz@grow@concentric is defined and hooked by
    growth function=\tikz@grow@concentric
  • Using \pgftransformreset and some supporting variables, a node could be at anywhere we want. In this case, level-2 concepts are aligned along a circle. This suggest that somehow their position do not (only) depend on their parents'.
  • I define branch color so we can assign the level-1 and level-2 concept color in just one step.

The drawbacks are

  • TikZ does not count children/descendants for you. It typesets parents first. So sibling angle=360/23 is assigned by hand.

  • Also you need to give the correct number of children in every branch by noc=5. (NOC stands for number of children)

  • \tikz@grow@concentric is designed for 2-level mind map. More variables and more if-statements are demanded for more levels.
  • The yellow part looks weird. I do not know why.

Code

\documentclass[tikz,border=9]{standalone}
\usetikzlibrary{mindmap,decorations}
\usepackage{xspace}
\definecolor{joli}{RGB}{225,95,0}
\definecolor{JOLI}{RGB}{225,95,0}
\newcommand\etoc{\textcolor{joli}{\ttfamily\bfseries etoc}\xspace}
\DeclareRobustCommand\csa[1]{{\ttfamily\hyphenchar\font45 \char`\\ #1}}

\makeatletter
\newcount\tikzcountgrandchild
\def\tikz@grow@concentric{%
  \pgftransformreset%
  \pgftransformrotate{(\pgfkeysvalueof{/tikz/sibling angle})*(\tikzcountgrandchild)}%
  \ifnum\tikztreelevel=1
    \pgftransformrotate{(\pgfkeysvalueof{/tikz/sibling angle})*(\pgfkeysvalueof{/tikz/noc}-1)/2}%
  \fi
  \pgftransformxshift{\the\tikzleveldistance}%
  \ifnum\tikztreelevel=2
    \global\advance\tikzcountgrandchild by1
 \fi
}
\tikzset{
    noc/.initial=0,
    branch color/.style={
        concept color=#1!white,
        every child/.append style={concept color=#1!white!30!white},
    }
}
\begin{document}
\begin{tikzpicture}[text width=2cm,align=flush center,
                    mindmap,growth function=\tikz@grow@concentric,
                    sibling angle=360/23,nodes={concept},concept color=orange!60,
                    level 1/.style={level distance=10cm},
                    level 2/.style={level distance=16cm}
                   ]
\node{\textbf{The \etoc documentation}}
    child[noc=5,branch color=teal!60]{node{I. Overview}
        child{node{3 Do I need to be a geek to use{\color{joli}\ttfamily \bfseries etoc}\xspace ?}}
        child{node{4 Line styles and toc display style}}
        child{node{5 A first example}}
        child{node{6 A second example}}
        child{node{7 Linked list of the main package commands}}
    }
    child[noc=0,branch color=yellow!80]{node{II. Arbitrarily many TOCs, and local ones too}
    }
    child[noc=7,branch color=green!50]{node{III. Surprising uses of{\color{joli}\ttfamily \bfseries etoc}\xspace }
        child{node{15 The TOC of TOCs}}
        child{node{16 Arbitrary ``Lists Of...'', \csa{etoctoccontentsline}}}
        child{node{17 A TOC with a fancy layout}}
        child{node{18 Another compatibility mode}}
        child{node{19 The TOC as a tree}}
        child{node{21 The TOC as a TikZ Mindmap}}
        child{node{22 The TOC as a table}}
    }
    child[noc=0,branch color=teal!60]{node{IV. Commands for the toc line styles}
    }
    child[noc=3,branch color=yellow!80]{node{V. Commands for the toc display style}
        child{node{27 Specifying the toc display style}}
        child{node{28 Starred variants of the \csa{tableofcontents} etc... commands}}
        child{node{29 Table of contents for this part}}
    }
    child[noc=4,branch color=green!50]{node{VI. Using and customizing{\color{joli}\ttfamily \bfseries etoc}\xspace }
        child{node{30 Summary of the main style commands}}
        child{node{31 The package default line styles: \csa{etocdefaultlines}}}
        child{node{32 Customizing{\color{joli}\ttfamily \bfseries etoc}\xspace }}
        child{node{33 One more example of colored TOC layout}}
    }
    child[noc=1,branch color=teal!60]{node{VII. Tips}
        child{node{34 ... and tricks}}}
    child[noc=3,branch color=yellow!80]{node{VIII. The code}
        child{node{35 Timestamp}}
        child{node{36 Change history}}
        child{node{37 Implementation}}
    }
;
\end{tikzpicture}
\end{document}
Related Question