我的文档确实有问题。
我重新定义了我的 ruby 代码的列表:
\usepackage{listings}
\renewcommand\lstlistingname{Quellcode}
\lstloadlanguages{Ruby}
\lstset{%
basicstyle=\small\ttfamily\color{black},
commentstyle = \ttfamily\color{red},
keywordstyle=\ttfamily\color{blue},
stringstyle=\color{orange},
backgroundcolor=\color{grey},
columns=fullflexible}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
并重新定义了lstlistoflistings。
\renewcommand\lstlistlistingname{Quellcodeverzeichnis}
\addcontentsline{toc}{section}{Quellcodeverzeichnis}
\lstlistoflistings
\newpage
但是lstlistoflistings
没有显示名字,只显示第一个的号码。
实际情况如下lstlistoflistings
:
lstlistingname
有人能帮助我并告诉我如何在每一行中获取(Quellcode)吗lstlistoflistings
?
谢谢
更新:
这里是 MWE:
\documentclass[12pt, a4paper, oneside]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage[ngerman]{babel}
\usepackage[hidelinks=true]{hyperref}
\usepackage[final]{pdfpages}
\definecolor{grey}{gray}{0.9}
\usepackage{listings}
\renewcommand\lstlistingname{Quellcode-Ausschnitt}
\lstloadlanguages{Ruby}
\lstset{%
basicstyle=\small\ttfamily\color{black},
commentstyle = \ttfamily\color{red},
keywordstyle=\ttfamily\color{blue},
stringstyle=\color{orange},
backgroundcolor=\color{grey},
columns=fullflexible}
\usepackage{color}
\usepackage{xcolor}
\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}
\usepackage{geometry}
\geometry{a4paper, top=25mm, left=25mm, right=25mm, bottom=20mm, headsep=10mm, footskip=12mm}
\begin{document}
\renewcommand\lstlistlistingname{Quellcodeverzeichnis}
\addcontentsline{toc}{section}{Quellcodeverzeichnis}
\lstlistoflistings
\newpage
\begin{lstlisting}[language=Ruby, caption=StatusCalculator Initialize, label=initialize]
def initialize(project_id)
@project = Project.find(project_id)
end
\end{lstlisting}
\end{document}
答案1
您可以在调用之前将此代码添加到您的文档中\lstlistoflistings
(例如在序言中):
\let\oldlstlistoflistings\lstlistoflistings
\renewcommand{\lstlistoflistings}{%
\begingroup%
\let\oldnumberline\numberline%
\renewcommand{\numberline}{\lstlistingname~\oldnumberline}%
\oldlstlistoflistings%
\endgroup}
您将获得:
请注意,此代码改编自回答沃纳 (Werner) 的论文,该论文针对的是指挥部,讨论了同样的问题\listofalgorithms
。