我目前正在写论文。我使用 titletoc 包来管理目录。我对过长的章节标题感到困扰。我希望有一个新行与章节标题的第一行对齐。
这是我的示例代码。
\documentclass[fontsize=16pt,a4paper,oneside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% Layout packages
\usepackage[top=25mm, bottom=20mm, left=25mm, right=20mm]{geometry}
%%% toc packages
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{lineno}
\def\firstindentlength{1cm}
\setcounter{tocdepth}{1}
\makeatletter
\renewcommand\tableofcontents{%
\chapter*{Contents}%
\begin{flushright}
\textbf{page}
\end{flushright}
% Hold current page value
% for TOC heading
\newcounter{tocitem}
\setcounter{tocitem}{0}
\modulolinenumbers[50]
\linenumbers[1]
\@starttoc{toc}%
\setcounter{tocitem}{0}
\clearpage
\cleardoublepage
}
\makeatother
\titlecontents{chapter}
[0mm]
{\stepcounter{tocitem}}
{\MakeUppercase\chaptername\hspace{1ex}\thecontentslabel\enspace}
{}
{\titlerule*[0.6pc]{.}\contentspage}
\titlecontents{section}
[0mm]
{\stepcounter{tocitem}}
{\hspace{\firstindentlength}\thecontentslabel.\hspace{2mm}}
{\hspace{\firstindentlength}\thecontentslabel\hspace{2mm}}
{\titlerule*[0.6pc]{.}\contentspage}
\begin{document}
\thispagestyle{empty}
\tableofcontents
\newpage
\chapter{new chapter1}
\newpage
\chapter{This is a handbook about TeX, a new typesetting system intended for the creation of beautiful books and especially for books that contain a lot of mathematics.}
\newpage
\end{document}
谢谢你的建议。
答案1
使用该\contentslabel
命令,它有一个强制参数——标签使用的宽度,以及一个可选参数——标签格式,并相应地更改目录中章节的左边距(`\titlecontents 的第一个可选参数)。我还使用 \titlecontents 的最后一个可选参数在目录中的章节之间添加了一些垂直填充:
\documentclass[fontsize=16pt,a4paper,oneside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% Layout packages
\usepackage[top=25mm, bottom=20mm, left=25mm, right=20mm]{geometry}
%%% toc packages
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{lineno}
\setcounter{tocdepth}{1}
\makeatletter
\renewcommand\tableofcontents{%
\chapter*{Contents}%
\begin{flushright}
\textbf{page}
\end{flushright}
% Hold current page value
% for TOC heading
\newcounter{tocitem}
\setcounter{tocitem}{0}
\modulolinenumbers[50]
\linenumbers[1]
\@starttoc{toc}%
\setcounter{tocitem}{0}
\clearpage
\cleardoublepage
}
\makeatother
\titlecontents{chapter}
[0cm]
{\stepcounter{tocitem}}
{\contentspush{CHAP}TER\hspace{1ex}\thecontentslabel\enspace}
{}
{\titlerule*[0.6pc]{.}\contentspage}[\medskip]
\titlecontents{section}
[2.88em]
{\stepcounter{tocitem}}
{\thecontentslabel.\hspace{2mm}}
{\thecontentslabel\hspace{2mm}}
{\titlerule*[0.6pc]{.}\contentspage}
\begin{document}
\thispagestyle{empty}
\tableofcontents
\newpage
\chapter{New chapter1}
\newpage
\chapter{This is a handbook about TeX, a new typesetting system intended for the creation of beautiful books and especially for books that contain a lot of mathematics.}
\section{Hello! This is a section}
\newpage
\end{document}