当将“列表列表”添加到目录中时(如我自定义标题的图像所示),我注意到当章节发生变化时,列表元素之间没有空格,这与图表列表不同。以下是区别:
如您所见,章节更改时条目之间没有空格。
我尝试过\setlength{\cftfignumwidth}{3em}
,其中 3em 只是间距的一个示例,但它给了我一个错误,说它已经定义了,而我自己并没有定义。现在自定义列表的代码是这样的:
\renewcommand\listingscaption{Codice}
\renewcommand\listoflistingscaption{Elenco dei codici sorgenti}
\counterwithin*{listing}{chapter}
\renewcommand\thelisting{\thechapter.\arabic{listing}}```
以下是一个例子:
\documentclass{report}
\usepackage{minted}
\usepackage{hyperref}
\usepackage{graphicx}
\renewcommand\listingscaption{Codice}
\renewcommand\listoflistingscaption{Elenco dei codici sorgenti}
\counterwithin*{listing}{chapter}
\renewcommand\thelisting{\thechapter.\arabic{listing}}
\begin{document}
\cleardoublepage
\pdfbookmark{\contentsname}{tableofcontents}
\setcounter{secnumdepth}{5} % Numbering depth for sections
\setcounter{tocdepth}{5}
% Depth of entries in the table of contents
\tableofcontents
%\markboth{\contentsname}{\contentsname}
\clearpage
\begingroup
\let\clearpage\relax
\let\cleardoublepage\relax
\let\cleardoublepage\relax
% Figures list
\phantomsection
\pdfbookmark{\listfigurename}{lof}
\listoffigures
\vspace*{8ex}
% Listings list
\phantomsection
\pdfbookmark{\listoflistingscaption}{lol}
\listoflistings
\vspace*{8ex}
\endgroup
\cleardoublepage
\chapter{First Chapter}
\begin{listing}[!ht]
\begin{minted}{c}
#include <stdio.h>
int main() {
print("Hello, world!");
return 0;
}
\end{minted}
\caption{Example of code in Chapter 1}
\label{listing:1}
\end{listing}
\section{Introduzione al progetto}
\begin{figure}[!ht]
\centering
\includegraphics[alt={Testo alternativo dell'immagine}, width=0.5\columnwidth]{img/pk_estate.jpeg}
\caption{Caption}
\label{fig:pk_estate}
\end{figure}
\begin{listing}[!ht]
\begin{minted}{c}
#include <stdio.h>
int main() {
print("Hello, world!");
return 0;
}
\end{minted}
\caption{Example of another code in Chapter 1}
\label{listing:2}
\end{listing}
\chapter{Second Chapter}
\section{Introduzione al progetto}
\begin{figure}[!ht]
\centering
\includegraphics[alt={Testo alternativo dell'immagine}, width=0.5\columnwidth]{img/pk_estate.jpeg}
\caption{Caption}
\label{fig:pk_etate}
\end{figure}
\section{Introduzione al progetto}
\begin{figure}[!ht]
\centering
\includegraphics[alt={Testo alternativo dell'immagine}, width=0.5\columnwidth]{img/pk_estate.jpeg}
\caption{Caption}
\label{fig:pk_estate2-2}
\end{figure}
\begin{listing}[!ht]
\begin{minted}{c}
#include <stdio.h>
int main() {
print("Hello, world!");
return 0;
}
\end{minted}
\caption{Example of code in Chapter 2}
\label{listing:3}
\end{listing}
% More chapters and listings...
\end{document}
答案1
您需要注入类似的代码\@chapter
,在新章节开始时在辅助文件“列表”中插入垂直空格。
无论是否加载 ,下面的代码都可以正常工作hyperref
。问题是,如果hyperref
加载 ,则修补命令为 ,\NR@chapter
而不是\@chapter
。
\documentclass{report}
\usepackage{minted}
\usepackage{etoolbox}
\usepackage{hyperref}
\makeatletter
\ifdefined\NR@chapter
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi{\patchcmd\NR@chapter}{\patchcmd\@chapter}
{\addtocontents{lot}{\protect\addvspace{10\p@}}}
{\addtocontents{lot}{\protect\addvspace{10\p@}}%
\addtocontents{lol}{\protect\addvspace{10\p@}}}
{}{}
\makeatother
\renewcommand\listingscaption{Codice}
\renewcommand\listoflistingscaption{Elenco dei codici sorgenti}
\counterwithin*{listing}{chapter}
\renewcommand\thelisting{\thechapter.\arabic{listing}}
\begin{document}
\tableofcontents
\listoffigures
\listoflistings
\chapter{First Chapter}
\begin{listing}[!ht]
\begin{minted}{c}
#include <stdio.h>
int main() {
print("Hello, world!");
return 0;
}
\end{minted}
\caption{Example of code in Chapter 1}
\label{listing:1}
\end{listing}
\section{Introduzione al progetto}
\begin{figure}[!ht]
\centering
% \includegraphics[alt={Testo alternativo dell'immagine}, width=0.5\columnwidth]{img/pk_estate.jpeg}
\caption{Caption}
\label{fig:pk_estate}
\end{figure}
\begin{listing}[!ht]
\begin{minted}{c}
#include <stdio.h>
int main() {
print("Hello, world!");
return 0;
}
\end{minted}
\caption{Example of another code in Chapter 1}
\label{listing:2}
\end{listing}
\chapter{Second Chapter}
\section{Introduzione al progetto}
\begin{figure}[!ht]
\centering
% \includegraphics[alt={Testo alternativo dell'immagine}, width=0.5\columnwidth]{img/pk_estate.jpeg}
\caption{Caption}
\label{fig:pk_etate}
\end{figure}
\section{Introduzione al progetto}
\begin{figure}[!ht]
\centering
% \includegraphics[alt={Testo alternativo dell'immagine}, width=0.5\columnwidth]{img/pk_estate.jpeg}
\caption{Caption}
\label{fig:pk_estate2-2}
\end{figure}
\begin{listing}[!ht]
\begin{minted}{c}
#include <stdio.h>
int main() {
print("Hello, world!");
return 0;
}
\end{minted}
\caption{Example of code in Chapter 2}
\label{listing:3}
\end{listing}
% More chapters and listings...
\end{document}