10

I want to present an "itemize" list as a tree. I.e, the current list is:

Root

  • Child 1
  • Child 2
  • Child 3

And I want it to look something like this (but with continuous lines):

Root

|

|-- Child 1

|-- Child 2

|-- Child 3

I know that there are packages for creating trees in pictures, but I want to keep it a simple list inside the text, just change its appearance. Is this possible?

  • I don't think this is a duplicate because it asks how to create a tree from input formatted in a particular way. That's not the same as asking simply how to make the tree and it is very possible that alternative answers might be provided here. For example, suppose somebody has code for turning a list into a forest tree or tikz-qtree tree or whatever. That would not make a good answer to the other question. Even if the answers were identical, moreover, the *questions* are not duplicates. – cfr Dec 14 '15 at 23:37
  • @cfr Yes, I thought so too initially but voted to close anyway. But I've voted to reopen. – Alan Munn Dec 14 '15 at 23:50

3 Answers3

10

The dirtree package is ideally suited for this, and the input is quite simple: each line consists of a . prefix, the level number, the text of the item and a final ..

.<level> Text.

e.g.

\documentclass{article}
\usepackage{dirtree}
\begin{document}
\dirtree{% This % is required
.1 Root. 
.2 First Level.
.2 First level.
.3 Second level.
.3 Second level.
.2 First level.
}
\end{document}

output of code

Alan Munn
  • 218,180
  • Odd. If I TeX your code as-is, the word 'Root' is well off to the left of the vertical line for 'First Level'. Using MacTeX'15. – sgmoye Dec 14 '15 at 15:07
  • @sgmoye This image is the result of MacTeX '15 also. – Alan Munn Dec 14 '15 at 15:11
  • Oops. Had an old version of dirtree.sty hidden away in ~/Library/texmf/tex/latex. Deleted it and everything is now as it should be. Sorry for the noise. – sgmoye Dec 14 '15 at 15:18
  • I don't see why this is a duplicate - at least of the question it has been marked as duplicating. This question asks how to create the tree from input formatted in a particular way. A good answer to this question might be a good answer to that one, but it might not be and, even if it was, that doesn't make the questions duplicates. – cfr Dec 14 '15 at 23:39
7
\documentclass[border=5pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
 for tree={
font=\sffamily,
grow'=0,
child anchor=west,
parent anchor=south,
anchor=west,
calign=first,
edge path={
  \noexpand\path [draw, \forestoption{edge}]
  (!u.south west) +(7.5pt,0) |- node[fill,inner sep=1.25pt] {} (.child anchor)\forestoption{edge label};
},
before typesetting nodes={
  if n=1
    {insert before={[,phantom]}}
    {}
},
fit=band,
before computing xy={l=15pt},
}
[Corporate Operations
[Trade Finance
[Import LCs
[Issuance of Import LCs
[Pre-Advice of Import LCs]
 [Pre-Advice to Issue/List of Pre-Advised LCs]
[Issue of Sight Payment LCs]
[Issue of Usance LCs]
[Issue of Negotiation LCs]
[Issue of Mixed Payment LCs]
[Issue of Stand By LCs]
[Issue internet LCs]
]
]
]
]
\end{forest}
\end{document}

enter image description here

murugan
  • 1,669
2

I originally posted this solution answering a different question. Since that question referenced this one and my solution is really an answer to this one, I post it here, too.


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

output from the code above

The 5 in \newlist{treelist}{itemize}{5} sets the maximum list depth. If you need more than five levels, just increase this number. If you want to further customize the appearance of these lists, you should have a look at the documentations of enumitem and TikZ.

schtandard
  • 14,892