4

I am using the minted package to highlight source code and also to add a list of listings. My code already looks like it should:

\begin{listing}[hb]
    \inputminted[frame=single,linenos]{c}{code/hello_world.c}
    \caption{Hello World in C}
    \label{hello_world_c}
\end{listing}

Code snippet, working as intended

I used the following commands to change the autoref name and the caption name:

\providecommand*{\listingautorefname}{Qc.}
\addto\captionsngerman{\renewcommand{\listingscaption}{Qc.}}

I also removed the chapter counter in the list of listings with the following commands:

\usepackage{chngcntr}
\counterwithout{figure}{chapter} 
\counterwithout{table}{chapter}
\counterwithout{listing}{chapter}

Now I insert the list of listings like this:

\addcontentsline{toc}{chapter}{Quellcodeverzeichnis}
\renewcommand{\listoflistingscaption}{Quellcodeverzeichnis}
\listoflistings
\clearpage

And my list of listings looks like this:

The actual list of listings

But instead I would like it to look like this:

List of listings as it should look like

I already tried inserting the name with \renewcommand{\cftlistingpresnum}{Qc.~}

But I get the following error: LaTeX Error: \cftlistingpresnum undefined.

I also tried using \usepackage[newfloat]{minted} but then the commands that worked before are undefined:

LaTeX Error: \listingscaptionundefined.
LaTeX Error: \listoflistingscaptionundefined.

I use ShareLaTeX for compiling my files. I read that the babel package might cause some problems, here is a list of packages I also use:

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[chapter]{minted}
\usepackage{etoolbox}

\usepackage[decimalsymbol=comma]{siunitx}
\usepackage[german,algosection,boxed]{algorithm2e}
\usepackage[onehalfspacing]{setspace}
\usepackage[titles]{tocloft}
\usepackage{caption}
\usepackage{enumitem}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{here}
\usepackage{hyperref}
\usepackage{pdflscape}
\usepackage{pstricks}
\usepackage{subcaption}
\usepackage{thmbox}

Edit: Here is my minimal working example:

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[chapter]{minted}
\usepackage{etoolbox}
\usemintedstyle{vs}

\usepackage[titles]{tocloft}
\usepackage{hyperref}
\usepackage{caption}
\usepackage{subcaption}

% ----------------------------------------------------------------
% Settings of Quellcodeverzeichnis
% ----------------------------------------------------------------
\usepackage{chngcntr}
\counterwithout{listing}{chapter}

% Doesn't work: LaTeX Error: \cftlistingpresnum undefined.
% \renewcommand{\cftlistingpresnum}{Qc.~}

\addto\captionsngerman{\renewcommand{\listingscaption}{Qc.}}
\providecommand*{\listingautorefname}{Qc.}

% ----------------------------------------------------------------
% Table of contents
% ---------------------------------------------------------------- 
\begin{document}
\tableofcontents
\clearpage

% ----------------------------------------------------------------
% Quellcodeverzeichnis
% ----------------------------------------------------------------
\phantomsection
\addcontentsline{toc}{chapter}{Quellcodeverzeichnis}
\renewcommand{\listoflistingscaption}{Quellcodeverzeichnis}
\listoflistings
\clearpage

% ----------------------------------------------------------------
% Content
% ----------------------------------------------------------------
\chapter{LaTeX-Template}
\label{ch:anhang}

My Hello World C program is right here: \autoref{hello_world_c}

\begin{listing}[hb]
\begin{minted}[frame=single,linenos]{c}
#include<stdio.h>

int main() {
    printf("Hello World\n");
    return 0;
}
\end{minted}
\caption{Hello World in C}
\label{hello_world_c}
\end{listing}
\clearpage


\end{document}

Any suggestions would be greatly appreciated.

2
  • 1
    Welcome to TeX.SX! Could you provide a full minimal working example (MWE). ... so just compilable code, starting with \documentclass and ending with \end{document}.
    – Bobyandbob
    May 24, 2018 at 20:56
  • @Bobyandbob Hello and thanks for answering, I added a minimal working example. May 24, 2018 at 21:35

1 Answer 1

3

I was able to solve my problem with the help of this answer: Customizing the list of listings from minted

Here is my result:

\documentclass{scrreprt}

\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage[titles]{tocloft}
\newlistof{listing}{lol}{Quellcodeverzeichnis}

\usepackage[newfloat]{minted}
\usemintedstyle{vs}
\usepackage{caption}

\usepackage{hyperref}
\usepackage{subcaption}

% ----------------------------------------------------------------
% Settings of Quellcodeverzeichnis
% ----------------------------------------------------------------
\usepackage{chngcntr}
\counterwithout{listing}{chapter}

\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{%
    name={Qc.},
    fileext=lol}

\renewcommand{\cftlistingpresnum}{Qc.~}
\setlength{\cftlistingnumwidth}{2cm}

\begin{document}

% ----------------------------------------------------------------
% Table of contents
% ---------------------------------------------------------------- 
\tableofcontents
\clearpage

% ----------------------------------------------------------------
% Quellcodeverzeichnis
% ----------------------------------------------------------------
\phantomsection
\addcontentsline{toc}{chapter}{Quellcodeverzeichnis}
\listoflistings
\clearpage

% ----------------------------------------------------------------
% Content
% ----------------------------------------------------------------
\chapter{LaTeX-Template}
\label{ch:anhang}

My Hello World C program is right here: \autoref{hello_world_c}

\begin{listing}[hb]
\begin{minted}[frame=single,linenos]{c}
#include<stdio.h>

int main() {
    printf("Hello World\n");
    return 0;
}
\end{minted}
\caption{Hello World in C}
\label{hello_world_c}
\end{listing}
\clearpage

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .