# Pretty Table of Contents

I would like to know if it's possible to have a Table of Contents looking like the following, where the number of the page is the big number on the left.

The sections could look like in the following "uggly-font-formatted" example. If someone has a better idea for the sections and subsections...

-
Have a look at this post, it might help get you started –  cmhughes Nov 22 '11 at 22:52
not necessarily related but few ideas here: tex.stackexchange.com/questions/19796/… –  pluton Apr 2 '12 at 2:32
add comment

## 3 Answers

Here's a solution with a redefinition of the \chapter command (as implemented in book.cls) using \parboxes and the leftbar environment from the framed package:

\documentclass{book}
\usepackage{xcolor}
\usepackage{framed}

\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

\renewenvironment{leftbar}{%
\def\FrameCommand{{\color{myyellow}\vrule width 2pt depth 6pt} \hspace{10pt}}%
\MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\endMakeFramed}

\makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
\if@mainmatter
\refstepcounter{chapter}%
\typeout{\@chapapp\space\thechapter.}%
\addtocontents{toc}%
{%
{\protect\parbox{3.5em}{\hfill\Huge\color{myred}\bfseries\thepage}}%
\protect\hspace*{.5em}
\protect\parbox{\dimexpr\linewidth-4em\relax}{%
\protect\begin{leftbar}
{\scshape\small\chaptername~\thechapter}\\\sffamily#1%
\protect\end{leftbar}}\par\noindent
}%
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\else
\addcontentsline{toc}{chapter}{#1}%
\fi
\chaptermark{#1}%
\addtocontents{lof}{\protect\addvspace{10\p@}}%
\addtocontents{lot}{\protect\addvspace{10\p@}}%
\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}
\makeatother

\begin{document}

\tableofcontents

\chapter{Beginning to learn design with \LaTeX}
\chapter{Beginning to learn design with HTML}
\setcounter{page}{13}% just for the example
\chapter{Beginning to learn design with HTML and some other text to span more than one line in the ToC}

\end{document}


The first \parbox will contain the page number; I just reserved space for two-digit numbers (3.5em); for three-digit numbers, the width of this box will have to be increased, and that of the third \parbox will have to be decreased in the same amount.

I've made some improvements and additions to my first solution. Now there will be no problems when loading hyperref (my previous solution was incompatible with hyperref); the modifications to the ToC emtries are now made with the help of the titletoc package; I've also added redefinitions for the section and subsection entries.

\documentclass{book}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{lmodern}

\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

\patchcmd{\tableofcontents}{\contentsname}{\sffamily\contentsname}{}{}

\renewenvironment{leftbar}
{\def\FrameCommand{\hspace{6em}%
{\color{myyellow}\vrule width 2pt depth 6pt}\hspace{1em}}%
\MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
}
{\endMakeFramed}

\titlecontents{chapter}
[0em]{\vspace*{2\baselineskip}}
{\parbox{4.5em}{%
\hfill\Huge\sffamily\bfseries\color{myred}\thecontentspage}%
\vspace*{-2.3\baselineskip}\leftbar\textsc{\small\chaptername~\thecontentslabel}\\\sffamily}
{}{\endleftbar}
\titlecontents{section}
[8.4em]
{\sffamily\contentslabel{3em}}{}{}
{\hspace{0.5em}\nobreak\itshape\color{myred}\contentspage}
\titlecontents{subsection}
[8.4em]
{\sffamily\contentslabel{3em}}{}{}
{\hspace{0.5em}\nobreak\itshape\color{myred}\contentspage}

\begin{document}

\tableofcontents

\chapter{Beginning to learn design with \LaTeX}
\section{This is a test section}
\subsection{Long subsection title and some other text to span more than one line}

\newpage\setcounter{page}{123}% just for the example

\chapter{Beginning to learn design with HTML and some other text to span more than one line in the ToC}
\section{This is a test section}
\subsection{Long subsection title and some other text to span more than one line}

\end{document}


As Harish Kumar suggested in a comment, it will be nice to have some decorations for parts too. This new variation explores one possibility for these decorations:

\documentclass{book}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{tikz}
\usepackage{titletoc}
\usepackage{etoolbox}
\usepackage{lmodern}

% definition of some personal colors
\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

% command for the circle for the number of part entries
\newcommand\Circle[1]{\tikz[overlay,remember picture]
\node[draw,circle, text width=18pt,line width=1pt] {#1};}

% patching of \tableofcontents to use sans serif font for the tile
\patchcmd{\tableofcontents}{\contentsname}{\sffamily\contentsname}{}{}
% patching of \@part to typeset the part number inside a framed box in its own line
% and to add color
\makeatletter
\patchcmd{\@part}
{\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}}
{\addtocontents{toc}{\protect\addvspace{20pt}}
\addcontentsline{toc}{part}{\huge{\protect\color{myyellow}%
\setlength\fboxrule{2pt}\protect\Circle{%
\hfil\thepart\hfil%
}%
}\\[2ex]\color{myred}\sffamily#1}}{}{}

%\patchcmd{\@part}
%  {\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}}
%  {\addtocontents{toc}{\protect\addvspace{20pt}}
%    \addcontentsline{toc}{part}{\huge{\protect\color{myyellow}%
%      \setlength\fboxrule{2pt}\protect\fbox{\protect\parbox[c][1em][c]{1.5em}{%
%        \hfil\thepart\hfil%
%      }}%
%    }\\[2ex]\color{myred}\sffamily#1}}{}{}
\makeatother

% this is the environment used to typeset the chapter entries in the ToC
% it is a modification of the leftbar environment of the framed package
\renewenvironment{leftbar}
{\def\FrameCommand{\hspace{6em}%
{\color{myyellow}\vrule width 2pt depth 6pt}\hspace{1em}}%
\MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
}
{\endMakeFramed}

% using titletoc we redefine the ToC entries for parts, chapters, sections, and subsections
\titlecontents{part}
[0em]{\centering}
{\contentslabel}
{}{}
\titlecontents{chapter}
[0em]{\vspace*{2\baselineskip}}
{\parbox{4.5em}{%
\hfill\Huge\sffamily\bfseries\color{myred}\thecontentspage}%
\vspace*{-2.3\baselineskip}\leftbar\textsc{\small\chaptername~\thecontentslabel}\\\sffamily}
{}{\endleftbar}
\titlecontents{section}
[8.4em]
{\sffamily\contentslabel{3em}}{}{}
{\hspace{0.5em}\nobreak\itshape\color{myred}\contentspage}
\titlecontents{subsection}
[8.4em]
{\sffamily\contentslabel{3em}}{}{}
{\hspace{0.5em}\nobreak\itshape\color{myred}\contentspage}

\begin{document}

\tableofcontents

\part{Designing with \LaTeX}

\chapter{Beginning to learn design with \LaTeX}
\section{This is a test section}
\subsection{Long subsection title and some other text to span more than one line}

\newpage\setcounter{page}{123}% just for the example

\part{Designing with HTML}

\chapter{Beginning to learn design with HTML and some other text to span more than one line in the ToC}
\section{This is a test section}
\subsection{Long subsection title and some other text to span more than one line}

\end{document}


Unfortunately, if hyperref is loaded, the part entry formatting will be lost (I'll have to think about this).

## Memoir document class

In some of the comments below there are suggestions to implement the style using the memoir document class. Below I present two variations.

### First variation

This version works for numbered and unnumbered parts, chapters, sections and subsections, and cooperates with hyperref:

\documentclass{memoir}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{tikz}
\usepackage[colorlinks,linkcolor=black]{hyperref}

% colors to be used
\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

% a modification of the leftbar environment defined by the framed package
% will be used to place a vertical colored bar separating the page number and the
% title in chapter entries
\renewenvironment{leftbar}{%
\def\FrameCommand{\textcolor{myyellow}{\vrule width 2pt depth 6pt}\hspace*{15pt}}%
\MakeFramed{\advance\hsize-\width\FrameRestore}}%
{\endMakeFramed}

% a command to circle the part numbers
\newcommand\Circle[1]{\tikz[overlay,remember picture]
\node[draw=myyellow,circle, text width=18pt,line width=1pt,align=center] {#1};}

% redefinition of the name of the ToC
\renewcommand\printtoctitle[1]{\HUGE\sffamily\bfseries#1}

\makeatletter
% redefinitions for part entries
\renewcommand\cftpartfont{\Huge\sffamily\bfseries\hfill}
\renewcommand\partnumberline[1]{%
\hbox to \textwidth{\hss\Circle{\textcolor{myyellow}{#1}}\hss}%
\vskip3.5ex\par\hfill\color{myred}}
\renewcommand*\cftpartformatpnum[1]{\hfill}
\renewcommand\cftpartafterpnum{\vskip1ex}

% redefinitions for chapter entries
\renewcommand\chapternumberline[1]{\mbox{\small\@chapapp~#1}\par\noindent\Large}
\renewcommand\cftchapterfont{\sffamily}
\cftsetindents{chapter}{0pt}{0em}
\renewcommand\cftchapterpagefont{\Huge\sffamily\bfseries\color{myred}}

\newcommand*{\l@mychap}[3]{%
\def\@chapapp{#3}
\vskip1ex%
\par\noindent\begin{minipage}{\textwidth}%
\parbox{4.5em}{%
\hfill{\cftchapterpagefont#2}%
}\hspace*{1.5em}%
\parbox{\dimexpr\textwidth-4.5em-15pt\relax}{%
\leftbar\cftchapterfont#1\hspace{1sp}\endleftbar%
}%
\end{minipage}\par%
}

\renewcommand*{\l@chapter}[2]{%
\l@mychap{#1}{#2}{\chaptername}%
}

\renewcommand*{\l@appendix}[2]{%
\l@mychap{#1}{#2}{\appendixname}%
}

% redefinitions for section entries
\renewcommand\cftsectionfont{\sffamily}
\renewcommand\cftsectionpagefont{\sffamily\itshape\color{myred}}
\renewcommand\cftsectionleader{\nobreak}
\renewcommand\cftsectiondotsep{\cftnodots}
\renewcommand\cftsectionafterpnum{\hspace*{\fill}}
\setlength\cftsectionnumwidth{12em}
\cftsetindents{section}{6em}{3em}
\renewcommand\cftsectionformatpnum[1]{%
\hskip1em\hbox to \@pnumwidth{{\cftsectionpagefont #1\hfill}}}

% redefinitions for subsection entries
\renewcommand\cftsubsectionfont{\sffamily}
\renewcommand\cftsubsectionpagefont{\sffamily\itshape\color{myred}}
\renewcommand\cftsubsectionleader{\nobreak}
\renewcommand\cftsubsectiondotsep{\cftnodots}
\renewcommand\cftsubsectionafterpnum{\hspace*{\fill}}
\setlength\cftsubsectionnumwidth{12em}
\cftsetindents{subsection}{9em}{3em}
\renewcommand\cftsubsectionformatpnum[1]{%
\hskip1em\hbox to \@pnumwidth{{\cftsubsectionpagefont #1\hfill}}}
\makeatother

\settocdepth{subsection}
\setsecnumdepth{subsection}

\begin{document}

\phantomsection
\addcontentsline{toc}{part}{\textcolor{myred}{Test Unnumbered Part}}
\part*{Test Unnumbered Part}

\tableofcontents*

\part{Designing with \LaTeX}
\chapter{Beginning to learn design with \LaTeX}
\section{A test section}
\subsection{A test subsection}
\phantomsection
\addcontentsline{toc}{section}{Test unnumbered section}
\section*{Test unnumbered section}

\newpage\setcounter{page}{123}% just for the example

\part{Designing with HTML}
\chapter{Beginning to learn design with HTML and some other text to span more than one line}
\section{Another test section}

\chapter*{Test Unnumbered Chapter}
\phantomsection
\addcontentsline{toc}{chapter}{Test Unnumbered Chapter}

\end{document}


### Second variation

projetmbc has suggested in an edit to the original question a different formatting when including sections and subsections; this is a first attempt to produce this new layout.

Some remarks:

1. The \StartMark command must be placed before each \chapter command and \EndMark must be placed immediately after the last sectional unit of a chapter that will be included in the ToC:

2. Page breaks can occur for the sectional units associated to a chapter and will be dealt automatically.

3. The code needs at least three runs.

The code:

\documentclass{memoir}
\usepackage[T1]{fontenc}
\usepackage{refcount}
\usepackage[colorlinks,linkcolor=black]{hyperref}
\usepackage{tikz}
\usetikzlibrary{calc}

% colors to be used
\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

% a command to circle the part numbers
\newcommand\Circle[1]{\tikz[overlay,remember picture]
\node[draw=myyellow,circle, text width=18pt,line width=1pt,align=center] {#1};}

% redefinition of the name of the ToC
\renewcommand\printtoctitle[1]{\HUGE\sffamily\bfseries\color{myred}#1}

\makeatletter
% redefinitions for part entries
\renewcommand\cftpartfont{\Huge\sffamily\bfseries}
\renewcommand\partnumberline[1]{%
\hbox to \textwidth{\hss\Circle{\textcolor{myyellow}{#1}}\hss}%
\vskip3.5ex\color{myred}}

\renewcommand*{\l@part}[2]{%
\ifnum \c@tocdepth >-2\relax
\cftpartbreak
\begingroup
{\interlinepenalty\@M
\leavevmode
\settowidth{\@tempdima}{\cftpartfont\cftpartname}%
\addtolength{\@tempdima}{\cftpartnumwidth}%
\let\@cftbsnum \cftpartpresnum
\let\@cftasnum \cftpartaftersnum
\let\@cftasnumb \cftpartaftersnumb
\advance\memRTLleftskip\@tempdima \null\nobreak\hskip -\memRTLleftskip
\centering{\cftpartfont#1}\par%
}
\nobreak
\global\@nobreaktrue
\everypar{\global\@nobreakfalse\everypar{}}%
\endgroup
\fi}

% redefinitions for chapter entries
\renewcommand\chapternumberline[1]{\mbox{\Large\@chapapp~#1}\par\noindent}
\renewcommand\cftchapterfont{\Large\sffamily}
\cftsetindents{chapter}{0pt}{0pt}
\renewcommand\cftchapterpagefont{\HUGE\sffamily\bfseries\color{myred}}

\newcommand*{\l@mychap}[3]{%
\def\@chapapp{#3}\vskip1ex%
\par\noindent\begin{minipage}{\textwidth}%
\parbox{4.7em}{%
\hfill{\cftchapterpagefont#2}%
}\hspace*{1.5em}%
\parbox{\dimexpr\textwidth-4.7em-15pt\relax}{%
\cftchapterfont#1%
}%
\end{minipage}\par\vspace{2ex}%
}

\renewcommand*{\l@chapter}[2]{%
\l@mychap{#1}{#2}{\chaptername}%
}

\renewcommand*{\l@appendix}[2]{%
\l@mychap{#1}{#2}{\appendixname}%
}

% redefinitions for section entries
\renewcommand\cftsectionfont{\sffamily}
\renewcommand\cftsectionpagefont{\sffamily\itshape\color{myred}}
\renewcommand{\cftsectionleader}{\nobreak}
\renewcommand{\cftsectionafterpnum}{\cftparfillskip}
\cftsetindents{section}{7.5em}{3em}
\renewcommand\cftsectionformatpnum[1]{%
\hskip1em\hbox to 4em{{\cftsectionpagefont #1\hfill}}}

% redefinitions for subsection entries
\renewcommand\cftsubsectionfont{\sffamily}
\renewcommand\cftsubsectionpagefont{\sffamily\itshape\color{myred}}
\renewcommand\cftsubsectionleader{\nobreak}
\renewcommand{\cftsubsectionafterpnum}{\cftparfillskip}
\renewcommand\cftsubsectiondotsep{\cftnodots}
\cftsetindents{subsection}{10.5em}{3em}
\renewcommand\cftsubsectionformatpnum[1]{%
\hskip1em\hbox to 4em{{\cftsubsectionpagefont #1\hfill}}}
\makeatother

\settocdepth{subsection}
\setsecnumdepth{subsection}

% length to be used when drawing a line from the top of the text area
\newlength\Myhead
\setlength\Myhead{\dimexpr\headheight+\headsep+1in+\voffset+5ex\relax}

% length to be used when drawing a line to the bottom of the text area
\newlength\Myfoot
\setlength\Myfoot{\dimexpr\paperheight-\Myhead-\textheight-\footskip+5ex\relax}

% auxiliary counter to place labels
\newcounter{chapmark}

% Adds a mark and a label at the beginning of each chapter entry in the ToC and draws a line
% from the start of the chapter to the bottom of the text area if the mark
% for the chapter ending lies in a different page than the one from the end of the chapter.
% (the value of tjose pages is calculated using the label)
% Must be used right before each \chapter command
\newcommand\StartMark{%
\addtocontents{toc}{\protect\label{st\thechapmark}%
\protect\begin{tikzpicture}[overlay,remember picture,baseline]
\protect\node [anchor=base] (s\thechapmark) {};%
\ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark} \else
\protect\draw[myyellow,line width=3pt] let \protect\p3= (s\thechapmark),%
\protect\p4 = (current page.south) in %
($(4em,\protect\y3) + (0,-1ex)$) -- ($(4em,\protect\y4) + (0,\protect\the\Myfoot)$);\fi
\protect\end{tikzpicture}\par}%
}

% Adds a mark and a label at the end of each chapter entry in the ToC and draws a line from
% the top of the text area to the ending of the chapter if the mark
% for the chapter ending lies in a different page than the one from the start of the chapter
% if both marks are in the same page, simple draws a line connecting the marks
% (the value of tjose pages is calculated using the label)
% Must be used right after the last sectional unit (that will go to the ToC) belonging to
% a chapter
\newcommand\EndMark{
\addtocontents{toc}{\protect\label{en\thechapmark}%
\protect\begin{tikzpicture}[overlay,remember picture,baseline]
\protect\node [anchor=base] (e\thechapmark) {};
\ifnum\getpagerefnumber{st\thechapmark}=\getpagerefnumber{en\thechapmark}
\protect\draw[myyellow,line width=3pt] let \protect\p1= (s\thechapmark), \protect\p2=(e\thechapmark) in ($(4em,\protect\y1) + (0,-1ex)$) -- ($(4em,\protect\y2) + (0,2ex)$);
\else%
\protect\draw[myyellow,line width=3pt] let \protect\p1= (e\thechapmark), \protect\p2=(current page.north) in ($(4em,\protect\y2) + (0,-\protect\the\Myhead)$) -- ($(4em,\protect\y1) + (0,1.5ex)$);
\fi
\protect\end{tikzpicture}\par}\stepcounter{chapmark}%
}

\begin{document}

\tableofcontents*

\part{Designing with \TeX\ and \LaTeX}

\StartMark
\chapter{Beginning to learn design with \TeX}
\section{Another test section}
\section{Another test section }
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\subsection{A test subsection with a long title spanning more than one line in the table of contents}
\section{Another test section}
\section{Another test section}
\section{Another test section}
\EndMark

\StartMark
\chapter{Beginning to learn design with \LaTeX}
\section{A test section with a long title spanning more than one line in the table of contents}
\subsection{A test subsection}
\subsection{Another test subsection}
\section{A test section}
\phantomsection
\addcontentsline{toc}{section}{Test unnumbered section}
\section*{Test unnumbered section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\EndMark

\newpage\setcounter{page}{123}% just for the example

\part{Designing with HTML}
\StartMark
\chapter{Beginning to learn design with HTML and some other text to span more than one line}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section with a long title spanning more than one line in the table of contents}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\EndMark

\StartMark
\chapter{Beginning to learn design with HTML and some other text to span more than one line}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection with a long title spanning more than one line in the table of contents}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\section{Another test section}
\subsection{A test subsection}
\EndMark

\appendix
\StartMark
\chapter{Test Appendix}
\section{Another test section}
\section{Another test section with a long title spanning more than one line in the table of contents}
\section{Another test section}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\EndMark

\end{document}


The obtained ToC:

-
With your minimal code you make it look easy. Looks great! –  Werner Nov 23 '11 at 0:15
The alignment seems to be a little off on the right hand side. Otherwise, what a beautiful implementation! –  Mark S. Everitt Nov 23 '11 at 11:16
@bobicool: when I have the time I will take a look about using memoir (although I don't use that document class). For the problem with the frenchb option for babel, simply use \shorthandoff{;} before \tableofcontents to temporarily switch off the shorthand action of the character ;. To switch back on the shorthand, you can use \shorthandon{;} after \tableofcontents. –  Gonzalo Medina Apr 2 '12 at 14:19
@bobicool: I've updated my answer providing an implementation for the chapter entries with the memoir document class. –  Gonzalo Medina Apr 8 '12 at 23:21
@dochar: the first one actually took less time (10-15 min.) but is a very restrictive solution. The last one (using memoir and allowing page breaks) took longer (several hours).. and I am still working (whenever I find some free time) on improving the solutions ;-) –  Gonzalo Medina May 1 '12 at 22:36
show 31 more comments

Here is a solution using ConTeXt:

\define[3]\myTOC{% #1=chapter number, #2=chapter text, #3=page
{\ssd #3\hskip.4em}
\framed
[
frame=off,
leftframe=on,
rulethickness=2pt,
framecolor=darkgreen,
loffset=1em,
align=right,
location=bottom,
foregroundstyle=sans,
]
{{\rm\sc Chapter #1}\\#2}
}

\setuplist [chapter]
[
alternative=none,
command=\myTOC,
]

\starttext

\placelist [chapter]

\setnumber[userpage]{10}
\startchapter [title=Beginning to learn design with ConTeXt]
\stopchapter

\startchapter [title=Beginning to learn design with HTML]
\stopchapter

\stoptext


The result looks like this:

However, it is not optimal. It only defines the list style for the chapters. But since you didn't specify anything else, that's all I can do.

The command \setuplist defines the layout of the list in the first argument, here chapter. alternative=none tells the system that you don't want a predefined style, rather than to use the custom command, which defines the appearance. I set the page number to a two-digit value, otherwise it gets confusing, which number belongs to the page and which to the chapter count.

-
This is another great ConTeXt example! What's the use of {\sc Chapter #1} that seems to have lost the Small Caps? –  Werner Nov 22 '11 at 23:28
Yes I saw it too and removed it from the code (and you posted the comment in the mean time ;) Does LM have sans small caps by the way? –  Marco Nov 22 '11 at 23:35
Not that I can see; Read An exploration of the Latin Modern fonts (p 3). –  Werner Nov 22 '11 at 23:45
@Werner According to the doc there are no sans small caps. I changed to roman ones (which in fact is ugly). The fine-tuning is is left for the OP. –  Marco Nov 23 '11 at 0:03
Yes, @Gonzalo's answer reflects the same for LaTeX. Most likely the OP's images is from a PDF screen grab, with the original document constructed in some different publishing software. –  Werner Nov 23 '11 at 0:15
show 1 more comment

I have pached the solution proposed by Marco (1) to allow for starred version of the \chapter command and (2) to prevent wrong pagebreaks which sometimes occured (in Marco's solution) between the pagenumber and the chapter title. For the latter purpose I wrapped the \parbox that contains \thecontentspage and the leftbar environment into the minipage environment.

\usepackage{framed}
\usepackage{titletoc}
\usepackage{etoolbox}
\definecolor{myred}{RGB}{127,0,0}
\definecolor{myyellow}{RGB}{169,121,69}

\patchcmd{\tableofcontents}{\contentsname}{\sffamily\contentsname}{}{}

\renewenvironment{leftbar}
{\def\FrameCommand{\hspace{6em}%
{\color{myyellow}\vrule width 2pt depth 6pt}\hspace{1em}}%
\MakeFramed{\parshape 1 0cm \dimexpr\textwidth-6em\relax\FrameRestore}\vskip2pt%
}
{\endMakeFramed}

\titlecontents{chapter}
[0em]{\vspace*{\baselineskip}}
{%
\begin{minipage}{\textwidth}
\parbox{4.5em}{\hfill\Huge\sffamily\bfseries\color{myred}\thecontentspage}%
\vspace{-2.3\baselineskip}\leftbar{\sffamily\chaptername~\thecontentslabel}\\
\sffamily
}
{%
\begin{minipage}{\textwidth}
\parbox{4.5em}{%
\hfill\Huge\sffamily\bfseries\color{myred}\thecontentspage}%
\vspace{-2.3\baselineskip}\leftbar\textsf{}\\\sffamily}
{\endleftbar\end{minipage}\nopagebreak}[\vskip2pt\nopagebreak]
\titlecontents{section}
[8.4em]
{\sffamily\contentslabel{3em}}{}{}
{\hspace{0.5em}\nobreak\itshape\color{myred}\contentspage}
\titlecontents{subsection}
[8.4em]
{\sffamily\contentslabel{3em}}{}{}
{\hspace{0.5em}\nobreak\itshape\color{myred}\contentspage}

-
This almost works with memoir ... Any chance you might be able to fix it to work with it? –  André Apr 7 '12 at 13:41
The page number of subsubsection is not changed in TOC, please add this feature –  KOF Jan 12 at 22:01
add comment