I am new here, but not new to LaTeX.
My question concerns the topic discussed in this thread:
Pretty Table of Contents.
The topic is about how to make a pretty Table of Contens. My question is now, what do I need to do in order to apply the same pretty layout style of the TOC on the LOF and LOT?
How can I override the pretty TOC layout
on LOF
and LOT
?
For your information:
- I have copied my minimal working example from
Gonzalo Medina
in the linked post and modified it a little bit. - I use the
memoir
class for my minimal working example. - I have added a
Part TOC
(just to see if it looks good etc.). However, in my opinion aPart TOC
is only good-looking if it can stay on the same page as the part text. Otherwise, it does not look good, and then one has to consider to put thePart TOC
on the following page. By the way, I do not remember if someone in the community already did post something about making aPart TOC
. In this case: Here you are! 🙂 - My minimal working example uses different colours in the
TOC
andPart TOC
(same colours in both TOCs of course) to make it easier to see what the different code blocks do in the preamble under thePretty TOC
code section. - Be careful when using the
hyperref
package with the\hypersetup
command! Ifcolorlinks
is set totrue
, then the (red) colour in the chapter text in theTOC
disappears. -
Also, be aware about the fact that you then need to colour your URLs manually if you want your URLs to be something else than black when using the
\url{}
command!- [SOLUTION] regarding the URLs is to apply the
\renewcommand{\UrlFont}{\color{cyan}}
(or the colour you would like…) AFTER the\hypersetup
code block in the preamble! If doing so, this will solve the 'lack of URL colour' problem, allowing to use the\url
command as you are used to.
- [SOLUTION] regarding the URLs is to apply the
And here is my minimal working example:
\documentclass[a4paper,11pt,twoside,openright]{memoir}
\usepackage{fixltx2e}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{ae,aecompl}
\usepackage[utf8]{inputenx}
\usepackage{float}
\usepackage{graphicx}
\setlrmargins{*}{*}{1}
\setulmargins{*}{*}{1}
\checkandfixthelayout[nearest]
\usepackage{color}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{mathtools}
\usepackage{hyphenat} % I use it to prevent hyphenation of table of contents items
\usepackage{refcount}
\usepackage{tikz}
\usetikzlibrary{calc}
%%% Do not include titletoc here - do it at the end of the "Pretty TOC" (very important!)
% WHY? Because then in the Part TOC, the next part will be displayed in the very end of that Part TOC! Of course, this will not happen in the very last Part TOC because there is no part after that...
% \usepackage{titletoc}
%%% Pretty TOC
%%%%% adapted from http://tex.stackexchange.com/questions/35825/pretty-table-of-contents/35835
% 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{green}{\vrule width 1.5pt depth 0pt}\hspace*{15pt}}%
\MakeFramed{\advance\hsize-\width\FrameRestore}}%
{\endMakeFramed}
\makeatletter
% a command to circle the part numbers
\newcommand\Circle[1]{\tikz[overlay,remember picture]
\node[draw=blue,circle, text width=18pt,line width=1pt,align=center] {#1};}
% redefinitions for part entries
\renewcommand\cftpartfont{\Large\sffamily\bfseries}
\renewcommand\partnumberline[1]{%
\hbox to \textwidth{\hss\Circle{\textcolor{red}{#1}}\hss}%
\vskip 3.5ex\color{cyan}}
\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{\small\@chapapp~#1}\par\noindent\Large}
\renewcommand\cftchapterfont{\sffamily}
\cftsetindents{chapter}{0pt}{0em}
\renewcommand\cftchapterpagefont{\large\sffamily\bfseries\color{blue}}
\newcommand*{\l@mychap}[3]{%
\def\@chapapp{\large\color{cyan}#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{\color{red}#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\color{black}}
\renewcommand\cftsectionpagefont{\sffamily\itshape\color{blue}}
\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\color{black}}
\renewcommand\cftsubsectionpagefont{\sffamily\itshape\color{blue}}
\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
%%%% End of Pretty ToC
\settocdepth{subsection}
\setsecnumdepth{subsection}
% include after the change above (very important!)
\usepackage{titletoc}
\makeatletter
\def\@endpart{
%
\vfil
\textcolor{red}{\hrule height 1.5 pt}
\setcounter{tocdepth}{0}
\startcontents[parts]
\printcontents[parts]{}{0}{}
\textcolor{red}{\hrule height 1.5 pt}
\par\bigskip
\vfil\newpage
\if@twoside
\if@openright
\null
\thispagestyle{empty}%
\newpage
\fi
\fi
\if@tempswa
\twocolumn
\fi}
\makeatother
%%%
% be careful with the hyperref package; if colorlinks = true, then the (red) color in the chapter text in the TOC and disappears!
\usepackage{varioref,hyperref}
\hypersetup{
bookmarks=true, % show bookmarks bar?
unicode=false, % non-Latin characters in Acrobat’s bookmarks
pdftoolbar=true, % show Acrobat’s toolbar?
pdfmenubar=true, % show Acrobat’s menu?
pdffitwindow=true , % window fit to page when opened
pdfstartview={FitH}, % fits the width of the page to the window
pdftitle={}, % title
pdfauthor={}, % author
pdfsubject={}, % subject of the document
pdfnewwindow=true, % links in new window
colorlinks=false, % false: boxed links; true: colored links
linkcolor=black, % color of internal links (change box color with linkbordercolor)
citecolor=black, % color of links to bibliography
filecolor=black, % color of file links
%urlcolor=cyan % color of external links
}
\renewcommand{\UrlFont}{\color{cyan}} % must come after \hypersetup code block!
\begin{document}
\frontmatter
\tableofcontents*
\cleardoublepage
\listoffigures
\cleardoublepage
\listoftables
\cleardoublepage
\chapter{Foreword}
Be careful about the URLs. Because the colorlinks is set to false (in the hypersetup in the preamble), this is how the URL will look like: \newline
\url{http://tex.stackexchange.com/questions/169068} \newline
\noindent
If you would like to have the URLs in a specific colour, you have to manually colour code them: \newline
{\color{cyan}{\url{http://tex.stackexchange.com/questions/169068}}} \newline
\noindent
However, If you do not care about the chapter text colour in the TOC (if you want it black, which is standard), then the colorlinks can be set to true, which then should colour code the URLs automatically.
\mainmatter
\part{Designing with \TeX\ and \LaTeX}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\chapter{Beginning to learn design with \TeX}
\section{Another test section}
\section{Another test section}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\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}
\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}
\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}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\section{Another test section}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\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}
\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}
\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}
\appendix
\chapter{Test Appendix}
\section{Another test section}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\begin{figure}[H]
\caption[(short) caption that goes to the LOF.]{(long) caption that goes below the figure}
\end{figure}
\section{Another test section with a long title spanning more than one line in the table of contents}
\section{Another test section}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\begin{table}[H]
\caption[(short) caption that goes to the LOT.]{(long) caption that goes below the figure}
\end{table}
\subsection{A test subsection}
\section{Another test section}
\section{Another test section}
\end{document}
And this is how some of it looks like:
Best Answer
I had to provide a different answer since when I tried to edit my previous answer to include the new code, the 30.000 character limit was exceeded.
A little modification suggested in a comment: some information for chapters is automatically included in the LoF (LoT, resp.) only for those chapters containing figures (tables, resp.).
An image of the new resulting LoF:
An image of the new resulting LoT: