In this question Source code listing with frame around code? Ignasi provides a really nice latex snippet for code blocks. However when I use it the code block doesn't get listed in the \lstlistoflistings. It just remains empty. Does someone know how to fix this?
Asked
Active
Viewed 275 times
1 Answers
1
I adapted the answer of @Ignasi for Source code listing with frame around code? for the following solution.
Basically, auto counter has to be replaced by blend into=listings. Further, \AtBeginDocument is needed here:
\documentclass{report}
\usepackage{listings}
\usepackage[most]{tcolorbox}
\usepackage{inconsolata}
\AtBeginDocument{
\newtcblisting[blend into=listings]{sexylisting}[2][]{sharp corners,
fonttitle=\bfseries, colframe=gray, listing only,
listing options={basicstyle=\ttfamily,language=java},
title=#2, #1}
}
\begin{document}
\begin{sexylisting}{Some Code}
public void here() {
goes().the().code()
}
\end{sexylisting}
\begin{sexylisting}[colback=white]{Same code again}
public void here() {
goes().the().code()
}
\end{sexylisting}
\lstlistoflistings
\end{document}
With these changes, the new sexylisting takes the original listings counter and may be used mixed with normal listings.
Thomas F. Sturm
- 25,210
\documentclass{}and ´\end{document}´ thats shows your problem. This make it easier to help you. – faltfe Sep 13 '18 at 20:03