12

I would like to make visual table of contents, just like here. However, I have a part that does not have a section and I would like it to output, but it does not do so.

I took my code from here as well and deleted the sections for the last part (\part {Model-building Methods}):

 \documentclass[12pt,oneside, tikz, ignorerest=false]{standalone}

\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}

\usepackage{etoc}
% \usepackage{hyperref}% if links are wanted
\begin{document}

\newtoks\treetok
\newtoks\parttok
\newtoks\sectiontok

\newcommand*\treenode {}  % just to check we don't overwrite something
\newcommand*\tmprotate {} % just to check we don't overwrite something
\newcommand*\tmpoption {} % just to check we don't overwrite something
\newcommand*\tmpstuff  {} % just to check we don't overwrite something

\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

\newcommand*{\appendchildtree}[3]{% 
% this is to construct "t1 child [concept color= #3]{t2}" from #1=t1 and #2=t2
% t1 and t2 are two toks variable (not macros)
% #3 = for example teal!60
   \edef\tmpstuff {\the#1 child [concept color = #3]{\the#2}}%
   #1\expandafter {\tmpstuff }%
}

\newcounter{partco}

\etocsetstyle{part}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
   \stepcounter{partco}%
   \ifcase\value{partco}%
   \or  \def\tmpoption {}%
        \def\tmprotate {}% first
   \or  \def\tmpoption {[concept]}%
        \def\tmprotate {[clockwise from = 60]}% second
   \else\def\tmpoption {}%
        \def\tmprotate {[counterclockwise from = 90]}% third and higher
   \fi
% define the part node
   \edef\treenode{node \tmpoption {\the\toks0. \the\toks2} \tmprotate }%
% this is a starting point which will be filled it by the section children
   \parttok\expandafter{\treenode}}
  {}

\etocsetstyle{section}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
% define the section node
   \edef\treenode {node {\the\toks0 \space\the\toks2}}
   \sectiontok\expandafter{\treenode}%
% update current part tree with this section node, adding the correct color
   \ifcase\value{partco}%
   \or \appendchildtree\parttok\sectiontok {teal!30}% first
   \or \appendchildtree\parttok\sectiontok {yellow!40}% second
   \else\appendchildtree\parttok\sectiontok {green!30}% third etc...
   \fi }
% This updates the global tree with the data  from the
% part and all its children sections
  {\ifcase\value{partco}%
   \or \appendchildtree\treetok\parttok {teal!60}%   first
   \or \appendchildtree\treetok\parttok {yellow!80}% second
   \else\appendchildtree\treetok\parttok {green!50}% third and next ...
   \fi
   }

\etocsettocstyle
  {\treetok{\node{\textbf{Discrete Data Analysis with R}} [clockwise from=60]}}
  {\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group

\tableofcontents

% \showthe\treetok % debugging

\begin{tikzpicture}[grow cyclic, text width=2cm, 
                    align=flush center, 
                    every node/.style=concept, 
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]

\the\treetok
\end{tikzpicture}


\part {Getting Started}
\section {Introduction}
\section {Working with Categorical Data}
\section {Discrete Distributions}


\part {Exploratory  Methods}
\section {Two-way Contingency Tables}
\section {Mosaic Displays}
\section {Correspondence Analysis}


\part {Model-building Methods}


\end{document}

The code above produces the image below. However, as you can see, the part Model-building Methods is not outputted in the image.

I would like to output the part ''Model-building Methods'' as well, even though it doesn't contain sections. How can I do this?

Thanks in advance.

enter image description here

1
  • The examples in the etoc manual have some hand setting of toc depths for each part. Have you tried to mimic that? Commented Aug 24, 2015 at 11:52

1 Answer 1

5

Sorry about the late answer. I modify the code from your question to handle the case of a part with no sections: the trick is to move from the section style to the part style the code which updates the global token register with the tree data.

\documentclass[12pt,oneside, tikz, ignorerest=false]{standalone}

\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}

\usepackage{etoc}
% \usepackage{hyperref}% if links are wanted
\begin{document}

\newtoks\treetok
\newtoks\parttok
\newtoks\sectiontok

\newcommand*\treenode {}  % just to check we don't overwrite something
\newcommand*\tmprotate {} % just to check we don't overwrite something
\newcommand*\tmpoption {} % just to check we don't overwrite something
\newcommand*\tmpstuff  {} % just to check we don't overwrite something

\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
  #1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}

\newcommand*{\appendchildtree}[3]{% 
% this is to construct "t1 child [concept color= #3]{t2}" from #1=t1 and #2=t2
% t1 and t2 are two toks variable (not macros)
% #3 = for example teal!60
   \edef\tmpstuff {\the#1 child [concept color = #3]{\the#2}}%
   #1\expandafter {\tmpstuff }%
}

\newcounter{partco}

\etocsetstyle{part}
  {\etocskipfirstprefix}
% This updates the global tree with the data  from the
% previous part and all its children sections
  {\ifcase\value{partco}%
   \or \appendchildtree\treetok\parttok {teal!60}%   first
   \or \appendchildtree\treetok\parttok {yellow!80}% second
   \else\appendchildtree\treetok\parttok {green!50}% third and next ...
   \fi
   }
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
   \stepcounter{partco}%
   \ifcase\value{partco}%
   \or  \def\tmpoption {}%
        \def\tmprotate {}% first
   \or  \def\tmpoption {[concept]}%
        \def\tmprotate {[clockwise from = 60]}% second
   \else\def\tmpoption {}%
        \def\tmprotate {[counterclockwise from = 90]}% third and higher
   \fi
% define the part node
   \edef\treenode{node \tmpoption {\the\toks0. \the\toks2} \tmprotate }%
% this is a starting point which will be filled it by the section children
   \parttok\expandafter{\treenode}}
% This updates the global tree with the data  from the
% last part and all its children sections
  {\ifcase\value{partco}%
   \or \appendchildtree\treetok\parttok {teal!60}%   first
   \or \appendchildtree\treetok\parttok {yellow!80}% second
   \else\appendchildtree\treetok\parttok {green!50}% third and next ...
   \fi
   }

\etocsetstyle{section}
  {}
  {}
  {\toks0 \expandafter{\etocthelinkednumber}%
   \toks2 \expandafter{\etocthelinkedname }%
% define the section node
   \edef\treenode {node {\the\toks0 \space\the\toks2}}
   \sectiontok\expandafter{\treenode}%
% update current part tree with this section node, adding the correct color
   \ifcase\value{partco}%
   \or \appendchildtree\parttok\sectiontok {teal!30}% first
   \or \appendchildtree\parttok\sectiontok {yellow!40}% second
   \else\appendchildtree\parttok\sectiontok {green!30}% third etc...
   \fi }
  {}

\etocsettocstyle
  {\treetok{\node{\textbf{Discrete Data Analysis with R}} [clockwise from=60]}}
  {\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group

\tableofcontents

% \showthe\treetok % debugging

\begin{tikzpicture}[grow cyclic, text width=2cm, 
                    align=flush center, 
                    every node/.style=concept, 
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]

\the\treetok
\end{tikzpicture}

\part {Getting Started}
\section {Introduction}
\section {Working with Categorical Data}
\section {Discrete Distributions}

\part {Exploratory  Methods}
\section {Two-way Contingency Tables}
\section {Mosaic Displays}
\section {Correspondence Analysis}

\part {Model-building Methods}

\end{document}

mindmap of TOC

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .