我希望我正在编辑的书的目录首先显示章节的页码,然后显示章节标题。类似于这本书:
我正在使用 XeTeX(通过 LyX),我的文档类别是 Memoir。
答案1
这是一种可能性(正如评论中所要求的那样,未编号章节的章节号已包含在相应的标题之前):
\documentclass{memoir}
\usepackage{graphicx}
\renewcommand\partnumberline[1]{}
\renewcommand\chapternumberline[1]{#1~\raisebox{.2ex}{\scalebox{0.75}{\textbullet}~}}
\renewcommand\cftpartpagefont{\huge\bfseries}
\renewcommand\cftpartfont{\LARGE\bfseries}
\renewcommand\cftchapterpagefont{\normalfont\large\itshape}
\renewcommand\cftchapterfont{\normalfont}
\newlength\ToCindent
\setlength\ToCindent{4em}
\makeatletter
\renewcommand*{\l@part}[2]{%
\ifnum \c@tocdepth >-2\relax
\cftpartbreak
\begingroup
{\leftskip0pt\noindent
\interlinepenalty\@M
\leavevmode
\parbox[t]{\ToCindent}{\makebox[2em][r]{\cftpartpagefont #2}\hfill}%
\parbox[t]{\dimexpr\textwidth-\ToCindent\relax}{\cftpartfont #1}%
}
\par\nobreak
\global\@nobreaktrue
\everypar{\global\@nobreakfalse\everypar{}}%
\endgroup
\fi}
\newcommand*{\l@mychap}[3]{%
\def\@chapapp{#3}
\vskip2ex%
\par%
\noindent\parbox[t]{\ToCindent}{\makebox[2em][r]{\cftchapterpagefont#2}\hfill}%
\parbox[t]{\dimexpr\textwidth-\ToCindent\relax}{\cftchapterfont#1}\par%
}
\renewcommand*{\l@chapter}[2]{%
\l@mychap{#1}{#2}{\chaptername}%
}
\renewcommand*{\l@appendix}[2]{%
\l@mychap{#1}{#2}{\appendixname}%
}
\makeatother
\begin{document}
\tableofcontents*
\part{A test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\addcontentsline{toc}{chapter}{A test unnumbered chapter}
\chapter{Another test chapter with an interesting title}
\part{Another test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\addcontentsline{toc}{chapter}{Another test unnumbered chapter}
\chapter{Another test chapter with an interesting title}
\part{Yet another test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\chapter{Another test chapter with an interesting title}
\end{document}
我在这里添加了另一个选项,显示用项目符号分隔的页码和章节号,这是评论中最初要求的;我更喜欢以前的解决方案,因为这个可能会导致混淆:
\documentclass{memoir}
\usepackage{graphicx}
\renewcommand\partnumberline[1]{}
\renewcommand\chapternumberline[1]{\makebox[0pt][l]{%
\llap{\raisebox{.2ex}{\scalebox{0.75}{\textbullet}}\,#1\hspace{1.2em}}}}
\renewcommand\cftpartpagefont{\huge\bfseries}
\renewcommand\cftpartfont{\LARGE\bfseries}
\renewcommand\cftchapterpagefont{\normalfont}
\renewcommand\cftchapterfont{\normalfont}
\newlength\ToCindent
\setlength\ToCindent{4.5em}
\makeatletter
\renewcommand*{\l@part}[2]{%
\ifnum \c@tocdepth >-2\relax
\cftpartbreak
\begingroup
{\leftskip0pt\noindent
\interlinepenalty\@M
\leavevmode
\parbox[t]{\ToCindent}{\makebox[2em][r]{\cftpartpagefont #2}\hfill}%
\parbox[t]{\dimexpr\textwidth-\ToCindent\relax}{\cftpartfont #1}%
}
\par\nobreak
\global\@nobreaktrue
\everypar{\global\@nobreakfalse\everypar{}}%
\endgroup
\fi}
\newcommand*{\l@mychap}[3]{%
\def\@chapapp{#3}
\vskip2ex%
\par%
\noindent\parbox[t]{\ToCindent}{\makebox[2em][r]{\cftchapterpagefont#2}\hfill}%
\parbox[t]{\dimexpr\textwidth-\ToCindent\relax}{\cftchapterfont#1}\par%
}
\renewcommand*{\l@chapter}[2]{%
\l@mychap{#1}{#2}{\chaptername}%
}
\renewcommand*{\l@appendix}[2]{%
\l@mychap{#1}{#2}{\appendixname}%
}
\makeatother
\begin{document}
\tableofcontents*
\part{A test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\addcontentsline{toc}{chapter}{A test unnumbered chapter}
\chapter{Another test chapter with an interesting title}
\part{Another test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\addcontentsline{toc}{chapter}{Another test unnumbered chapter}
\chapter{Another test chapter with an interesting title}
\part{Yet another test part}
\chapter{Test chapter with a really long title spanning several lines just for the example}
\chapter{Another test chapter}
\chapter{Another test chapter with an interesting title}
\end{document}
长度\ToCindent
控制页码和标题之间的间隔。