目录作为右侧生长的树

目录作为右侧生长的树

如何准备目录如下:

样本

\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}

答案1

绝对不应该尝试回答这个问题......

概念证明:

\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}

树目录

这允许(但不再要求)您也拥有常规目录。这很好,因为所需的格式对于定位内容来说毫无用处,而常规目录的设计就是如此。

相关内容