我第一次使用 tocloft,我想让“图片列表”和“表格列表”的字体变小,并显示在同一页上,紧接着目录之后。我希望列表标题的大小与目录中的章节条目相同。例如,在下面的 MWE 中,我希望文本“表格列表”和“图片列表”具有与文本“1 Stuff”和“2 More Stuff”相同的格式,并出现在第 1 页,紧接着目录之后。
\documentclass[10pt,oneside]{book}
\usepackage[titles]{tocloft} % To adjust the typography of the List of Figures and List of Tables
\usepackage{lipsum}
\usepackage{xcolor} % To change color of hyperlinks
\usepackage{helvet}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\color{teal}\normalfont\sffamily\huge\bfseries}
{\color{teal}\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
{\color{teal}\normalfont\sffamily\Large\bfseries}
{\color{teal}\thesection}{1em}{}
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkbordercolor=red,linkcolor=teal,citecolor=teal,urlcolor=teal}
\begin{document}
\tableofcontents
\addcontentsline{toc}{section}{Table of Contents}
\listoftables
\addcontentsline{toc}{section}{List of Tables}
\listoffigures
\addcontentsline{toc}{section}{List of Figures}
\chapter{Stuff}
\section{A section}
\lipsum[65]
\begin{table}[h!]
\centering
\caption{This is my first table.}
\begin{tabular}{c c}
\hline
\hline
Names & Ages \\
\hline
Margaret & 26 \\
John & 45 \\
Mary & 34 \\
\hline
\end{tabular}
\end{table}
\begin{table}[h!]
\centering
\caption{This is my second table.}
\begin{tabular}{c c}
\hline
\hline
Names & Ages \\
\hline
Paul & 85 \\
George & 13 \\
Stephanie & 56 \\
\hline
\end{tabular}
\end{table}
\section{Another section}
\lipsum[65]
\chapter{More Stuff}
\section{A section again}
\lipsum[65]
\begin{figure}[h!]
\caption{Figure caption here.}
\end{figure}
\end{document}
答案1
我希望列表标题的大小与目录中的章节条目的大小相同。
chapter
然后使用类型(而不是)将元素添加到 ToC section
。
我想让“图表列表”和“表格列表”[...]出现在同一页面上,紧接着目录之后。
由于你正在使用titlesec
它也覆盖了tocloft
管理 ToC/LoF/LoT 标题构造。您必须恢复使用titlesec
's\titlespacing{\chapter}{<left>}{<before>}{<after>}[<right>]
来设置 s 的间距方式\chapter
;请注意,ToC/LoF/LoT 都设置为\chapter
s(带星号的版本)。
此外,您必须设置\clearpage
为\relax
以避免分页符。请参阅如何在同一页和目录中\listoffigures
显示?\listoftables
这是您的最小示例:
\documentclass{book}
\usepackage[titles]{tocloft} % To adjust the typography of the List of Figures and List of Tables
\usepackage{lipsum}
\usepackage{xcolor} % To change color of hyperlinks
\usepackage{helvet}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\color{teal}\normalfont\sffamily\huge\bfseries}
{\color{teal}\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
{\color{teal}\normalfont\sffamily\Large\bfseries}
{\color{teal}\thesection}{1em}{}
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkbordercolor=red,linkcolor=teal,citecolor=teal,urlcolor=teal}
\begin{document}
\begingroup
\titlespacing*{\chapter}{0pt}{20pt}{5pt}
\tableofcontents
\addcontentsline{toc}{chapter}{Table of Contents}
\let\clearpage\relax
\listoftables
\addcontentsline{toc}{chapter}{List of Tables}
\listoffigures
\addcontentsline{toc}{chapter}{List of Figures}
\endgroup
\chapter{Stuff}
\section{A section}
\lipsum[65]
\begin{table}[h!]
\centering
\caption{This is my first table.}
\begin{tabular}{c c}
\hline \hline
Names & Ages \\
\hline
Margaret & 26 \\
John & 45 \\
Mary & 34 \\
\hline
\end{tabular}
\end{table}
\begin{table}[h!]
\centering
\caption{This is my second table.}
\begin{tabular}{c c}
\hline \hline
Names & Ages \\
\hline
Paul & 85 \\
George & 13 \\
Stephanie & 56 \\
\hline
\end{tabular}
\end{table}
\section{Another section}
\lipsum[65]
\chapter{More Stuff}
\section{A section again}
\lipsum[65]
\begin{figure}[h!]
\caption{Figure caption here.}
\end{figure}
\end{document}
答案2
这里建议使用包tocbasic
,但是请注意,此包不能与包一起使用tocloft
。
\documentclass[10pt,oneside]{book}
\usepackage{lipsum}
\usepackage{xcolor} % To change color of hyperlinks
\usepackage{helvet}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\color{teal}\normalfont\sffamily\huge\bfseries}
{\color{teal}\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titleformat{\section}
{\color{teal}\normalfont\sffamily\Large\bfseries}
{\color{teal}\thesection}{1em}{}
\usepackage{tocbasic}
\addtotoclist[\jobname]{toc}
\renewcommand\tableofcontents{\listoftoc[{\contentsname}]{toc}}
\setuptoc{toc}{totoc}% TOC entry for TOC
\addtotoclist[float]{lof}
\renewcommand\listoffigures{\listoftoc[{\listfigurename}]{lof}}
\addtotoclist[float]{lot}
\renewcommand\listoftables{\listoftoc[{\listtablename}]{lot}}
\doforeachtocfile[float]{%
\deftocheading{#1}{\section*{##1\addxcontentsline{toc}{chapter}{##1}}}%
}
\usepackage{hyperref}
\hypersetup{colorlinks=true,linkbordercolor=red,linkcolor=teal,citecolor=teal,urlcolor=teal}
\begin{document}
\tableofcontents
\listoftables
\listoffigures
\chapter{Stuff}
\section{A section}
\lipsum[65]
\begin{table}[h!]
\centering
\caption{This is my first table.}
\begin{tabular}{c c}
\hline
\hline
Names & Ages \\
\hline
Margaret & 26 \\
John & 45 \\
Mary & 34 \\
\hline
\end{tabular}
\end{table}
\begin{table}[h!]
\centering
\caption{This is my second table.}
\begin{tabular}{c c}
\hline
\hline
Names & Ages \\
\hline
Paul & 85 \\
George & 13 \\
Stephanie & 56 \\
\hline
\end{tabular}
\end{table}
\section{Another section}
\lipsum[65]
\chapter{More Stuff}
\section{A section again}
\lipsum[65]
\begin{figure}[h!]
\caption{Figure caption here.}
\end{figure}
\end{document}
结果:
如果 LOF 和 LOT 需要获得章节标题,请使用
\doforeachtocfile[float]{%
\deftocheading{#1}{\subsection*{##1\addxcontentsline{toc}{chapter}{##1}}}
}