1

When trying to make the hirachical structure of an itemize environment more "visible" I found this nice answer from @schtandard to the original question Make itemize look like dirtree:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{tikz}

\makeatletter
    \newlist{treelist}{itemize}{5}
    \setlist[treelist]{label=\treelist@label}

    \tikzset{treelist line/.style={thick, line cap=round, rounded corners}}
    \def\treelist@label{%
        \begin{tikzpicture}[remember picture, baseline={([yshift=-.6ex] treelist-bullet-\the\enit@depth.center)}]
            \draw [treelist line] (0, 0) -- node (treelist-bullet-\the\enit@depth) {} ++(.5em, 0);
        \end{tikzpicture}%
        \ifnum\enit@depth>1
            \tikz[remember picture, overlay] \draw [treelist line] (treelist-bullet-\the\numexpr\enit@depth-1\relax.center) |- (treelist-bullet-\the\enit@depth.center);%
        \fi
    }
\makeatother

\begin{document}

\begin{treelist}
    \item
    Gas ideal (partículas idénticas que no interactúan, i.e.~la energía no tiene términos cruzados).
    \begin{treelist}
        \item
        Fermiones.
        \begin{treelist}
            \item
            Límite de gas no degenerado.
            Corresponde a temperaturas muy altas y densidades muy bajas, el resultado es el gas ideal clásico.

            \item
            Límite de gas degenerado.
            Es lo opuesto, temperaturas bajas y densidades altas.
            Aparece Pauli con su principio de exclusión. 
            \begin{treelist}
            \item
            Enanas blancas. 

            \end{treelist}

        \end{treelist}

        \item
        Bosones.
        \begin{treelist}
            \item
            Límite de gas no degenerado.
            Corresponde a temperaturas muy altas y densidades muy bajas, el resultado es el gas ideal clásico.
            \begin{treelist}
                \item
                Gas de fotones.

                \item
                Gas de fonones.

            \end{treelist}

            \item
            Límite de gas degenerado.
            Básicamente es un condensado de Bose-Einstein.
            \begin{treelist}
                \item
                Superfluidos.

                \item
                Superconductores.

            \end{treelist}

        \end{treelist}

    \end{treelist}

    \item
    Otros temas que no sean gas ideal. No vimos nada, creo.

\end{treelist}

\end{document}

Unfortunately I've got a lot of items to show and the connecting lines get lost when a page break occures. I found another post from @Schrödinger's cat showing how to get an arrow spanning between annotations over multiple pages:

