我想在章节标题前添加作者姓名。我使用以下内容:
\documentclass{book}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{lipsum}% just to generate some text
\makeatletter
\newcommand*\l@authors{\@dottedtocline{1}{0pt}{0pt}}
\makeatother
\newcommand\chapaut[1]{%
\addcontentsline{toc}{authors}{#1}%
{\bfseries#1}\vskip35pt}
\titleformat{\chapter}[display]
{\normalfont\huge\bfseries}{}{20pt}{\Huge}[\addvspace{5pt}]
\titlespacing*{\chapter}
{0pt}{10pt}{0pt}
\titlecontents{chapter}
[0pt]{\addvspace{10pt}}{\bfseries}{\bfseries}{}
\begin{document}
\tableofcontents
\chapter{Test chapter one}
\chapaut{The name of the first author, The name of second author and The name of the third author}
\lipsum[1-20]
\chapter{Test chapter two}
\chapaut{The First author and The second author}
\lipsum[1-20]
\end{document}
我想用 chapaut 更改章节,因此它看起来像:
另外,在目录中:
答案1
如果我理解正确的话,你想实现两件事:
在目录中,您希望将该章节的作者列在章节标题之前。
当打印章节时,您还希望在章节标题前显示作者。
我认为这可能会有所帮助,但我确实相信有比这更好的方法,尤其是对于 ToC。
在文本中将作者打印在章节标题上方的另一种方法可能是更改 的定义\chapter
,但有时更改某些命令的定义可能会产生无法预料的副作用,因此只有在您知道自己在做什么时才这样做。这个问题可能会引起人们的兴趣:在同一页上开始新的篇章。
编辑:非常长的章节标题,跨越目录中的多行,现在将在每一行缩进,而不仅仅是第一行。
\documentclass{book}
\usepackage{titletoc}
\usepackage{lipsum}% just to generate some text
% This part changes how chapters are displayed in the Table of COntents
\titlecontents{chapter}
[0pt]% Left margin, optional
{}% Code insertet above
{\bfseries}% Numbered-entryformat
{\bfseries}% Numberless-format
{\contentspage\vskip1.5ex} %Below code, here: add dotfill and pagenumber for entry, and some vertical space between entries
% Custom command to keep the author on the same page of chaptertitle, and above it.
\newcommand{\chapterAndAuthor}[2]{%
% Takes the following input
% #1: Author
% #2: Chaptertitle
\clearpage%
% Minipage to keep the author and chaptertitle on same page
\noindent\begin{minipage}{\textwidth}
% Set the author style
{\bfseries#1}
% Bring the chaptertitle a bit closer to the authrotitle
\vspace{-3\baselineskip}
% Add an entry to the Table of Contents, with the name of the author in italics and the chapter title
\addcontentsline{toc}{chapter}{{\normalfont\itshape #1}\vspace{1ex}\newline%
%To make long chapter titles spanning multiple lines indent on each line, a \parbox is created. This is siimply a box holding a wrapped paragraph at a certain length. Also, we need to move the dotfill here.
\hspace*{1em}\protect{\parbox[b]{\textwidth}{#2 \dotfill}}}
% Print the chapter
\chapter*{#2}
\end{minipage}
}
\begin{document}
\tableofcontents
\clearpage
\chapterAndAuthor{The name of the first author, The name of second author and The name of the third author}{Test Chapter One is really long, and I wouldn't really bother to read it as I am falling asleep}
\lipsum[1-20]
\chapterAndAuthor{John Doe}{Test Chapter Two}
\lipsum[1-20]
\end{document}