update

I don't think it's possible to use a \caption
without much redefinitions. Here's a version with blend into=listings
, which must be done in \AtBeginDocument
or after \begin{document}
.
The title=
will then be used as the long caption text, the short one is given by list text=...
-- See the example, please.
To move the caption to the bottom, the title has to be detached and the title box reconfigured.
\documentclass[a4paper,11pt,twoside]{report}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[fleqn]{amsmath}
\usepackage[scaled=.95]{inconsolata}
\usepackage{tcolorbox}
\tcbuselibrary{listings, breakable, skins}
\definecolor{bg}{rgb}{0.85,0.85,0.85}
\renewcommand*\thelstnumber{\makebox[3em][r]{\ifnum\value{lstnumber}<10 0\fi\the\value{lstnumber}}}
\AtBeginDocument{%
\newtcblisting[blend into=listings]{ccode}[1][]{%
colback=bg,
colframe=black!70,
enhanced,
listing only,
overlay={\begin{tcbclipinterior}\fill[black!25] (frame.south west)
rectangle ([xshift=5.1mm]frame.north west);\end{tcbclipinterior}},
listing remove caption=false,
listing options={numbers=left, numberstyle=\tiny,
basicstyle=\small\ttfamily,
xleftmargin=0.6em,
language = c,
aboveskip=\smallskipamount,
belowskip=\smallskipamount,
},
coltitle=black,
attach boxed title to bottom center={yshift=-10pt},
boxed title style={enhanced jigsaw, colback=white, sharp corners, boxrule=0pt},
#1
}
}
\begin{document}
\lstlistoflistings
\begin{ccode}[list text={C-Programm!},title={Ein primitives C - Programm!}]
#include <stdio.h>
int main()
{
stub;
}
\end{ccode}
\end{document}
tcolorbox
defines listing remove caption=true
, i.e use this as an option and provide a caption argument, i.e. define the \newtcblisting
with a mandatory argument`.
\documentclass[a4paper,11pt,twoside]{report}
%\usepackage{ngerman}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[fleqn]{amsmath}
\usepackage[scaled=.95]{inconsolata}
\usepackage{tcolorbox}
\tcbuselibrary{listings, breakable, skins}
\definecolor{bg}{rgb}{0.85,0.85,0.85}
\renewcommand*\thelstnumber{\makebox[3em][r]{\ifnum\value{lstnumber}<10 0\fi\the\value{lstnumber}}}
\newtcblisting{ccode}[2][]
{colback=bg,
colframe=black!70,
enhanced,
listing only,
overlay={\begin{tcbclipinterior}\fill[black!25] (frame.south west)
rectangle ([xshift=5.1mm]frame.north west);\end{tcbclipinterior}},
listing remove caption=false,
listing options={numbers=left, numberstyle=\tiny, basicstyle=\small\ttfamily, xleftmargin=0.6em, language = c, aboveskip=\smallskipamount, belowskip=\smallskipamount, caption={#2}},#1
}
\begin{document}
\begin{ccode}{Ein primitives C - Programm!}
#include <stdio.h>
int main()
{
stub;
}
\end{ccode}
\end{document}

floating
listings? – Ignasi Apr 20 '16 at 17:18floating
andcaptioned
solution you'd totally save my day. – Raito Apr 20 '16 at 17:20ngerman
is actually a little bit outdated. Use\usepackage[ngerman]{babel}
rather – user31729 Apr 20 '16 at 17:22\usepackage{caption}
and then\captionof
? – naphaneal Apr 20 '16 at 17:23