6

I'm currently working on a set of notes and would like to encircle the item numbers in the enumerate environment. This problem largely seems to have been solved by Raphink in the thread Enumerated list with blue circles and number inside it, and their efforts are reproduced in the code below. However, as you can see, there is a slight problem around the vertical interline spacing in the paragraph corresponding to item number 2. It is inconsistent, and I would much prefer the spacing between the first and second lines to resemble the others. How would I go about this? enter image description here

\documentclass{article}

\usepackage{tikz}
\usepackage{lipsum}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{%
            \node[shape=circle,fill=blue!20,draw,inner sep=8pt] (char) {#1};}}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=\protect\circled{\arabic*}]
\item Step one 
\item Step two \lipsum[1]
\item Step three
\end{enumerate}

\end{document}

2 Answers 2

8
\documentclass{article}

\usepackage{tikz}
\usepackage{lipsum}
\newcommand*\circled[1]{\smash{\tikz[baseline=(char.base)]{%
            \node[shape=circle,fill=blue!20,draw,inner sep=8pt] (char) {#1};}}}

\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=\protect\circled{\arabic*},itemsep=5ex]
\item Step one 
\item Step two \lipsum[1]
\item Step three
\end{enumerate}

\end{document}

enter image description here

3
  • That was very quick! Thank you.
    – wrb98
    Feb 5, 2023 at 19:20
  • @wrb98 It might be a good idea to add topsep=... along with itemsep=5ex, otherwise the text above and below the list will be very close to the first and last circles.
    – Vincent
    Feb 5, 2023 at 19:22
  • Thanks for the advice. Just as an extra point: if I later decide to ditch the circles for, say, a rounded rectangle made with \tcbox (which throws up the same spacing issues), would the \smash argument still work? If so, where should I place it?
    – wrb98
    Feb 5, 2023 at 19:50
4

You want to smash the bottom of the picture, but also add empty lines depending on how many lines the item occupies.

Here I add one empty line if the item has just one line.

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}
\usepackage{enumitem}

\usepackage{lipsum}

\newcommand*\circled[1]{%
  \smash[b]{%
    \begin{tikzpicture}[baseline=(char.base)]
    \node[shape=circle,fill=blue!20,draw,inner sep=8pt] (char) {#1};
    \end{tikzpicture}%
  }%
}

\ExplSyntaxOn
\NewDocumentEnvironment{circledenum}{O{}+b}
 {
  \wrb_circledenum:nn { #1 } { #2 }
 }
 {}

\seq_new:N \l__wrb_circledenum_items_seq

\cs_new_protected:Nn \wrb_circledenum:nn
 {
  \seq_set_split:Nnn \l__wrb_circledenum_items_seq { \item } { #2 }
  % discard the first (empty) item
  \seq_pop_left:NN \l__wrb_circledenum_items_seq \l_tmpa_tl
  \begin{enumerate}[label=\protect\circled{\arabic*},#1]
  \seq_map_inline:Nn \l__wrb_circledenum_items_seq
   {
    \item ##1 \par
    \int_compare:nT { \prevgraf < 3 }
     {\vspace{ \int_eval:n { 2-\prevgraf } \baselineskip }}
   }
  \end{enumerate}
 }

\ExplSyntaxOff

\begin{document}

\begin{circledenum}
\item Step one
\item Another short one
\item Step two \lipsum[1][1-2]
\item Step three \lipsum[1][1-3]
\item Step four \lipsum[1][1-5]
\end{circledenum}

\end{document}

The trick is to make TeX know how many lines the previous paragraph consists of by issuing \par so that the number is stored in \prevgraf.

enter image description here

Caveat. You can't nest other lists, but I don't think it's a problem for this application.

You must log in to answer this question.

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