TransWikia.com

How can I fix the extra space I am getting when giving color to an equation in an itemize environment?

TeX - LaTeX Asked by Abe Schulte on March 22, 2021

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

2 Answers

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}]
    leavevmodecolor{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}

Correct answer by Ulrike Fischer on March 22, 2021

A simple solution with makebox:

documentclass{article}
usepackage{showframe}
renewcommandShowFrameLinethickness{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 leavevmodevspace{-baselineskip}useshortskip[ color{red}y=x^2 ]

Answered by Bernard on March 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP