2

I'm relatively new to LaTeX — I haven't really gotten into formatting things too deeply until around a month ago although I've used it for longer — so I don't know how I could format a couple of things in a document I'm doing. Here's my question: How do I format the Table of Contents to appear similar to this photo:

enter image description here

I really like the flow of this Table of Contents (I know, technically this was meant to be an Index) and would really like to know if something like this is possible in LaTeX.

1 Answers1

3

This is some reuse of two different codes I wrote a while ago (and which reminds me the plan to make a package out of it ;-))

(See Redefining \listoffigures and \listoftables as tables and Chapter style for a book of complied articles for the extended versions of the 'old' codes)

I've defined an \authortableofcontents command and redefined \chapter 'slightly' to have an additional optional argument (see the usage in the code) and some key-values to configure the appearance of the entries in the Author ToC.

The author ToC itself is a longtable, making pakebreaks easier. I chose longtable to provide the long vertical rule.

\documentclass{book}

\usepackage{xcolor}
\usepackage{xkeyval}
\usepackage{xparse}
\usepackage{longtable}

\usepackage{array}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}

\makeatletter
\let\latex@chapter\chapter

\def\latex@starttoc#1{%
  \begingroup
  \makeatletter
  \begin{longtable}{@{}R{\@pnumwidth}|p{0.8\linewidth}@{}}
    \@input{\jobname.#1}%
  \end{longtable}
  \if@filesw
  \expandafter\newwrite\csname tf@#1\endcsname
  \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
  \fi
  \@nobreakfalse
  \endgroup
}



\newcommand{\NoNameAuthor}{Unknown}
\newcommand{\authortocname}{List of Authors}

\newcommand{\AuthorTocSectionDefaultOrder}{subtitle,author,date,journal,url} % Default sections 

\NewDocumentCommand{\DeclareArticleSection}{m}{%
  \define@key{authortoc}{#1}{%
    \expandafter\def\csname kvauthortoc#1\endcsname{##1}
  }%
  \define@key{authortoc}{#1style}{%
    \expandafter\def\csname kvauthortoc#1style\endcsname{##1}
  }%
}



\define@key{authortoc}{order}[]{%
  \def\KVAuthorTocOrder{#1}%
}

\DeclareArticleSection{title}
\DeclareArticleSection{author}
\DeclareArticleSection{pagenumber}
%\DeclareArticleSection{date}


\def\@makechapterhead#1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 20\p@
  }
}




\NewDocumentCommand{\AddAuthorName}{mmm}{%
  \addtocontents{autoc}{\authortoctext{#1}{#2}{#3}}%
}




\newcommand{\authortableofcontents}{%
  \chapter*{\authortocname
    \@mkboth{%
      \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
  \latex@starttoc{autoc}%
}


\DeclareRobustCommand\authortoctext[3]{%
  #3 & #1 \\ & #2 \\[1ex]
}

\RenewDocumentCommand{\chapter}{somO{}}{%
  \begingroup
  \setkeys{authortoc}{author={\NoNameAuthor},#4}%
  \IfBooleanTF{#1}{%
    \latex@chapter*{#3}%
  }{%
    \IfValueTF{#2}{%
      \latex@chapter[#2]{#3}
      \AddAuthorName{\kvauthortoctitlestyle{#2}}{\kvauthortocauthorstyle{\kvauthortocauthor}}{\kvauthortocpagenumberstyle{\thepage}}%
    }{% 
      \latex@chapter[#3]{#3}
     \AddAuthorName{\kvauthortoctitlestyle{#3}}{\kvauthortocauthorstyle{\kvauthortocauthor}}{\kvauthortocpagenumberstyle{\thepage}}%
    }%
  }%
  \endgroup
}
\makeatother


\newcommand{\DefaultAuthorStyle}[1]{%
{\normalsize \itshape #1}
}

\newcommand{\DefaultPagenumberStyle}[1]{%
{\bfseries \color{blue} #1}
}

\newcommand{\DefaultTitleStyle}[1]{%
{\bfseries #1}
}


\presetkeys{authortoc}{authorstyle=\DefaultAuthorStyle, 
  titlestyle={\DefaultTitleStyle},
  pagenumberstyle=\DefaultPagenumberStyle}{}


\begin{document}
\authortableofcontents
\tableofcontents


\chapter{The Fellowship of the Ring}[author={J. R. R. Tolkien}]

\chapter{The Two Towers}[author={J.R.R. Tolkien}, authorstyle={\color{red}}]

\chapter{The Return of the King}[author={J.R.R. Tolkien}, pagenumberstyle={\bfseries \color{brown}}]


\chapter[High Castle]{The man in the high castle}[author={J. P. Dick}, pagenumberstyle={\bfseries \color{brown}}]


\end{document}

enter image description here