7

How to prepare table of contents as follows:

sample

\documentclass{article}
\usepackage{tikz}
\usepackage{tikz-qtree}
\begin{document}

\begin{tikzpicture}
\tikzset{grow'=right,level distance=32pt}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west}}
\Tree [.S [.Introduction ] [.Taxonomy
 ] ]
\end{tikzpicture}
\section{Introduction}
\section{Taxonomy}
\section{User Association}
\subsection{Subsection Header}
\end{document}
11
  • 1
    How much have you got so far? Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – DG'
    Commented Apr 17, 2017 at 8:31
  • I tried using qtree, however I don't know how to add table of contents in qtree, thus, I thought MWE is no use here.
    – Mithun
    Commented Apr 17, 2017 at 16:06
  • 1
    A MWE is always useful. And almost mandatory in your case, since we don't know anything about your document (i.e. documentclass, packages, etc.)
    – DG'
    Commented Apr 17, 2017 at 16:10
  • 1
    Ok, I'll add some that might be helpful.
    – Mithun
    Commented Apr 17, 2017 at 16:11
  • @DG' , I added, please kindly check.
    – Mithun
    Commented Apr 17, 2017 at 16:43

1 Answer 1

10

Definitely shouldn't have tried to answer this ....

Proof of concept:

\documentclass{article}
\usepackage[edges]{forest}
\forestset{%
  subsection/.style={%
    delay n={%
      >O{n} %
    }{%
      for preceding siblings={do dynamics},
      temptoksa/.option=name,
      if nodewalk valid={previous}{%
        for previous={%
          if section={append/.register=temptoksa}{}%
        }%
      }{%
        replace by={[, coordinate, append]},
      },
    },
  },
  declare boolean={section}{0},
}
\makeatletter
\newcommand\foresttoc{%
  \begingroup
    \xdef\foresttoctoc{}%
    \renewcommand\contentsline[3]{%
      \let\tempb\foresttoctoc
      \xdef\foresttoctoc{\tempb[{##2}, ##1]}%
    }%
    \renewcommand\numberline[1]{Sec.~##1 }%
    \bracketset{action character=@}%
    \@starttoc{toc}%
    \begin{forest}
      before typesetting nodes={
        forked edges,
        for tree={
          grow'=0,
          anchor=parent,
          tier/.option=level,
        },
        where level=1{fork sep'=0pt}{},
      },
      [, coordinate,   @+\foresttoctoc  ]
    \end{forest}%
  \endgroup
}
\makeatother
\begin{document}
\foresttoc
% \tableofcontents
\subsection{Awkward}
\section{User Association}
\subsection{Subsection Header}
\subsection{Subsection Header}
\section{Introduction}
\section{Taxonomy}
\section{User Association}
\subsection{Subsection Header}
\subsection{Subsection Header}
\end{document}

tree-toc

This allows - but no longer requires - you to have a regular table of contents, too. This is good because the desired format is pretty useless for locating things, something regular tables of contents do by design.

7
  • I am surprised that it takes you ~20 hours. :p
    – Symbol 1
    Commented Apr 18, 2017 at 3:56
  • 1
    I'm surprised someone could even answer! This should deserve a bounty!
    – CarLaTeX
    Commented Apr 18, 2017 at 3:58
  • @CarLaTeX definitely deserves. I don't have enough points to offer.
    – Mithun
    Commented Apr 18, 2017 at 4:14
  • @Mithun I hope someone with > 20k will do it for us! I've already started too much bounties, recently :):):)
    – CarLaTeX
    Commented Apr 18, 2017 at 4:18
  • 1
    @Mithun Please see edited version above. A regular ToC is now permitted, but no longer required. (But we still use the .toc file and apparatus to collect the information etc.)
    – cfr
    Commented Apr 21, 2017 at 0:26

You must log in to answer this question.

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