[Tex/LaTex] grouping enumerated list

#enumerategroupinglists

I am trying to generate a numbered list with a bracket to the right of the list to group the list items into additional categories. I am trying to get something like:

enter image description here

I have fiddled around with \mbox and \frame, and even thought about using a table, but I would have to re-start the list numbering, and I want to make sure that the alignment is correct.

Is this something that can be done?

Glenn

Best Answer

Yep, this can easily be done with \tikzmark. With this you

  • complete the enumerate list as you normally would
  • mark specfic points with a \tikzmark{<name>}
  • access these \tikzmarks in a \tikzpicture with the [overlay,remember picture] options and draw as desired.

enter image description here

Note:

References:

Code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}

\tikzset{My Node Style/.style={midway, right, xshift=3.0ex, align=left, font=\small, draw=none, thin, text=black}}

\newcommand\VerticalBrace[4][]{%
    % #1 = draw options
    % #2 = top mark
    % #2 = bottom mark
    % #4 = label
\begin{tikzpicture}[overlay,remember picture]
  \draw[decorate,decoration={brace, amplitude=1.5ex}, #1] 
    ([yshift=1ex]#2.north east)  -- ([yshift=-1ex]#3.south east)
        node[My Node Style] {#4};
\end{tikzpicture}
}

\begin{document}
\begin{enumerate}
\item Item 1\tikzmark{top 1}
\item Item 2\tikzmark{bottom 1}
\item Item 3\tikzmark{top 2}
\item Item 4
\item Item 5
\item Item 6\tikzmark{bottom 2}
\end{enumerate}

\VerticalBrace[ultra thick, blue]{top 1}{bottom 1}{The first two items}
\VerticalBrace[ultra thick, blue]{top 2}{bottom 2}{The last four items}
\end{document}
Related Question