# How can I prevent the background from overlapping the rounded corners in an \lstinputlisting?

I want to include listings of external files in my document. These listings should have a solid background and rounded corners. The problem is, that if I define a style with frameround and backgroundcolor, the background overlaps the rounded corners.

\lstdefinestyle{cftemplate}{
frameround=tttt,
rulecolor=\color[rgb]{0.7, 0.7, 0.7},
frame=single,
backgroundcolor=\color[rgb]{0.95, 0.95, 0.95}
}


There already exists a question how this behavior can be prevented in a lstlisting. In particular the solution presented in this answer works well for me. So I tried to extend this solution so that it also works with \lstinputlisting. However, the obvious attempt to replace "lstlisting" with "lstinputlisting" in the code snippet did not work.

So my question is: How can I create a \lstinputlisting with a background and rounded corners, where the background does not overlap the rounded corners?

If you are willing to use the tcolorbox package and its listings library, this is easy; using \newtcbinputlisting you can define a customizable macro which behaves pretty much as \lstinputlisting and with \newtcblisting you define your customizable version of lstlisting:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{beramono}% just for the example
\usepackage[many]{tcolorbox}
\tcbuselibrary{listings}

\newtcbinputlisting{\myinputlisting}[2][]{%
listing engine=listings,
listing file={#2},
colback=red!15,
colframe=red!75!black,
arc=12pt,
listing only,
listing options={
language={[LaTeX]TeX},
basicstyle=\ttfamily\small
},
breakable,
#1
}
\newtcblisting{mylisting}[1][]{%
listing engine=listings,
colback=red!15,
colframe=red!75!black,
arc=12pt,
listing only,
listing options={
language={[LaTeX]TeX},
basicstyle=\ttfamily\small
},
breakable,
#1
}

\usepackage{filecontents}
\begin{filecontents*}{Gtest1.tex}
\newlength\mylena
\newlength\mylenb
\setlength\mylena{2cm}
\setlength\mylenb{4cm}
\end{filecontents*}

\begin{document}

\myinputlisting{Gtest1.tex}

\begin{mylisting}[]
\documentclass{article}
\begin{document}
test
\end{document}
\end{mylisting}

\end{document}


• It was a bit tricky, because apparently I had an outdated version of the tcolorbox package. But now it looks very nice. Thanks! Jul 16 '14 at 20:38