1

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?

  • 1
    Welcome to SE.tex Please provide us a MWE with \documentclass{} and ´\end{document}´ thats shows your problem. This make it easier to help you. – faltfe Sep 13 '18 at 20:03
  • Sorry for not including a MWE. I'll try to keep it in mind for the next post. Or should I still include one? – Nebucatnetzer Sep 16 '18 at 10:17
  • In almost every case it is better to include one. It will help understanding your problem much better and helpers will find a solution for your problem easier. – faltfe Sep 17 '18 at 09:37

1 Answers1

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.