Consider the following code which deals with a lstlisting
.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{listings}
\usepackage{xcolor}
\lstset{basicstyle=\small\ttfamily,keywordstyle=\color{blue},language=C++,showstringspaces=false,tabsize=2,numbers=left}
\begin{document}
\begin{lstlisting}
#include <stdio.h>
int main(void) {
printf("Hello World!");
return 0;
}
\end{lstlisting}
\end{document}
Is there a way to coulour the background of line numbers (in grey for example) but not the background of the code ?
Best Answer
listings
doesn't have a predefined option for this, but if you are willing to use thetcolorbox
package, which has a nice interaction with thelistings
package, here's how you can do it: