129

I would like some portion of the text to have all three features but it's not compiling. It works two at a time but not with all three.

\hl{\textbf{foo}}
\hl{\textcolor{red}{foo}}
\textbf{\textcolor{red}{foo}}

The above three work but this doesn't

\hl{\textbf{\textcolor{red}{foo}}}

I have tried all 6 combinations.. I think.

Thanks

3

2 Answers 2

158

Put \hl{..} inside.

\documentclass{report}
\usepackage{color,soul}
\begin{document}
  \hl{foo}
  \hl{\textbf{foo}} 
  \textcolor{red}{foo}
  \textbf{\textcolor{red}{\hl{foo}}}
  \textcolor{red}{\textbf{\hl{foo}}}
\end{document}

enter image description here

12
  • 58
    And don't be afraid of getting eye cancer :-)
    – Daniel
    Oct 31, 2013 at 9:10
  • 4
    @Daniel hehe, I won't color my words like this. :-)
    – user11232
    Oct 31, 2013 at 9:14
  • 9
    how is this done for beamer?
    – S_S
    Jul 12, 2015 at 11:37
  • 9
    You guys were not mentioning which package one should include, in order to have \hl working. (Or, color, soul is not working for Beamer.
    – llinfeng
    Feb 20, 2018 at 16:35
  • 1
    For beamer see tex.stackexchange.com/a/460764/152568
    – ijuneja
    Jul 8, 2021 at 11:36
96
\documentclass{article}
\usepackage{xcolor}
\begin{document}
~\\
\colorbox{pink}{highlight}\\
\colorbox{green}{highlight}\\
\colorbox{yellow}{highlight}\\
\bfseries\colorbox{pink}{highlight + boldface}\\
\colorbox{green}{highlight + boldface}\\
\colorbox{yellow}{highlight + boldface}\\
\color{red}\colorbox{pink}{highlight  + boldface  + colored text}\\
\colorbox{green}{highlight  + boldface + colored text}\\
\colorbox{yellow}{highlight  + boldface  + colored text}\\
\color{red}\colorbox{pink}{\parbox{10cm}{
highlight  + boldface  + long long long  long long long long long long long long long long long long long long long colored text}}\\
\color{red}\colorbox{green}{\parbox{10cm}{
highlight  + boldface  + long long long  long long long long long long long long long long long long long long long colored text}}\\
\color{red}\colorbox{yellow}{\parbox{10cm}{
highlight  + boldface  + long long long  long long long long long long long long long long long long long long long colored text}}\\
\end{document}

enter image description here

6
  • 5
    The problem is that you are building a box and hence your text is not broken at the end of line.
    – yannis
    Oct 29, 2017 at 11:16
  • 1
    @yannis I added an example of a long colored text.
    – SDrolet
    Nov 1, 2017 at 1:36
  • 4
    I think "textcolor{}" should be mentioned. "color{}" by itself is causing text that follows to change as well. Nov 25, 2018 at 22:49
  • 5
    And how to highlight text over several lines in the middle of a paragraph? Thank you
    – Confounded
    Jan 18, 2021 at 13:28
  • 1
    @YasinŞale Use \hl and \sethlcolor from the soul package instead, it can break highlighted text over mutliple lines.
    – Fritz
    Mar 8 at 15:58

You must log in to answer this question.

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