2

in my book project, I was inspired by fantastic table of contents display as a mindmap, posted as answer in this question:

Visual table of contents using tikz mindmap or similar

but in my case, the mind map is pretty big and I would like, at least try to, make it span over two A4 pages. For that, I happen to find solution of Mr. Scharrer in answer to this question:

How to include a picture over two pages, left part on left side, right on right (for books)?

However, simple applying mind map code into the command for two page picture led to non-coherent behaviour of the mindmap (even side wasnt fully rendered). I decided to try to generate the table of contents outside of the main document, then include it as a .pdf as stated in solution of second question.

For that, I found a solution from Mr. Oberdiek, using zref package:

Export only table of contents

but I am having trouble to generate exported table of contents in other format than default one. And TikZ mind-map format is desired.

What have I got until now:

file myreport.text:

\documentclass{book}
\usepackage{zref-abspage,zref-thepage}
\makeatletter
\newcommand*{\pagevaluelabel}[1]{%
  \zref@labelbyprops{toc}{abspage}%
}
\makeatother
\AtBeginDocument{%
  \addtocontents{toc}{\string\providecommand\string\pagevaluelabel[1]{}}%
  \addtocontents{toc}{\string\pagevaluelabel{toc}}%
}
\usepackage{hyperref}

\setcounter{secnumdepth}{4}

\begin{document}

\frontmatter

Title page
\newpage

\chapter*{Foreword}

\tableofcontents

\mainmatter

\chapter{Chapter}

\section{Section}

\subsection{Subsection}

\subsubsection{Subsubsection}

\end{document}

file myreport-toc

\documentclass{book}

\usepackage [a3paper,%
         landscape,%
         twoside,%
         inner=2.5cm,%
         outer=2.5cm,%
         bottom=3.2cm,%
        headheight=14.5pt, % Header height
        footskip=1.4cm, % Space from the bottom margin to the baseline of the footer
        headsep=10pt, % Space from the top margin to the baseline of the header
        %showframe, % Uncomment to show how the type block is set on the page
         ] {geometry}

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

\usepackage{etoc}

\usepackage{hyperref}
\usepackage{zref-xr}
\zexternaldocument[main:]{test}\relax

\makeatletter
\newcommand*{\tocinclude}[1]{%
   \begingroup
    \makeatletter
    \def\@prj{#1}%
    \let\contentsline\foreign@contentsline
    \input{\@prj.toc}%
  \endgroup
}
\def\foreign@contentsline#1#2#3#4{%
  \ifx\\#4\\%
    \csname l@#1\endcsname{#2}{#3}%
  \else
    \ifHy@linktocpage
      \csname l@#1\endcsname{{#2}}{%
        \hyper@linkfile{#3}{\@prj.pdf}{#4}%
      }%
    \else
      \csname l@#1\endcsname{%
        \hyper@linkfile{#2}{\@prj.pdf}{#4}%
      }{#3}%
    \fi
  \fi
}%

\begin{document}
\makeatletter
\zref@refused{main:toc}
\setcounter{page}{%
  \numexpr\zref@extractdefault{main:toc}{abspage}{1}\relax
}
\renewcommand*{\thepage}{%
  \zref@extractdefault{main:thepage\number\value{page}}%
  {page}{\arabic{page}}%
}
\tocinclude{myreport}

\clearpage

\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{My book title}} [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}

\end{document}

I am sorry for this not being an short MWE (not even short question), but I think its a pretty complex one.

I would like to ask, how to put this formatting information (commands \etocsetstyle) into toc extraction procedure in order to produce table of contents as a mind map. Ideally with hyperlinks preserved (but not necessary). Any help would be very much appreciated, even as a nudge which part of documentation read, since I wasnt able to find solution anywhere.

With hope that someone will take interest in this, regards

Tomáš Kruliš

2 Answers2

3

You can store the tikzpicture in a box and then clip parts of this box. (hyperlinks won't work correctly, so better disable them, but by including a pdf you are loosing them too).

You could also try to add clipping pathes directly to the tikzpicture, but imho it is more difficult to get the correct values.

The code until \tableofcontents is from one of the answers you linked to, the clipping code is behind, the first uses a path inside the picture, the next use the box. Which clipping path is sensible depends on your real mindmap.

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{mindmap}
\pagestyle{empty}

\usepackage{etoc}
\newsavebox\tocbox

\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


\savebox\tocbox{%
\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}}

\noindent\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}]
  \path[clip] (0,-0.4\textheight) rectangle (\textwidth,0.4\textheight);
\the\treetok
\end{tikzpicture}


\begin{tikzpicture}
\path[clip] (0,0) rectangle (\dimexpr 0.5\wd\tocbox,\ht\tocbox);
\node[anchor=south west,inner sep=0pt] at (0,0){\usebox\tocbox};
\end{tikzpicture}

\begin{tikzpicture}
\path[clip] (\dimexpr 0.5\wd\tocbox,0) rectangle (\wd\tocbox,\ht\tocbox);
\node[anchor=south west,inner sep=0pt] at (0,0){\usebox\tocbox};
\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}
\section {Logistic Regression Models}
\section {Polytomous Responses}
\section {Loglinear and Logit Models}
\section {Extending Loglinear Models}
\section {Generalized Linear Models}


\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Thank you very much for your answer, Mrs. Fischer. I actually have to find out, which method will work best for me, if marmots or yours. But since marmots solution works with hyperref (eventhough I had to find out the correct cliping, because now the central part is on both pages), I will choose his answer as final. It might happen, that I actually give up on hyperref in this TOC and utilize it for other one. Thank you very much for your help. – Tomáš Kruliš Jul 31 '19 at 13:05
  • yes, @marmots idea is good. hyperref will work but be aware that clipping doesn't remove annotation areas, so don't add borders to the link (try \usepackage{hyperref} to see what I mean). – Ulrike Fischer Jul 31 '19 at 13:16
1

This is based on Ulrike Fischer's answer but here the \savebox is used to get the coordinates for the clip paths. They are installed, and hyperlinks work if you add \usepackage{hyperref} to the preamble.

\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{mindmap,calc}
\pagestyle{empty}

\usepackage{etoc}
\newsavebox\tocbox

\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
\newcounter{nc}

\savebox\tocbox{%
\begin{tikzpicture}[grow cyclic, text width=2cm,
                    align=flush center,
                    every node/.style=concept,
                    nodes={/utils/exec=\stepcounter{nc},alias=nc-\number\value{nc}},
                    concept color=orange!60,
                    level 1/.style={level distance=7cm,sibling angle=120},
                    level 2/.style={level distance=4cm,sibling angle=45}]

\the\treetok
\path let \p1=(nc-1.east),\p2=(current bounding box.south west),
\p3=(nc-1.west),\p4=(current bounding box.north east) in 
\pgfextra{\xdef\ClipPathOne{(\x2,\y2) rectangle (\x1+5pt,\y4)}%
\xdef\ClipPathTwo{(\x3-5pt,\y2) rectangle (\x4,\y4)}};
\end{tikzpicture}}

\noindent\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}]
  \path[clip] \ClipPathOne;
\the\treetok
\end{tikzpicture}

\noindent\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}]
  \path[clip] \ClipPathTwo;
\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}
\section {Logistic Regression Models}
\section {Polytomous Responses}
\section {Loglinear and Logit Models}
\section {Extending Loglinear Models}
\section {Generalized Linear Models}


\end{document}

enter image description here