5

I'm having the following problem: I'm using the listings package to render what is supposed to look like a teminal screenshot. But the background colour is striped. In my other code snippets the background colour is light gray so it is much less noticeable, but it's really ugly on the black background. I've looked at potential solutions online using \shaded or colorbox, but none have worked because of the shadowbox I'm using.

Any input would be much appreciated.

\lstset{%
  language=C,                % choose the language of the code
  basicstyle=\ttfamily\footnotesize\color{white} ,       % the size of the fonts that    are used for the code
  tabsize=2,                      % sets default tabsize to 2 spaces
  captionpos=b,                   % sets the caption-position to bottom
  breaklines=true,                % sets automatic line breaking
  breakatwhitespace=true,         % sets if automatic breaks should only happen at    whitespace
  keywordstyle=\color{white},
  commentstyle=\color{white},
  stringstyle=\color{white},
  numberstyle=\tiny\color{midgray},  % the style that is used for the line-numbers
  stepnumber=2,                   % the step between two line-numbers. If it's 1, each line 
                              % will be numbered
  numbersep=5pt,                  % how far the line-numbers are from the code
  frame=shadowbox,
  rulesepcolor=\color{darkgray},
  lineskip={-1.5pt}, % single line spacing
  aboveskip=1.5\bigskipamount,
  belowskip=\smallskipamount,
  escapechar={\@},
  showstringspaces=false,
  backgroundcolor=\color{black}
}
3
  • 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
    Feb 18, 2012 at 2:37
  • 1
    While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Feb 18, 2012 at 3:16
  • Possible duplicate: Problems with the lstlisting environment (margin and white line)
    – Werner
    Jun 18, 2013 at 23:29

1 Answer 1

6

Use the tcolorbox package, which uses the listings package, but has better support for effects.

enter image description here

This is what a MWE is:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{listings}
\begin{document}
\begin{tcblisting}{colback=black,coltext=green}
This is a \LaTeX\ example which displays the text as source code
and in compiled form.
\end{tcblisting}
\end{document}

The package has recently been updated to include English documentation, so you might need to update your distribution. The dotted line in the middle can be removed if you don't use the output frame with the listing only option.

2
  • Very nice terminal!
    – Werner
    Feb 18, 2012 at 4:30
  • @Werner Thanks! With a bit of patience and JavaScript you might get it to work as one in a pdf:) Feb 18, 2012 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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