7

I have an itemized list:

\begin{itemize}
    \item Lorem
    \item Ipsum
    \item Sit
    \item Dolor
    \item Amet
\end{itemize}

I want to create an accolade on the right side of 'Lorem' and 'Ipsum', and add a bit of text at the point of the accolade. The level of this text should be between the first and the second line. How can I get this done?

example

7
13

A little more generality is needed. The OP's example works nicely because 'Lorem' and 'Ipsum' have about the same width. But if the Ipsum line is longer, then this is the output:

Original output

Taking a cue from Large braces over several items in an itemize with text by the brace, we can write the following:

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}
\newcommand{\ntikzmark}[2]{#2\thinspace\tikz[overlay,remember picture,baseline=(#1.base)]{\node[inner sep=0pt] (#1) {};}}

\newcommand{\makebrace}[3]{%
    \begin{tikzpicture}[overlay, remember picture]
        \draw [decoration={brace,amplitude=0.5em},decorate]
        let \p1=(#1), \p2=(#2) in
        ({max(\x1,\x2)}, {\y1+0.8em}) -- node[right=0.6em] {#3} ({max(\x1,\x2)}, {\y2});
    \end{tikzpicture}
}

\begin{document}

\begin{itemize}
    \item \ntikzmark{L}{Very Long Lorem}
    \item \ntikzmark{O}{Long Ipsum}
    \item \ntikzmark{X}{Sit}
    \item \ntikzmark{Y}{Dolor}
    \item Amet
\end{itemize}
\makebrace{L}{O}{Bla bla bla.}
\makebrace{X}{Y}{More bla bla bla.}

\end{document}

which yields:

Corrected output

And changing 'Lorem' to 'Very Long Lorem' yields:

Alternate corrected output

It occurred to me that you might more than one brace. I altered the code to accommodate that possibility. The output in this case looks like this:

Alternate output

The trick is to find the longest line, and base the drawing of the brace on that. There may be an easier way, and I would like to see it...

#

At the risk of seeming tedious, I have simplified the interface a bit and made possible a formatting option.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,calc}

\newcounter{itemnum}

\newcommand{\nt}[2][0pt]{%
    \stepcounter{itemnum}%
    \if###2##%
    \else
        #2%
        \thinspace
    \fi
    \tikz[overlay,remember picture,baseline=(\theitemnum.base),xshift=#1]\node (\theitemnum){};%
}

\newcommand{\makebrace}[4][0pt]{%
    \begin{tikzpicture}[overlay, remember picture]
        \draw [decoration={brace,amplitude=0.5em},decorate]
        let \p1=(#2), \p2=(#3) in
        ({max(\x1+#1,\x2+#1)}, {\y1+1.75ex}) -- 
            node[right=0.6em] {#4} ({max(\x1+#1,\x2+#1)}, {\y2-0.5ex});
    \end{tikzpicture}%
}

\newenvironment{braceitems}{%
    \begin{enumerate}
}{%
    \end{enumerate}
    \setcounter{itemnum}{0}%
}

\begin{document}

\begin{braceitems}
    \item \nt{Very Long Lorem}
    \item \nt{Long Ipsum}
    \item \nt{Sit}
    \item \nt{Dolor}
    \item \nt{Amet}
\end{braceitems}
\makebrace{1}{2}{Bla bla bla.}
\makebrace{2}{5}{More bla bla bla.}
\makebrace{4}{5}{A note.}

\end{document}

This produces:

New output

which is not exactly what is wanted. So we use the optional argument to move the brace, \makebrace[15pt]{2}{5}{More bla bla bla.} to get this:

Better new output

Explanation: A new counter itemnum keeps track of the items in the list. Use the numbers of the items in \makebrace to determine how the brace is drawn. An optional argument to \makebrace will move the brace.

As it happens, this suggested an interesting solution to a problem in recipe formatting, which is why I seem fixated on the solution.


I have altered the code slightly. I discovered that this, for example, \item \nt{Very Long Lorem\\and more} would produce this:

Two line \item bad outout

Again, probably not what is wanted. I changed the code for \nt to allow for an empty argument, which simple creates an anchor for the drawing of the brace: \item Very Long Lorem\nt{}\\and more, which produces this:

Two line \item with better output

2
  • 1
    Taking a cue from ... Jan 1 '14 at 2:20
  • Had to change the 'correct' answer to this one Jan 1 '14 at 18:47
7

Remarks

Using the almighty TikZ and it decorations.pathreplacing library to place the brace decoration.

Implementation

\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\newcommand{\tikzmark}[2]{\tikz[remember picture,baseline=(#1.base)]{\node[inner sep=0pt] (#1) {#2};}}
\begin{document}
\begin{itemize}
    \item \tikzmark{L}{Lorem}
    \item \tikzmark{I}{Ipsum}
    \item Sit
    \item Dolor
    \item Amet
\end{itemize}
\begin{tikzpicture}[remember picture,overlay]
    \draw[decorate,decoration={brace}] (L.north east) -- node[right] {Bla bla bla} (L.north east |- I.south east);
\end{tikzpicture}
\end{document}

Output

enter image description here

0

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.