14

I am using lstlisting to show some code in my PDF. The problem is that when I use:

  basicstyle=\fontfamily{pcr}\selectfont\footnotesize\color{red},

to change the code color (not only the language keywords), the frame color changes too. What I want to achive is to have the source code all red and the frame black. Here my lstset:

\lstset{ 
    language=C++, % choose the language of the code
    basicstyle=\fontfamily{pcr}\selectfont\footnotesize\color{red},
    keywordstyle=\color{black}\bfseries, % style for keywords
    numbers=none, % where to put the line-numbers
    numberstyle=\tiny, % the size of the fonts that are used for the line-numbers     
    backgroundcolor=\color{darkgray},
    showspaces=false, % show spaces adding particular underscores
    showstringspaces=false, % underline spaces within strings
    showtabs=false, % show tabs within strings adding particular underscores
    frame=single, % adds a frame around the code
    tabsize=2, % sets default tabsize to 2 spaces
    rulesepcolor=\color{gray}
    captionpos=b, % sets the caption-position to bottom
    breaklines=true, % sets automatic line breaking
    breakatwhitespace=false, 
}
1
  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question.
    – Werner
    Nov 13, 2011 at 15:23

1 Answer 1

24

The package listings provide the option rulecolor.

rulecolor=\color{black},

To get a complete overview of all options have a look into the documentation.

An example with your settings is given below. I think with your settings you can see nothing.

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstset{ 
    language=C++, % choose the language of the code
    basicstyle=\fontfamily{pcr}\selectfont\footnotesize\color{red},
    keywordstyle=\color{black}\bfseries, % style for keywords
    numbers=none, % where to put the line-numbers
    numberstyle=\tiny, % the size of the fonts that are used for the line-numbers     
    backgroundcolor=\color{darkgray},
    showspaces=false, % show spaces adding particular underscores
    showstringspaces=false, % underline spaces within strings
    showtabs=false, % show tabs within strings adding particular underscores
    frame=single, % adds a frame around the code
    tabsize=2, % sets default tabsize to 2 spaces
    rulesepcolor=\color{gray},
    rulecolor=\color{black},
    captionpos=b, % sets the caption-position to bottom
    breaklines=true, % sets automatic line breaking
    breakatwhitespace=false, 
}
\begin{document}
\begin{lstlisting}

Some Code 

for loop

if

return
\end{lstlisting}
\end{document}
0

You must log in to answer this question.

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