1

I am trying to be able to color math that I am using within an itemize environment. Below is my MWE.

\documentclass{article}

\usepackage{xcolor}

\begin{document}
\begin{itemize}
\item
    \color{red}
    \[
        y=x^2
    \]
    \color{black}
\item
    Blah blah blah.
\end{itemize}
\end{document}

which produces:

enter image description here

If I remove the \color commands, I get:

enter image description here

So for whatever reason, there is additional space between the bullets when I do the color stuff. I have tried using \bgroup and \egroup rather than changing the color back with \color{black}, and did not have luck getting rid of that extra space. Does anyone know how to fix this?

EDIT: My original example out some things in the sake of being minimal. The code and image below are more representative of the usage I am looking for. In particular, I would strongly prefer to not have to set up colors both outside of and inside of the math mode, as that seems rather clunky to fix a spacing issue.

EDIT 2: To clarify, the problem that remains is that the spacing after the equation is larger than it would be without the color stuff.

\documentclass{article}

\usepackage{xcolor}

\begin{document}
\begin{itemize}
\item
    A few things I would like to say.
    \color{red}
    Some text here to say some things about the equation.
    \[
        y=x^2
    \]
    \color{black}
\item
    Blah blah blah.
\end{itemize}
\end{document}

enter image description here

4
  • 3
    remove the \color{black} and put the red color inside the equation? Oct 31, 2020 at 20:27
  • Thanks for the suggestion, but unfortunately not ideal for my use case. I've added an edit to my question to be more specific. Nov 1, 2020 at 0:24
  • Are you interested in only one color, say red as in the example, for your colored paragraphs?
    – Daniel N
    Nov 21, 2020 at 5:34
  • Yes, I am only looking to use one color in my paragraphs. Nov 21, 2020 at 15:29

2 Answers 2

3
+50

As the documentation grfguide writes:

There is a different type of problem that will occur for all drivers. Due to certain technical difficulties, it is possible that at points where the colour changes, the spacing is affected.

enter image description here

color commands insert whatsits and in certain places this is quite a pain. So if possible try to insert color changes in paragraphs. For your example, e.g. in the next item. You will have to adapt the color of the bullet too:

\documentclass{article}

\usepackage{xcolor}

\begin{document}
\begin{itemize}
\item
    A few things I would like to say.
    
    \color{red}Some text here to say some things about the equation.
    \[
        y=x^2
    \]
\item[\textcolor{black}{\labelitemi}]
    \leavevmode\color{black}Blah blah blah.
\end{itemize}
\end{document}

But grfguide is a bit wrong in one place: the problem doesn't exist for all drivers. With lualatex you could use the luacolor package and there your example would work without problems:

\documentclass{article}

\usepackage{xcolor}
\usepackage{luacolor}
\begin{document}
\begin{itemize}
\item
    A few things I would like to say.
    \color{red}Some text here to say some things about the equation.
    \[
        y=x^2
    \]\color{black}
\item
    Blah blah blah.
\end{itemize}
\end{document}
1
  • The second response was exactly what I was looking for, nice and clean without having to do a bunch of stuff manually everywhere. Thanks! Nov 21, 2020 at 16:02
3

A simple solution with \makebox:

\documentclass{article}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.3pt}
\usepackage{xcolor}

\begin{document}

\begin{itemize}
\item \makebox[\linewidth]{$ \color{red}\displaystyle y=x^2$}
\item Blah blah blah.
\end{itemize}

\end{document}

enter image description here

Edit: to obtain the same result with \[ \], you can load nccmath and use this code:

\item \leavevmode\vspace{-\baselineskip}\useshortskip\[ \color{red}y=x^2 \]
12
  • you probably want \displaystyle Oct 31, 2020 at 20:46
  • That' right. I didn't think of it because it wasn't necessary with this formula. Thanks for reminding me!
    – Bernard
    Oct 31, 2020 at 20:52
  • even here you'll get a higher superscript Oct 31, 2020 at 20:52
  • I didn't know that! I'll change the screenshot.
    – Bernard
    Oct 31, 2020 at 20:58
  • Unfortunately, I am specifically looking for a method that works with \[ ... \] and as far as I can tell with briefly playing around, this does not seem to work. Edit: To elaborate, in my use case, I often have larger equations introduced by text, so an out-of-line equation is preferable. Oct 31, 2020 at 21:55

You must log in to answer this question.

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