当我向目录(TOC)和表格表(TOT)添加行时,出现了两个问题:
- 目录行编号不正确。
- TOT 线上不显示 TOT。
知道如何修复吗?
%!TEX TS-program = pdflatex
\documentclass[10pt,a4paper]{book}
\usepackage{array}
%------------
\newcommand{\SampleTable}{
\begin{table}
\caption{Title of Sample Table}
\begin{tabular}{ l c r }
1 & 2 & 3 \\
\end{tabular}
\end{table}
}
%------------
\begin{document}
\frontmatter
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\tableofcontents
\newpage
\section{section one}
\subsection{subsection one}
\setcounter{subsubsection}{0}
\addcontentsline{toc}{subsubsection}{line added to TOC: subsubsection one}
\addcontentsline{tot}{subsubsection}{line added to TOT: subsubsection one}
\addcontentsline{toc}{subsubsection}{line added to TOC: subsubsection two}
\addcontentsline{tot}{subsubsection}{line added to TOT: subsubsection two}
\subsubsection{subsubsection after addcontentsline: three}
\SampleTable
\backmatter
\listoftables
\end{document}
答案1
以下是两个答案以及最终的代码:
正如 Werner 提到的,\addcontentsline 不包含根据添加行的级别(例如:子子节)添加的行的编号。因此,我们必须在计数器的帮助下添加数字(章节的值、节的值、子节的值、子子节的值)(请参阅http://en.wikibooks.org/wiki/LaTeX/Counters)。
\addtocounter{subsubsection}{1} \addcontentsline{toc}{subsubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}.\arabic{subsubsection}~~ line added to TOC: subsubsection one}
Werner 指出了一个更好的选择(下面的评论):\protect\numberline{\thesubsubsection}
\addcontentsline{toc}{subsubsection}{\protect\numberline{\thesubsubsection} line added to TOC: subsubsection one}
确实,TOT 并不存在,但“lot”存在。
%!TEX TS-program = pdflatex \documentclass[10pt,a4paper]{book} \usepackage{array} %------------ \newcommand{\SampleTable}{ \begin{table} \caption{Title of Sample Table} \begin{tabular}{ l c r } 1 & 2 & 3 \\ \end{tabular} \end{table} } %------------ \begin{document} \frontmatter \setcounter{secnumdepth}{5} \setcounter{tocdepth}{5} \tableofcontents \newpage \part{part one} \chapter{chapter one} \section{section one} \subsection{subsection one} \addtocounter{subsubsection}{1} \addcontentsline{toc}{subsubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}.\arabic{subsubsection}~~ line added to TOC: subsubsection one} \addtocounter{table}{1} \addcontentsline{lot}{section}{\arabic{table}~~~~ line added to TOT: subsubsection one} \addtocounter{subsubsection}{1} \addcontentsline{toc}{subsubsection}{\arabic{chapter}.\arabic{section}.\arabic{subsection}.\arabic{subsubsection}~~ line added to TOC: subsubsection two} \addtocounter{table}{1} \addcontentsline{lot}{section}{\arabic{table}~~~~ line added to TOT: subsubsection two} \subsubsection{subsubsection after addcontentsline: three} \SampleTable \backmatter \listoftables \end{document} %% Reference on counters: http://en.wikibooks.org/wiki/LaTeX/Counters
以下是 Werner 的更好选择的代码:
%!TEX TS-program = pdflatex
\documentclass[10pt,a4paper]{book}
\usepackage{array}
%------------
\newcommand{\SampleTable}{
\begin{table}
\caption{Title of Sample Table}
\begin{tabular}{ l c r }
1 & 2 & 3 \\
\end{tabular}
\end{table}
}
%------------
\begin{document}
\frontmatter
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\tableofcontents
\newpage
\part{part one}
\chapter{chapter one}
\section{section one}
\subsection{subsection one}
\addtocounter{subsubsection}{1}
\addcontentsline{toc}{subsubsection}{\protect\numberline{\thesubsubsection} line added to TOC: subsubsection one}
\addtocounter{table}{1}
\addcontentsline{lot}{section}{\arabic{table}~~~~ line added to TOT: subsubsection one}
\addtocounter{subsubsection}{1}
\addcontentsline{toc}{subsubsection}{\protect\numberline{\thesubsubsection} line added to TOC: subsubsection two}
\addtocounter{table}{1}
\addcontentsline{lot}{section}{\arabic{table}~~~~ line added to TOT: subsubsection two}
\subsubsection{subsubsection after addcontentsline: three}
\SampleTable
\backmatter
\listoftables
\end{document}
%% Reference on counters: http://en.wikibooks.org/wiki/LaTeX/Counters