如何重新定義 \lstlistoflistings 標題的樣式?

如何重新定義 \lstlistoflistings 標題的樣式?

我正在使用基於 cls 的memoir套件listings。我想要一個包含所有清單(表格清單、圖形清單、清單清單)的附錄章節。這些清單的標題樣式應該像section標題一樣。

我可以對錶格和數字執行此操作,如下所示:

\makeatletter
\renewcommand\@lofmaketitle{%
  \section*{\listfigurename}%
  \tocmark%
  \@afterheading}
\makeatother

\makeatletter
\renewcommand\@lotmaketitle{%
  \section*{\listtablename}%
  \tocmark%
  \@afterheading}
\makeatother

所以我認為它也應該適用於列表,但以下內容沒有效果:

\makeatletter
\renewcommand\@lolmaketitle{%
  \section*{\lstlistlistingname}%
  \tocmark%
  \@afterheading}
\makeatother

我使用\lstlistoflistings*所以我不希望它出現在目錄中。

我怎樣才能做到這一點?

答案1

這應該可以做到

\documentclass[a4paper]{memoir}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[caption=Hest]
a
\end{lstlisting}


\begingroup

\makeatletter
\renewcommand\@tocmaketitle{%
  \section*{\contentsname}%
  \markboth{\contentsname}{\contentsname}
  \@afterheading}
\makeatother

% adding a star to \lstlistoflistings does not work, the inner 
% \tableofcontents never sees it. Locally use \KeepFromToc 
% to emulate the *
\KeepFromToc
\lstlistoflistings
\endgroup

\end{document}

請注意,更改實際上不能在序言中,因為它也會影響\tableofcontents.

相關代碼listings來自

\lst@UserCommand\lstlistoflistings{\bgroup
    \let\contentsname\lstlistlistingname
    \let\lst@temp\@starttoc \def\@starttoc##1{\lst@temp{lol}}%
    \tableofcontents \egroup}

在這裡我們可以看到它重置,以及應該使用\contentsname什麼檔案。通常執行,所以他們就執行。\@starttoc\tableofcontents\@starttoc\tableofcontents

相關內容