2

I want to include the author name before the chapter title. I am using the following:

\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}

I want to change chapter with chapaut, so it will look like:

enter image description here

Also, in the table of contents:

enter image description here

Wings
  • 131
mvp285286
  • 289
  • drives me nuts, not sure want you mean. Can you please show me a code example – mvp285286 May 29 '16 at 07:18
  • Is the problem resolved? – Runar May 29 '16 at 20:51
  • thank you for your example. But my problem isn't solved yet. Your code is good, but very complex :-) Is it possible to change my code, I just want to change the chapter with the author name like the img above – mvp285286 May 30 '16 at 14:30
  • I simplified the code, removed some unused packages and some other code, and added a lot of comments to make sense of the code. Does it help? – Runar May 30 '16 at 20:55
  • awesome! thx, it works fine – mvp285286 May 31 '16 at 09:49
  • hopefully my last question :-) If the title of the chapter (Test chapter one) is longer than just one row, the indent is missing. Is it possible to change it "\newline\hspace*{1em}#2" for more than one row? – mvp285286 May 31 '16 at 12:34
  • I made the change to the code now. I also added some vertical space for between entries, and for between author and chapter title in the table of contents. Adjust this for your needs. – Runar May 31 '16 at 17:03
  • thx, looks great. But the code below do not create a pdf file. The compiler says "no errors" but won't create a pdf file. does this code give you a pdf file? Can't see any mistake :-( – mvp285286 May 31 '16 at 18:08
  • works fine here. new code should not have made any changes that could affect the stability of the code. – Runar May 31 '16 at 20:02
  • not working for me. The issue is with the parbox, if I comment the parbox, it create a pdf file, but not correctly. Is there any other way to solve it? – mvp285286 Jun 01 '16 at 09:42
  • I have no idea why a \parboxwould cause errors. Are you sure you copied the code correctly? If you keep having trouble with this, I would suggest starting a new question regarding this, using the code and linking to this question. Also, please change your username to something a bit more human. – Runar Jun 01 '16 at 09:55
  • alright, thank you! I have to write \protect\parbox then it is working for me too :-). Is it possible to put the page number behind the dots? (if the chapter name is really long, it puts the page number in the middle of the box, as you see below with page "2") – mvp285286 Jun 01 '16 at 11:16
  • in this solution, we will have in the in the contentslist: "The name of the first author, The name of second author and The name of the third author author1ex [b] Test chapter" in the second chapter: "The name of the second author1ex [b]TestChapter two to.44.em". Is it possible to remove the"1ex [b]" and "1ex [b]" from the contentsmenu? And is it possible to do a vspace or something else in the preamble after chapterAndAuthor. Currently i will do it like this: \chapterAndAurthor(text) \vspace{0.84cm} – mvp285286 Jun 20 '16 at 08:09
  • I don't run into those problems here. Maybe post a new question, if you haven't already, regarding this, as I cannot reproduce your error here. – Runar Jun 20 '16 at 10:57

1 Answers1

5

if I understand you correctly, you want to achieve two things:

In the Tabel of Contents, you would like the author(s) of that chapter to be listed before the title of the chapter.

When the chapter is printed, you would also here, like to have the author(s) before the chapter title.

I think this might help, but I do believe there is a better way to do it, than this, especially for the ToC.

One other way to print the authors on top of the chaptertitle in the text, might be to change the definition of \chapter, but sometimes changing the definition of certain commands might have unforeseen sideeffects, so only do that if you know what you are doing. This question might be of interest: Start new chapter on same page.

EDIT: Really long chaptertitles, spanning multiple lines in the toc, will now be indentet on every line, instead of only the first.

\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}

enter image description here Chapter title

Runar
  • 6,082