2

This question already has an answer here:

I want to use a different text color in a listing, for example red to highlight a word or a sentence. I use \textcolor{} but if it's over more than one line the background gets white and not grey. Is there any way to set the background to grey or to use another method to change the color or some text?

\documentclass[11pt]{article}
\usepackage{listings}
\usepackage{color}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}  

% custom highlighting
\lstset{escapeinside={<@}{@>}}

\begin{document}
\lstset{  
tabsize=4,  
basicstyle=\ttfamily,  
backgroundcolor=\color{lbcolor},  
showstringspaces=false,
breaklines=true,
}
\begin{lstlisting}[]
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<@\textcolor{red}{\textbf{Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.}}@>
\end{lstlisting}
\end{document}

enter image description here

marked as duplicate by schtandard, Stefan Pinnow, Raaja, Mensch, Phelype Oleinik Jun 4 at 20:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Stefan Pinnow Jun 4 at 17:05
  • Sorry, I've added a compilable code. It's not the original but it should show the problem. Thank you. – Crankle Jun 4 at 17:33

Browse other questions tagged or ask your own question.