5

I found this nice answer regarding grouping of enumerated list. But it does not work for lists with different width. For instance

\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 wide wide wide\tikzmark{bottom 1}
\item Item 3\tikzmark{top 2}
\item Item 4
\item Item wide wide wide
\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} 

gives

enter image description here

How can I fix this?

Maryà
  • 4,830
  • It might not be a good solution at the first glance, but did you try to add some extra space to shorter items with \hspace? – Majid Abdolshah Apr 02 '19 at 06:44
  • @MajidAbdolshah It will certainly make ugly braces. It is very hard to make the braces absolutely vertical. –  Apr 02 '19 at 07:05

1 Answers1

6

You can keep track of which bullet is the longest and set all y-coordinates to that.

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

\VerticalBrace[ultra thick, blue]{top 1 -| bottom 1}{bottom 1}{The first two items}
\VerticalBrace[ultra thick, blue]{top 2 -| longest 2}{bottom 2 -| longest 2}{The last four items}

enter image description here

StefanH
  • 13,823