[Tex/LaTex] Height of colorbox


I'm trying to "highlight" two parts of a sentence by using a \colorbox like so:

\colorbox{red}{This is} \colorbox{blue}{a great sentence.}

The problem is that in the second part the height colorbox is a bit bigger, because it contains a g which extends below the baseline. As a result, the two colorboxes do not align at the bottom which looks suboptimal.

How would I make the two boxes line up?

Best Answer

You can use a \strut

{\colorbox{red}{\strut This is} \colorbox{blue}{\strut a great sentence.}}

LaTeX/TEX define \strut to be an invisible box of width zero that extends just enough above and below the baseline.

Related Question