![从回忆录类翻译成漂亮表格的书类](https://linux22.com/image/336205/%E4%BB%8E%E5%9B%9E%E5%BF%86%E5%BD%95%E7%B1%BB%E7%BF%BB%E8%AF%91%E6%88%90%E6%BC%82%E4%BA%AE%E8%A1%A8%E6%A0%BC%E7%9A%84%E4%B9%A6%E7%B1%BB.png)
Gonzalo Medina 漂亮的 TOC/LOF/LOT(回忆录类)可以在以下网址找到精美图表清单和表格清单。如果将类切换到书籍类,则会产生 187 条错误消息。有没有办法将此代码转换为书籍类?
\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 https://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}}}
%%%% End of Pretty ToC
\settocdepth{subsection}
\setsecnumdepth{subsection}
% redefinitions for figure entries
\renewcommand\cftfigurefont{\sffamily\color{black}}
\renewcommand\cftfigurepagefont{\sffamily\itshape\color{blue}}
\renewcommand\cftfigureleader{\nobreak}
\renewcommand\cftfiguredotsep{\cftnodots}
\renewcommand\cftfigureafterpnum{\hspace*{\fill}}
\setlength\cftfigurenumwidth{12em}
\cftsetindents{figure}{6em}{3em}
\renewcommand\cftfigureformatpnum[1]{%
\hskip1em\hbox to \@pnumwidth{{\cftfigurepagefont #1\hfill}}}
% redefinitions for table entries
\renewcommand\cfttablefont{\sffamily\color{black}}
\renewcommand\cfttablepagefont{\sffamily\itshape\color{blue}}
\renewcommand\cfttableleader{\nobreak}
\renewcommand\cfttabledotsep{\cftnodots}
\renewcommand\cfttableafterpnum{\hspace*{\fill}}
\setlength\cfttablenumwidth{12em}
\cftsetindents{table}{6em}{3em}
\renewcommand\cfttableformatpnum[1]{%
\hskip1em\hbox to \@pnumwidth{{\cfttablepagefont #1\hfill}}}
\usepackage{etoolbox} % or xpatch
% the following code adds chapter information into the LoF
% for chapters containing figures
% initial definitions of the chapter info (name and number)
\def\thischaptertitle{}\def\thischapternumber{}
\newtoggle{noFigs}
\apptocmd{\@chapter}%
{\gdef\thischaptertitle{#2}\gdef\thischapternumber{\thechapter}%
\global\toggletrue{noFigs}}{}{}
% the figure environment does the job: the first time it is used after a \chapter command,
% it writes the information of the chapter to the LoF
\AtBeginDocument{%
\AtBeginEnvironment{figure}{%
\iftoggle{noFigs}{
\addtocontents{lof}{\protect\contentsline {chapter}%
{\protect\numberline {\large\color{cyan}\@chapapp~\thischapternumber}{\thischaptertitle}}{}{} }
\global\togglefalse{noFigs}
}{}
}%
}
% the following code adds chapter information into the LoT
% for chapters containing tables
\newtoggle{noTabs}
\apptocmd{\@chapter}%
{\gdef\thischaptertitle{#2}\gdef\thischapternumber{\thechapter}%
\global\toggletrue{noTabs}}{}{}
% the table environment does the job: the first time it is used after a \chapter command,
% it writes the information of the chapter to the LoT
\AtBeginDocument{%
\AtBeginEnvironment{table}{%
\iftoggle{noTabs}{
\addtocontents{lot}{\protect\contentsline {chapter}%
{\protect\numberline {\large\color{cyan}\@chapapp~\thischapternumber}{\thischaptertitle}}{}{} }
\global\togglefalse{noTabs}
}{}
}%
}
% include after the change above (very important!)
\usepackage{titletoc}
\def\@endpart{
%
\vfil
\textcolor{red}{\hrule height 1.5 pt}
\setcounter{tocdepth}{0}
\startcontents[parts]
\printcontents[parts]{}{0}{} % change 0 to 1 etc. for more detail and vice versa
\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
hidelinks=true,
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=aau-purple % color of external links
}
\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{https://tex.stackexchange.com/posts/169068/edit} \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{https://tex.stackexchange.com/posts/169068/edit}}} \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}
\chapter{A test chapter}
\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}