4

I would like to have a list environment, which displays a vertical line along each nested list, but not for the outermost one, as in the following example:enter image description here

How can this be achieved in LaTeX?

Edit: Here is what I have tried so far:

    \documentclass[english]{article}
    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    \usepackage[latin9]{inputenc}
    \usepackage[a4paper]{geometry}
    \geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=3cm,rmargin=2cm}
    \setlength{\parskip}{\medskipamount}
    \setlength{\parindent}{0pt}

    \makeatletter
    \usepackage{tcolorbox}
    \tcbuselibrary{breakable,skins}
    \newenvironment{mylist}
    {
        \vspace{5pt}
        \begin{tcolorbox}[blanker,left=3mm,right=3mm,top=2mm,bottom=2mm,borderline west={1pt}{2pt}{gray!25!white}]
    }
    {
        \end{tcolorbox}
    }

    \usepackage{babel}
    \begin{document}
    This is normal text. This is normal text. This is normal text.

    This is normal text. This is normal text. This is normal text.
    \begin{mylist}
        First element of the outermost list
        \begin{mylist}
            First element of a nested list\\
            Second element of a nested list
            \begin{mylist}
                First element of a nested list\\
                Second element of a nested list
            \end{mylist}
        \end{mylist}
        Second element of the outermost list
        \begin{mylist}
            First element of a nested list\\
            Second element of a nested list
        \end{mylist}
    \end{mylist}

    \end{document}
3
  • 1
    Can you show us what you have tried so far? Welcome to TeX.SE!
    – Mensch
    Oct 3, 2015 at 20:06
  • So far, I have tried using both the "leftbar" environment from the "framed"-package and the "tcolorbox" package, which draws vertical lines when using the "borderline west"-option of a box environment. Apart from details it looked as I wanted, but the problem is, that I do not know how to prevent the line along the outermost list from beeing drawn.
    – emilG
    Oct 3, 2015 at 20:56
  • Ok, I have added it :-).
    – emilG
    Oct 3, 2015 at 22:30

2 Answers 2

5

Here is a solution with tikzmark:

enter image description here

\documentclass{article}
\usepackage{enumitem,tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}

\begin{itemize}[label={}]
    \item First element of the outermost list
    \begin{itemize}[label={}]
        \item \tikzmark{s1}First element of a nested list
        \item Second element of a nested list
        \begin{itemize}[label={}]
            \item \tikzmark{s2}First element of a nested list
            \item \tikzmark{e1}Second element of a nested list
         \end{itemize} 
     \end{itemize} 
    \item Second element of the outermost list
    \begin{itemize}[label={}]
        \item \tikzmark{s3}First element of a nested list
        \item \tikzmark{e2}Second element of a nested list
    \end{itemize}
\end{itemize}

\begin{tikzpicture}[overlay,remember picture,xshift=-1.6em,line width=.7pt,draw=gray!50]
\path (pic cs:s1)|-coordinate(E)(pic cs:e1);
\draw ($(pic cs:s1)+(0,\ht\strutbox)$)--(E) 
($(pic cs:s2)+(0,\ht\strutbox)$)--(pic cs:e1) 
($(pic cs:s3)+(0,\ht\strutbox)$)--(pic cs:e2);
\end{tikzpicture}

\end{document}

This can be made automatic, but I don't have much time for now.

3
  • Thank you a lot, that looks great. Of course, I would be even more grateful if you could tell me how to automate this, when you have more time.
    – emilG
    Oct 3, 2015 at 22:31
  • Can you give a description of what each command is performing for the less tikz inclined? (The markers seem to set the beginning and ending placements for the lines, but the bottom portion is a bit more evasive to me.)
    – kando
    Jun 21, 2017 at 17:27
  • I'm using labels - I want the line to follow directly under the label. How would I perform this? Also, what if I cross pages?
    – kando
    Jun 21, 2017 at 17:48
2

If the option list for mylist contains a every box/.style definition, this setting is valid for every embedded tcolorbox but not for the outermost one (there, the global and empty every box is used).

So, the setting

every box/.style={borderline west={1pt}{2pt}{gray!25!white}},

is only valid for the embedded boxes / lists.

I also added a breakable option assuming that you want this. Breakability will only work the the outermost list (the inner lists are not breabable).

The full code is:

\documentclass[english]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2cm,bmargin=2cm,lmargin=3cm,rmargin=2cm}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{babel}

\usepackage{tcolorbox}
\tcbuselibrary{breakable,skins}

\newtcolorbox{mylist}{blanker,
  breakable,
  left=3mm,right=3mm,top=2mm,bottom=2mm,
  before skip=5pt,after skip=5pt,
  every box/.style={borderline west={1pt}{2pt}{gray!25!white}},
}

\begin{document}
This is normal text. This is normal text. This is normal text.

This is normal text. This is normal text. This is normal text.
\begin{mylist}
    First element of the outermost list
    \begin{mylist}
        First element of a nested list\\
        Second element of a nested list
        \begin{mylist}
            First element of a nested list\\
            Second element of a nested list
        \end{mylist}
    \end{mylist}
    Second element of the outermost list
    \begin{mylist}
        First element of a nested list\\
        Second element of a nested list
    \end{mylist}
\end{mylist}

\end{document}

enter image description here

1
  • Thanks a lot, I did not know every box/.style, this is a quite useful option indeed.
    – emilG
    Oct 6, 2015 at 0:13

You must log in to answer this question.

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