\documentclass[10pt,oneside]{scrbook}
\usepackage{lipsum}
\usepackage[left=32.5mm, right=22.5mm, top=25mm, bottom=20mm, marginparsep=3mm]{geometry}
\usepackage{tikzpagenodes}
\usepackage{eso-pic}
\usetikzlibrary{tikzmark}
\usepackage{marginnote}
\renewcommand*{\marginfont}{\footnotesize\itshape}
\makeatletter
\newcommand\PageOfTikzmark[1]{%
\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname}
\makeatother
\newcommand{\ConnectTikZmarknodes}[3][]{\AddToShipoutPictureFG{%
\begin{tikzpicture}[remember picture, overlay, shorten >=1.5mm, 
    shorten <=1.5mm,#1]
\iftikzmark{#2}{\edef\pageA{\PageOfTikzmark{#2}}}{\edef\pageA{-1}}% 
\iftikzmark{#3}{\edef\pageB{\PageOfTikzmark{#3}}}{\edef\pageB{-1}}% 
\iftikzmarkoncurrentpage{#2}
\edef\myflag{1}%
\else
\edef\myflag{0}%
\fi 
\iftikzmarkoncurrentpage{#3}
\edef\myflag{\the\numexpr\myflag+2}%
\fi 
\ifcase\myflag
\or
 \draw[-] ([xshift=10pt]#2.south west)
     to ([xshift=10pt]#2.south west|-current page text area.south);
\or
 \draw[->] ([xshift=10pt]#3.north west|-current page text area.north) 
    to ([xshift=10pt]#3.north west);  
\or
 \draw[->] ([xshift=10pt]#2.south west)
     to ([xshift=10pt]#3.north west);
\fi
\ifnum\value{page}>\pageA
\ifnum\value{page}<\pageB
 \draw ([xshift=20pt]current page text area.north east) to
 ([xshift=20pt]current page text area.south east);
\fi
\fi
\end{tikzpicture}}}
\begin{document}

\marginnote{\tikzmarknode{a}{Thermoplast}}
\lipsum[1]
\marginnote{\tikzmarknode{b}{teilkristallin}}
\ConnectTikZmarknodes{a}{b}
\lipsum[1]
\marginnote{\tikzmarknode{c}{aliphatisch}} 
\ConnectTikZmarknodes{b}{c}
\lipsum[1-7]    % works fine
\marginnote{\tikzmarknode{d}{aliphatisch}} 
\ConnectTikZmarknodes{c}{d}
\ConnectTikZmarknodes{d}{e}
\lipsum[1-23]    
\marginnote{\tikzmarknode{e}{unproblematisch}} 
\end{document}

So my question is: is it possible to combine these two solutions? How could I make the connections of a treelist spanning over page breaks?

Could anybody help? Thanks in advance for your efforts.


EDIT: @Schrödinger's cat provided a good solution. But I missed to point out that there may be multiple connections crossing the page break. As can be seen from the following picture there should be a connection downwards from "Ferminons" to "Non-degenerate Fermi gas" and "Quasi-degenerate Fermi gas". Multiple

The corresponding code is:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,tikzmark}
\makeatletter
\newcommand\PageOfTikzmark[1]{%
\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname}
    \newlist{treelist}{itemize}{5}
    \setlist[treelist]{label=\treelist@label}

    \tikzset{treelist line/.style={thick, line cap=round, rounded corners},
    treelist cutoff/.initial=3\baselineskip}
    \def\treelist@label{%
        \tikzmarknode{treelist-\the\enit@depth}{\textbullet}%
        \ifnum\enit@depth>1\relax
         \iftikzmark{treelist-\the\numexpr\enit@depth-1}{%
          \begin{tikzpicture}[remember picture, overlay]
          \draw let \p1=(treelist-\the\enit@depth),
           \p2=(treelist-\the\numexpr\enit@depth-1)
           in
           \ifdim\y2>\y1
            (treelist-\the\enit@depth) -|
            (treelist-\the\numexpr\enit@depth-1\relax);
           \else
            (treelist-\the\enit@depth) -|
            (treelist-\the\numexpr\enit@depth-1\relax|-current page text area.north);
           \fi;
          \draw let \p1=($(treelist-\the\enit@depth)-(current page text area.south)$)
           in   
           \ifdim\y1<\pgfkeysvalueof{/tikz/treelist cutoff}
            (treelist-\the\enit@depth) -|
            (treelist-\the\numexpr\enit@depth-1\relax|-current page text area.south);
           \fi;
          \end{tikzpicture}%
         }{%
         }%
        \fi
    }
\makeatother
\begin{document}

\begin{treelist}
    \item Ideal gas of noninteracting particles.
    \begin{treelist}
        \item
        Fermions.
        \begin{treelist}
            \item Non--degenerate Fermi gas. The Pauli principle plays no major
            role.

            \item Quasi--degenerate Fermi gas. The Pauli principle is important
            and dictates the occupation number.
            \begin{treelist}
            \item
            Whatever.

            \end{treelist}

        \end{treelist}

        \item
        Bosons.
        \begin{treelist}
            \item Non--degenerate Bose gas.
            \begin{treelist}
                \item Photons.

                \item Phonons.

            \end{treelist}

            \item Quasi--degenerate Bose gas.
             Bose--Einstein condensation.
            \begin{treelist}
                \item
                Superfluids.

                \item
                Superconductors.

            \end{treelist}

        \end{treelist}

    \end{treelist}

    \item Ti\emph{k}Zlings

    \begin{treelist}
     \item Anteater
     \item Bear
     \item Bee
     \item Cat  
     \item Coati  
     \item Hippo 
     \item Koala
     \item Marmot 
     \item Mole
     \item Mouse  
     \item Panda 
     \item Penguin  
     \item Pig 
     \item Rhino 
     \item Sloth  
     \item Squirrel 
     \item Snowman 
    \end{treelist}

    \item Ideal gas of noninteracting particles.
    \begin{treelist}
        \item
        Fermions.
        \begin{treelist}
            \item Non--degenerate Fermi gas. The Pauli principle plays no major
            role.

            \item Quasi--degenerate Fermi gas. The Pauli principle is important
            and dictates the occupation number.
            \begin{treelist}
                \item
                Whatever.

            \end{treelist}

        \end{treelist}

        \item
        Bosons.
        \begin{treelist}
            \item Non--degenerate Bose gas.
            \begin{treelist}
                \item Photons.

                \item Phonons.

            \end{treelist}

            \item Quasi--degenerate Bose gas.
            Bose--Einstein condensation.
            \begin{treelist}
                \item
                Superfluids.

                \item
                Superconductors.

            \end{treelist}

        \end{treelist}

    \end{treelist}

\end{treelist}

\end{document}

As far as I understand a node is put around each list label. By checking if there is a node with a lower depth value a connection could be established. Depending on the y-coordinate of the node a line is drawn to the node with the lower depth value or to the "current page text area.south"/"current page text area.north"-nodes. But this seems to cause some problems with the nested treelists as shown above.

1
0

This is an ad hoc approach. The difficult thing is to find out if an item has a child on the next page. Here this check is done by computing the distance to the lower end of the text area. The check may not always be accurate. You can change the cutoff with

\tikzset{treelist cutoff=<dimension>}

locally if that happens.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{enumitem}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc,tikzmark}
\makeatletter
\newcommand\PageOfTikzmark[1]{%
\csname save@pg@\csname save@pt@\tikzmark@pp@name{#1}\endcsname\endcsname}
    \newlist{treelist}{itemize}{5}
    \setlist[treelist]{label=\treelist@label}

    \tikzset{treelist line/.style={thick, line cap=round, rounded corners},
    treelist cutoff/.initial=1.5\baselineskip}
    \def\treelist@label{%
        \tikzmarknode{treelist-\the\enit@depth}{\textbullet}%
        \ifnum\enit@depth>1\relax
         \iftikzmark{treelist-\the\numexpr\enit@depth-1}{%
          \begin{tikzpicture}[remember picture, overlay]
          \draw let \p1=(treelist-\the\enit@depth),
           \p2=(treelist-\the\numexpr\enit@depth-1)
           in
           \ifdim\y2>\y1
            (treelist-\the\enit@depth) -|
            (treelist-\the\numexpr\enit@depth-1\relax);
           \else
            (treelist-\the\enit@depth) -|
            (treelist-\the\numexpr\enit@depth-1\relax|-current page text area.north);
           \fi;
          \draw let \p1=($(treelist-\the\enit@depth)-(current page text area.south)$)
           in   
           \ifdim\y1<\pgfkeysvalueof{/tikz/treelist cutoff}
            (treelist-\the\enit@depth) -|
            (treelist-\the\numexpr\enit@depth-1\relax|-current page text area.south);
           \fi;
          \end{tikzpicture}%
         }{%
         }%
        \fi
    }
\makeatother
\begin{document}

\begin{treelist}
    \item Ideal gas of noninteracting particles.
    \begin{treelist}
        \item
        Fermions.
        \begin{treelist}
            \item Non--degenerate Fermi gas. The Pauli principle plays no major
            role.

            \item Quasi--degenerate Fermi gas. The Pauli principle is important
            and dictates the occupation number.
            \begin{treelist}
            \item
            Whatever.

            \end{treelist}

        \end{treelist}

        \item
        Bosons.
        \begin{treelist}
            \item Non--degenerate Bose gas.
            \begin{treelist}
                \item Photons.

                \item Phonons.

            \end{treelist}

            \item Quasi--degenerate Bose gas.
             Bose--Einstein condensation.
            \begin{treelist}
                \item
                Superfluids.

                \item
                Superconductors.

            \end{treelist}

        \end{treelist}

    \end{treelist}

    \item Ti\emph{k}Zlings

    \begin{treelist}
     \item Anteater
     \item Bear
     \item Bee
     \item Cat  
     \item Coati  
     \item Hippo 
     \item Koala
     \item Marmot 
     \item Mole
     \item Mouse  
     \item Panda 
     \item Penguin  
     \item Pig 
     \item Rhino 
     \item Sloth  
     \item Squirrel 
     \item Snowman 
    \end{treelist}

    \item Ti\emph{k}Zlings

    \begin{treelist}
     \item Anteater
     \item Bear
     \item Bee
     \item Cat  
     \item Coati  
     \item Hippo 
     \item Koala
     \item Marmot 
     \item Mole
     \item Mouse  
     \item Panda 
     \item Penguin  
     \item Pig 
     \item Rhino 
     \item Sloth  
     \item Squirrel 
     \item Snowman 
    \end{treelist}

\end{treelist}

\end{document}

enter image description here

Other things are much easier to customize. It is easy to change the bullets to something else.

9
  • Amazing. Please allow me a further enquiry: when there are two items on different list levels having children on the next page, there is only on line downwards on the first page. However, there are two lines upwards on the second page. I changed the value for the cutoff in a wide range but this seem to affect only the higher level item. Apr 28 '20 at 10:11
  • 1
    @HeinoToller I do not understand this comment.
    – user194703
    Apr 28 '20 at 14:13
  • 1
    @HeinoToller OK, well, I did not know that this was required. Please add the code that produced this so that I do not have to do that myself.
    – user194703
    Apr 28 '20 at 19:01
  • 1
    @HeinoToller No, sorry. I tried to be nice and answer your question but I am not going to follow external links.
    – user194703
    Apr 28 '20 at 19:19
  • 1
    @HeinoToller One can add the vertical bar but what if this is the last item at this level on the bottom of the page? Checking whether or not this is the case is major effort because we would have to store this information in the aux file.
    – user194703
    Apr 29 '20 at 4:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.