0

I've found this template to insert Python code in which the background color is very ease to my eyes:

enter image description here

\documentclass[12pt]{article}
\usepackage[left = 1in, right = 1in, top = 1in, bottom = 1in]{geometry}
\usepackage[most]{tcolorbox}
\usepackage{listings}

\begin{document}

% Define colors to be used in the code 
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{darkraspberry}{rgb}{0.53, 0.15, 0.34}
\definecolor{backcolour}{rgb}{0.95, 0.95, 0.96}
\definecolor{airforceblue}{rgb}{0.36, 0.54, 0.66}

% Define the style of the code 
\lstdefinestyle{codeStyle}{
backgroundcolor=\color{backcolour},   
  commentstyle=\color{codegreen},
  keywordstyle=\color{airforceblue},
  numberstyle=\tiny\color{codegray},
  stringstyle=\color{darkraspberry},
  basicstyle=\ttfamily\footnotesize,
  breakatwhitespace=false,         
  breaklines=true,                 
  captionpos=b,                    
  keepspaces=true,                 
  numbers=left,                    
  numbersep=5pt,                  
  showspaces=false,                
  showstringspaces=false,
  showtabs=false,                  
  tabsize=2
}

% Set the style of the code to be our defined style
\lstset{style = codeStyle}

% Create the code listing
\lstinputlisting[language=Python]{Question 2d.py}

\end{document}

Here is my Python file (.py) used in the code.

From \definecolor{backcolour}{rgb}{0.95, 0.95, 0.96}, I guess the RGB is 0.95, 0.95, 0.96. But this color is different than what I observed in the PDF.

enter image description here

My desired color (from the background of the code) is a little bit darker than the color {rgb}{0.95, 0.95, 0.96}.

Could you please help me figure out why there is such difference and how to obtain my desired color?

Akira
  • 1,215

0 Answers0