2

I'm trying to create a legal-like list that has numbering like 1., 1.1., etc., except where the top level numbers are bolded, and the rest aren't.

Currently I have:

\documentclass{article}
\usepackage{enumitem}

\newlist{questions}{enumerate}{2}
\setlist[questions,1]{label=\textbf{\arabic*.}}
\setlist[questions,2]{label*=\arabic*.}

\begin{document}

\begin{questions}

    \item Top level (number should be bolded)

    \begin{questions}

        \item Second level (whole number should be in normal font)

    \end{questions}

\end{questions}

\end{document}

which gives me:

tex output

So the second level has correctly appended a normal-font number onto the label from its parent, but it also kept the bolding in the parent's number (which I don't want).

I tried adding the font=\normalfont option to the second questions level, but that didn't have any effect.

Is there a good way to remove formatting from the parent label before appending to it?

1

Simply use the font key for the first level:

\documentclass{article}
\usepackage{enumitem}

\newlist{questions}{enumerate}{2}
\setlist[questions, 1]{label=\arabic*., font=\bfseries}
\setlist[questions, 2]{label*=\arabic*.}

\begin{document}

\begin{questions}

    \item Top level (number should be bolded)

    \begin{questions}

        \item Second level (whole number is in normal font)

    \end{questions}

\end{questions}

\end{document} 

enter image description here

0

I would declare a formatting command and then change that formatting command before any deeper levels are reached.

enter image description here

\documentclass{article}

\usepackage{enumitem}

\DeclareRobustCommand{\questionformat}{\textbf}

\newlist{questions}{enumerate}{2}
\setlist[questions,1]{label=\questionformat{\arabic*.}}
\setlist[questions,2]{label*=\arabic*.,before={\DeclareRobustCommand{\questionformat}{}}}

\begin{document}

\begin{questions}
  \item Top level (number should be bolded)
  \begin{questions}
    \item Second level (whole number should be in normal font)
    \item Second level (whole number should be in normal font)
  \end{questions}

  \item Top level (number should be bolded)
  \begin{questions}
    \item Second level (whole number should be in normal font)
    \item Second level (whole number should be in normal font)
  \end{questions}
\end{questions}

\end{document}

Since the hierarchy stores expanded versions of higher levels, \DeclareRobustCommand avoids expansions and therefore preserves the formatting command (making it changeable). However, don't use a \reference to one of the nested elements...

  • Ah, that's really cool. Kind of overkill for just the bold/non-bold application, but I'll definitely keep it in mind for more complex label formatting. Thanks! – Niayesh Isky Mar 16 '18 at 21:24

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.