6

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?

  • 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 2 at 6:44
  • @MajidAbdolshah It will certainly make ugly braces. It is very hard to make the braces absolutely vertical. – JouleV Apr 2 at 7:05
7

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

  • 1
    Very good answer. – Sebastiano Apr 2 at 7:20
  • Splendid! Gracias! – marya Apr 2 at 7:25

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.