我正在使用 minted 包来突出显示源代码并添加列表。我的代码看起来应该如下:
\begin{listing}[hb]
\inputminted[frame=single,linenos]{c}{code/hello_world.c}
\caption{Hello World in C}
\label{hello_world_c}
\end{listing}
我使用以下命令来更改自动引用名称和标题名称:
\providecommand*{\listingautorefname}{Qc.}
\addto\captionsngerman{\renewcommand{\listingscaption}{Qc.}}
我还使用以下命令删除了列表列表中的章节计数器:
\usepackage{chngcntr}
\counterwithout{figure}{chapter}
\counterwithout{table}{chapter}
\counterwithout{listing}{chapter}
现在我插入如下列表:
\addcontentsline{toc}{chapter}{Quellcodeverzeichnis}
\renewcommand{\listoflistingscaption}{Quellcodeverzeichnis}
\listoflistings
\clearpage
我的清单如下:
但我希望它看起来像这样:
我已经尝试插入名称
\renewcommand{\cftlistingpresnum}{Qc.~}
但我收到以下错误:LaTeX Error: \cftlistingpresnum undefined.
我也尝试使用\usepackage[newfloat]{minted}
但之前起作用的命令未定义:
LaTeX Error: \listingscaptionundefined.
LaTeX Error: \listoflistingscaptionundefined.
我使用 ShareLaTeX 编译我的文件。我读到 babel 包可能会导致一些问题,下面是我也使用的包的列表:
\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}
编辑:这是我的最小工作示例:
\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}
任何建议将不胜感激。
答案1
我能够在这个答案的帮助下解决我的问题:自定义来自 minted 的列表
这是我的结果:
\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}