Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use the following code in LaTeX to input the code Matlab there but I want to change the color of the background:

  \usepackage{textcomp}
  \usepackage{listings}
  \lstdefinestyle{customc}{
  belowcaptionskip=1\baselineskip,
  breaklines=true,
  frame=L,
xleftmargin=\parindent,
 language=Matlab,
  showstringspaces=false,
 basicstyle=\footnotesize\ttfamily,
 keywordstyle=\bfseries\color{green!40!black},
 commentstyle=\itshape\color{purple!40!black},
 identifierstyle=\color{blue},
stringstyle=\color{orange},
 }

  \lstdefinestyle{customasm}{
 belowcaptionskip=1\baselineskip,
 frame=L,
  xleftmargin=\parindent,
   language=[x86masm]Assembler,
  basicstyle=\footnotesize\ttfamily,
  commentstyle=\itshape\color{purple!40!black},
    }

   \lstset{escapechar=@,style=customc}

How can I do that to look like that in LaTeX report?

output

share|improve this question
    
Relevant: Inserting MATLAB code in the appendix –  Werner Sep 17 '13 at 20:38
    
You might be interested in the matlab-prettifier package; see this answer. –  Jubobs Apr 28 at 15:37

1 Answer 1

up vote 4 down vote accepted

The background colour of listings can be set with the backgroundcolor key. To get the specific colour, you can open your screenshot in for example Gimp and sample the colour used in the Matlab cells, then use this to define a custom colour:

\definecolor{MatlabCellColour}{RGB}{252,251,220}

Then add this to your customc style.

backgroundcolor=\color{MatlabCellColour} 

Complete example:

enter image description here

\documentclass{article}
\usepackage{textcomp,xcolor}
\definecolor{MatlabCellColour}{RGB}{252,251,220}
\usepackage{listings}
\lstdefinestyle{customc}{
  belowcaptionskip=1\baselineskip,
  breaklines=true,
  frame=L,
  xleftmargin=\parindent,
  language=Matlab,
  showstringspaces=false,
  basicstyle=\footnotesize\ttfamily,
  keywordstyle=\bfseries\color{green!40!black},
  commentstyle=\itshape\color{purple!40!black},
  identifierstyle=\color{blue},
  stringstyle=\color{orange},
  backgroundcolor=\color{MatlabCellColour}
 }


\begin{document}
\begin{lstlisting}[style=customc]
for k = 1:1000
  disp(k^2)
end
\end{lstlisting}
\end{document}
share|improve this answer
1  
@Educ Sorry, I must be blind. What is the problem exactly? –  Torbjørn T. Sep 17 '13 at 20:38
    
it's okay now thanks so much could you pleasse tell me what is the name of color in the background of matlab in my picture –  Educ Sep 17 '13 at 20:41
1  
@Educ I have no idea, but give me a minute, I'll open the screenshot in Gimp and sample the color. –  Torbjørn T. Sep 17 '13 at 20:42
    
Thanks Torbjørn T and take ur time –  Educ Sep 17 '13 at 20:44
1  
@Educ Torbjørn T. has just edited his answer showing you how. –  Gonzalo Medina Sep 17 '13 at 20:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.