0

I have seen that documents sometimes contain a figure with the document structure in the beginning. The figure shows the chapters and how they are connected (this can often be seen in dissertations). Random examples:

For my document, I am planning to also include such a figure. Now I was wondering whether it can be generated within LaTeX, so it updates automatically etc. which would make its handling likely much easier.

clel
  • 325

2 Answers2

0

Manually ... you can create them e.g. this way:

  1. one by \usepackage{tikz}
  2. same
  3. tikz or as a table; you may want to check the table- or matrix-packages on CTAN

Automatically ... I'm not sure. You probably think of converting the table of contents into some graphics. Though you could define and use variables in tikz, I don't know, if you could retrieve them from the toc.

I wonder, if that's even a good idea, should it be technically feasable ... it may turn out to be more of a macro-fiasco rather than a time-saver. So probably the best way to go is this:

  • sooner or later you'll know what the main structure of your document looks like
  • even if it changes, it will most likely be some minor changes
  • the final version will be clear anyway

Using tikz I'd do it this way:

  • putting \input{graph/flow} inside your document
  • maintaining and refining from time to time your extra-file graph/flow
  • go from coarse (\section) to fine (\subsection, \subsubsection etc.) over time as needed
  • if you want to ensure consistent titles everywhere, define them via some macros in the preamble

Here's some simple code. Unfortunately I can't put it nicely as code here, but you'll get the idea. The numbers of the chapters and section can certainly be retrieved one way or the other, but that's beyond my current scope ;-)

Code

And this is what it generates. What it may look like

MS-SPO
  • 11,519
  • 1
    That is a start :) I guess I'll have to look around to see how to semi-automatically retrieve section names and numbers and arrange them somewhat nicely. Ideally, an answer could include everything needed for that, let's see. – clel Jul 14 '21 at 14:24
  • 1
    nameref can be used to reference a name of a chapter or section directly (https://tex.stackexchange.com/questions/6238/get-the-title-instead-of-the-number-of-a-referenced-chapter-section). This additionally has the benefit that hyperref creates links. Additionally, the chapters or sections can also be referenced with other commands like \autoref from the hyperref package, but that will result in "chapter 1" or something else and not give the name. Possibly a combination of both is sensible. – clel Jul 14 '21 at 14:37
0

Since I managed to come up with an initial working approach, I wanted to share the result (which likely can be further extended and improved):

\documentclass{book}
\usepackage[utf8]{inputenc}

\usepackage{tikz} \usetikzlibrary{positioning,matrix,fit,arrows.meta}

\usepackage{adjustbox}

% Use a sans serif font \usepackage{helvet} \renewcommand{\familydefault}{\sfdefault}

% To add the list of figures etc. to the table of contents \usepackage{tocbibind}

% To have clickable links for TOC, references etc. \usepackage{hyperref} \hypersetup{colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue}

\usepackage{nameref}

\begin{document} \frontmatter \tableofcontents \listoffigures

\mainmatter \chapter{Introduction} \label{chap:introduction}

Test...

\section{Test} Test...

\section{Structure} Graphic of structure

\begin{figure}[h] \centering \begin{adjustbox}{max width=\textwidth} \begin{tikzpicture} \pgfdeclarelayer{background} % Declare a background layer \pgfdeclarelayer{chapter_background} % Declare a layer for the chapter backgrounds \pgfsetlayers{background,chapter_background,main} % Set the order of the layers (main is the standard layer)

        \tikzstyle{part_name} = [rectangle, align=left, text width=2.5cm]
        \tikzstyle{part} = [matrix, rectangle, inner sep=0.3cm, node distance=0.05, align=left, fill=black!05]
        \tikzstyle{part_background} = [rectangle, inner sep=0.2cm, node distance=0.05, align=left, fill=black!05]
        \tikzstyle{chapter} = [rectangle, rounded corners, inner sep=0.05cm, node distance=0.65cm and 0cm, align=center, text width=6cm, draw=black!70, fill=black!20]
        \tikzstyle{chapter_text} = [node distance=0.65cm and 0cm, align=center, text width=6cm]
        \tikzstyle{chapter_number} = [circle, inner sep=0, minimum width=0.8cm, node distance=0.65cm and 0cm, draw, fill=white]
        \tikzstyle{arrow} = [ultra thick, -Triangle]

        \newcommand{\drawchapter}[5]{
            \node[chapter_number#1] (#2) {#4};
            \node[chapter_text, right=of #2] (tx) {#5};
            \begin{pgfonlayer}{chapter_background}    % Select the chapter background layer
                \node[chapter, fit=(#2)(tx), draw] (#3) {};
            \end{pgfonlayer}
        }

        \newcommand{\drawpartbox}[2]{
            \begin{pgfonlayer}{background}    % Select the background layer
                \node[part_background, fit=#1] (#2) {};
            \end{pgfonlayer}
        }

        \drawchapter{}{n1}{c1}{\ref{chap:introduction}}{\nameref{chap:introduction}}
        \node[part_name, left=of n1] (part_intro) {Intro};
        \drawchapter{, below=of n1}{n2}{c2}{\ref{chap:next}}{\nameref{chap:next}}
        \drawchapter{, below=of n2}{n3}{c3}{\ref{chap:another}}{\nameref{chap:another}}
        \drawpartbox{(part_intro)(c1)(c2)(c3)}{p1}

        \drawchapter{, below=of n3}{n4}{c4}{...}{...}
        \node[part_name, left=of n4] (part_middle) {...};
        \drawchapter{, below=of n4}{n5}{c5}{...}{...}
        \drawpartbox{(part_middle)(c4)(c5)}{p2}

        \drawchapter{, below=of n5}{n6}{c6}{\ref{chap:conclusion_and_outlook}}{\nameref{chap:conclusion_and_outlook}}
        \node[part_name, left=of n6] (part_end) {...};
        \drawpartbox{(part_end)(c6)}{p3}

        \draw[arrow] (c1) -- (c2);
        \draw[arrow] (c2) -- (c3);
        \draw[arrow] (c3) -- (c4);
        \draw[arrow] (c4) -- (c5);
        \draw[arrow] (c5) -- (c6);

    \end{tikzpicture}
\end{adjustbox}
\caption{Structure of the document}
\label{fig:structure}

\end{figure}

\chapter{Next chapter} \label{chap:next} Test...

\chapter{Another chapter} \label{chap:another} Test...

\chapter{Conclusion and Outlook} \label{chap:conclusion_and_outlook}

\end{document}

The result looks like this: result

clel
  • 325