自定义列表列表

自定义列表列表

我需要自定义我的列表页面,在每个标题后添加一个句点(例如Listing 1.1.)。我在代码中找不到插入句点的正确位置。

在此处输入图片描述

这是我的 MWE:

\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}

\title{TEST}
\author{AYILDIZ}
\date{October 2020}

\usepackage{listings}


\makeatletter
\AtBeginDocument{%
\renewcommand\lstlistoflistings{\bgroup
  \let\contentsname\lstlistlistingname
  \def\l@lstlisting##1##2{\@dottedtocline{1}{0em}{2.3em}{Listing ##1}{##2}}
  \let\lst@temp\@starttoc \def\@starttoc##1{\lst@temp{lol}}%
  \clearpage %<---------------
  \addcontentsline{toc}{chapter}{Listings}%
  \tableofcontents \egroup}
}
\makeatother

\begin{document}

\maketitle

\tableofcontents
\listoffigures
\listoftables

\lstlistoflistings

\chapter{INTRODUCTION}\label{chp:Introduction}

Interest in exploring the genetic data of organisms is growing everyday.

Miusov, as a man man of breeding and deilcacy, could not but feel some inwrd qualms, when he reached the Father Superior's with Ivan: he felt ashamed of havin lost his temper. He felt that he ought to have disdaimed that despicable wretch, Fyodor Pavlovitch, too much to have been upset by him in Father Zossima's cell, and so to have forgotten himself. "Teh monks were not to blame, in any case," he reflceted, on the steps. "And if they're decent people here (and the Father Superior, I understand, is a nobleman) why not be friendly and courteous withthem? I won't argue, I'll fall in with everything, I'll win them by politness, and show them that I've nothing to do with that Aesop, thta buffoon, that Pierrot, and have merely been takken in over this affair, just as they have."

He determined to drop his litigation with the monastry, and relinguish his claims to the wood-cuting and fishery rihgts at once. He was the more ready to do this becuase the rights had becom much less valuable, and he had indeed the vaguest idea where the wood and river in quedtion were.

\begin{lstlisting}[caption={My Code},language=C]
#include<stdio.h>

int main(int argc,char **argv)
{
  printf("Hello World!\n");
  return(0);
}
\end{lstlisting}
\end{document}

答案1

您需要更改的定义\numberline

\makeatletter
\AtBeginDocument{%
\renewcommand\lstlistoflistings{\bgroup
  \let\contentsname\lstlistlistingname
  \def\numberline##1{\hb@xt@\@tempdima{##1.\hfil}}% <--- added by egreg
  \def\l@lstlisting##1##2{\@dottedtocline{1}{0em}{2.3em}{Listing ##1}{##2}}%
  \let\lst@temp\@starttoc \def\@starttoc##1{\lst@temp{lol}}%
  \cleardoublepage %<---------------
  \addcontentsline{toc}{chapter}{Listings}%
  \tableofcontents \egroup}%
}
\makeatother

在此处输入图片描述

另外,您应该使用\cleardoublepage而不是\clearpage。如果您改变主意并开始使用双面打印,那么 simple\clearpage就不合适了。对于单面打印,这两个命令是等效的。

相关内容