有人能解释以下行为吗:
梅威瑟:
\documentclass[12pt]{report}
\title{List of listings problem}
\author{Gerjan}
\date{June 2016}
%\usepackage{babel} % Use dutch, british or english
\usepackage[english]{babel}
% \usepackage{float} % Including this package influences the behavior of LOL!
\usepackage{listings}
\usepackage{tocbibind}
\usepackage{tocloft}
\begin{document}
\maketitle
\cleardoublepage
\pagenumbering{Roman}
\setlength{\cftbeforetoctitleskip}{0em}
\setlength{\cftbeforeloftitleskip}{0em}
\setlength{\cftbeforelottitleskip}{0em}
\setlength{\cftaftertoctitleskip}{10em} % Should affect toc AND lol
% toc and lol styling
\renewcommand\cfttoctitlefont{\normalfont\large}
% list of figures styling
\renewcommand\cftloftitlefont{\normalfont\Huge}
% list of tables styling
\renewcommand\cftlottitlefont{\normalfont\Huge}
% title of toc
\renewcommand\contentsname{Contents}
% title of lof
\renewcommand\listfigurename{List of Figures}
% title of lot
\renewcommand\listtablename{List of Tables}
% title of lol
\renewcommand\lstlistlistingname{List of Listings}
% Table of contents (toc)
\cleardoublepage
\phantomsection
\tableofcontents
% List of figures (lof)
\cleardoublepage
\phantomsection
\listoffigures
% List of tables (lot)
\cleardoublepage
\phantomsection
\listoftables
% List of listings (lol)
\cleardoublepage
\phantomsection
\lstlistoflistings
% Below is only needed when the float package is used
\addcontentsline{toc}{chapter}{\lstlistlistingname}
\cleardoublepage
\end{document}
当我包含(删除注释)该float
包时,发生以下情况:
- 列表列表的标题样式(字体,间距等)无法修改(一般情况下LOL的标题样式和TOC一样)
- 清单列表未在目录中列出(您需要手动执行)
答案1
float
实际上,它是和的相互作用,listings
以防止正确的(或期望的行为)
以下代码来自listings
\lst@UserCommand\lstlistoflistings{\bgroup
\let\contentsname\lstlistlistingname
\let\lst@temp\@starttoc \def\@starttoc##1{\lst@temp{lol}}%
\tableofcontents \egroup}
\@ifundefined{float@listhead}{}{%
\renewcommand*{\lstlistoflistings}{%
\begingroup
\@ifundefined{@restonecoltrue}{}{%
\if@twocolumn
\@restonecoltrue\onecolumn
\else
\@restonecolfalse
\fi
}%
\float@listhead{\lstlistlistingname}%
\parskip\z@\parindent\z@\parfillskip \z@ \@plus 1fil%
\@starttoc{lol}%
\@ifundefined{@restonecoltrue}{}{%
\if@restonecol\twocolumn\fi
}%
\endgroup
}%
}
一旦float@listhead
定义了(如果float
加载了就是这种情况),listings
就会重新定义\lstlistoflistings
。
为了防止这种情况,请float
在此处使用 afterlistings
和 aftertocbibind
等!
\documentclass[12pt]{book}
\title{List of listings problem}
\author{Gerjan}
\date{June 2016}
%\usepackage{babel} % Use dutch, british or english
\usepackage[english]{babel}
\usepackage{tocbibind}
\usepackage{listings}
\usepackage{tocloft}
\usepackage{float} % Including this package influences the behavior of LOL!
\AtBeginDocument{%
% toc and lol styling
\renewcommand\cfttoctitlefont{\normalfont\large}
% list of figures styling
\renewcommand\cftloftitlefont{\normalfont\Huge}
% list of tables styling
\renewcommand\cftlottitlefont{\normalfont\Huge}
% title of toc
\renewcommand\contentsname{Contents}
% title of lof
\renewcommand\listfigurename{List of Figures}
% title of lot
\renewcommand\listtablename{List of Tables}
% title of lol
\renewcommand\lstlistlistingname{List of Listings}
\setlength{\cftbeforetoctitleskip}{0em}
\setlength{\cftbeforeloftitleskip}{0em}
\setlength{\cftbeforelottitleskip}{0em}
\setlength{\cftaftertoctitleskip}{10em} % Should affect toc AND lol
}
\begin{document}
\maketitle
\cleardoublepage
\pagenumbering{Roman}
% Table of contents (toc)
\cleardoublepage
\tableofcontents
% List of figures (lof)
\cleardoublepage
\listoffigures
% List of tables (lot)
\cleardoublepage
\listoftables
% List of listings (lol)
\cleardoublepage
\lstlistoflistings
% Below is only needed when the float package is used
%\addcontentsline{toc}{chapter}{\lstlistlistingname}
\cleardoublepage
\chapter{Foo}
\begin{figure}
\caption{Foo figure}
\end{figure}
\begin{lstlisting}[language=C,caption={Foo listing}]
int main(void)
\end{lstlisting}
\end{document}