2

In enumitem, suppose that I do style=multiline and use custom labels and then set font to be some color specification. Then the custom labels appear below the baseline. As you see, it does not happen with some other font specification like font=\scshape. It looks like a bug to me, but perhaps some TeX guru in here can make sense of this behavior:

\documentclass{article}

\usepackage{color,enumitem}

\begin{document}
    
    \setlist[itemize]{style=multiline,labelwidth=2cm}
    
    \begin{itemize}
        \item[First] Hello
        \item[Second] World
        \item[Third\\Fourth] Again
    \end{itemize}
    
    \setlist[itemize]{font=\scshape,style=multiline,labelwidth=2cm}
    
    \begin{itemize}
        \item[First] Hello
        \item[Second] World
        \item[Third\\Fourth] Again
    \end{itemize}
    
    \setlist[itemize]{font=\color{red},style=multiline,labelwidth=2cm}
    
    \begin{itemize}
        \item[First] Hello
        \item[Second] World
        \item[Third\\Fourth] Again
    \end{itemize}
    
\end{document}

enter image description here

3
  • Hm, try \setlist[itemize]{ font=\color{red}\smash,style=multiline,labelwidth=2cm} (observe \smash)
    – Zarko
    Commented Sep 7 at 16:17
  • @Zarko This works well, unless you actually do have a multi-line label. Try \label[Third\\Fourth]. It crashes painfully. (See my updated question.)
    – Gaussler
    Commented Sep 7 at 16:19
  • 2
    font=\leavevmode\color{red}. Commented Sep 7 at 16:26

2 Answers 2

3

\color{red} sets a whatsit in vertical mode, which will produce a box.

Hack: add \mbox{}.

\documentclass{article}

\usepackage{color,enumitem}

\begin{document}

\section*{No color}

\begin{itemize}[style=multiline,labelwidth=2cm]
\item[First] Hello
\item[Second] World
\item[Third\\Fourth] Again
\end{itemize}

\section*{Colored}

\begin{itemize}[font=\mbox{}\color{red},style=multiline,labelwidth=2cm]
\item[First] Hello
\item[Second] World
\item[Third\\Fourth] Again
\end{itemize}

\end{document}

output

Your task is now to push the labels in some sensible position.

2
  • Nice solution. @UlrikeFischer suggested \leavevmode instead, which I guess works equally well, but is slightly cleaner IMO.
    – Gaussler
    Commented Sep 7 at 16:58
  • 1
    @Gaussler Whatever you prefer: \mbox is in the LaTeX manual, \leavevmode isn't.
    – egreg
    Commented Sep 7 at 17:07
3

If you compile with luatex, you can also try the luacolor package

\usepackage{luacolor}

It doesn't insert a color whatsits.

Example:

\documentclass{article}

\usepackage{color,enumitem}
\usepackage{luacolor}

\begin{document}

    \section*{No color}

    \setlist[itemize]{style=multiline,labelwidth=2cm}

    \begin{itemize}
        \item[First] Hello
        \item[Second] World
        \item[Third\\Fourth] Again
    \end{itemize}

    \section*{Small caps}

    \setlist[itemize]{font=\scshape,style=multiline,labelwidth=2cm}

    \begin{itemize}
        \item[First] Hello
        \item[Second] World
        \item[Third\\Fourth] Again
    \end{itemize}

    \section*{Colored}

    \setlist[itemize]{font=\color{red},style=multiline,labelwidth=2cm}

    \begin{itemize}
        \item[First] Hello
        \item[Second] World
        \item[Third\\Fourth] Again
    \end{itemize}

\end{document}

Example

You must log in to answer this question.

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