所以目前,将表格和图形整合到目录中的唯一方法是将它们设置在\tableofcontents
使用\listoffigures
和之后\listoftables
。我的教授要求在一份报告中将它们缩进目录中。
以下是该文件的代码副本:
\documentclass[11pt, A4]{article}
\usepackage{graphicx}
\usepackage{booktabs}
\begin{document}
\addcontentsline{toc}{section}{Table of contents}
\tableofcontents
\listoftables
\listoffigures
\newpage
\section{First Section}
\begin{figure}[!h]
\includegraphics[height=3cm]{image}
\caption{This is an image}
\label{img}
\end{figure}
\section{Second Section}
\begin{table}[!h]
\caption{Just a table}
\label{tabl}
\begin{center}
\begin{tabular}{l|l|c}
\toprule
& title & \\
\toprule
a & b & c \\
\hline
d & e & f \\
\hline
g & h & i
\end{tabular}
\end{center}
\end{table}
\end{document}
答案1
tocbasic
以下是对于图表条目(以及目录中的目录条目)格式的建议:
\documentclass[11pt, a4]{article}
\makeatletter
\renewcommand*{\ext@figure}{toc}
\renewcommand*{\ext@table}{toc}
\makeatother
\usepackage{tocbasic}
\addtotoclist[\jobname]{toc}
\renewcommand*\tableofcontents{\listoftoc[{\contentsname}]{toc}}
\setuptoc{toc}{totoc}% TOC entry in TOC
\newcommand\entrywithprefix[2]{\hfill#1~#2 - }
\DeclareTOCStyleEntry[
numwidth=6em,
entrynumberformat=\entrywithprefix{\figurename}
]{tocline}{figure}
\DeclareTOCStyleEntry[
numwidth=6em,
entrynumberformat=\entrywithprefix{\tablename}
]{tocline}{table}
\usepackage{graphicx}
\usepackage{booktabs}
\begin{document}
\tableofcontents
\clearpage
\section{First Section}
\begin{figure}[htbp]
\includegraphics[height=3cm]{example-image-a}
\caption{This is an image}
\label{img1}
\end{figure}
\begin{figure}[htbp]
\includegraphics[height=3cm]{example-image-b}
\caption{This is another image}
\label{img2}
\end{figure}
\begin{table}[htbp]
\caption{Just a table in first section}
\label{tabl}
\begin{center}
\begin{tabular}{l|l|c}
\toprule
& title & \\
\toprule
a & b & c \\
\hline
d & e & f \\
\hline
g & h & i
\end{tabular}
\end{center}
\end{table}
\section{Second Section}
\begin{table}[htbp]
\caption{Just a table in second section}
\label{tabl2}
\begin{center}
\begin{tabular}{l|l|c}
\toprule
& title & \\
\toprule
a & b & c \\
\hline
d & e & f \\
\hline
g & h & i
\end{tabular}
\end{center}
\end{table}
\begin{figure}[htbp]
\includegraphics[height=3cm]{example-image-a}
\caption{This is an image in second section}
\label{img3}
\end{figure}
\end{document}
结果:
答案2
\documentclass[11pt, a4paper]article}
\usepackage{graphicx}
\usepackage{booktabs}
\makeatletter
\def\ext@figure {toc}
\def\ext@table {toc}
\makeatother
\begin{document}
\addcontentsline{toc}{section}{Table of contents}
\tableofcontents
%\listoftables
%\listoffigures
\newpage
\section{First Section}
\begin{figure}[htbp]
\includegraphics[height=3cm]{example-image-a}
\caption{This is an image}
\label{img1}
\end{figure}
\begin{figure}[htbp]
\includegraphics[height=3cm]{example-image-b}
\caption{This is another image}
\label{img2}
\end{figure}
\begin{table}[htbp]
\caption{Just a table in first section}
\label{tabl}
\begin{center}
\begin{tabular}{l|l|c}
\toprule
& title & \\
\toprule
a & b & c \\
\hline
d & e & f \\
\hline
g & h & i
\end{tabular}
\end{center}
\end{table}
\section{Second Section}
\begin{table}[htbp]
\caption{Just a table in second section}
\label{tabl2}
\begin{center}
\begin{tabular}{l|l|c}
\toprule
& title & \\
\toprule
a & b & c \\
\hline
d & e & f \\
\hline
g & h & i
\end{tabular}
\end{center}
\end{table}
\begin{figure}[htbp]
\includegraphics[height=3cm]{example-image-a}
\caption{This is an image in second section}
\label{img3}
\end{figure}
\end{document}
更新
为了实现这一点:
在序言中使用它:
\makeatletter
\def\ext@figure{toc}
\def\ext@table {toc}
\let\originalnumberline\numberline
\def\l@figure{\def\numberline##1{\makebox[2cm][l]{Figure\hrulefill##1: }%
\global\let\numberline\originalnumberline}%
\l@subsection}
\def\l@table{\def\numberline##1{\makebox[2cm][l]{Table\hrulefill##1: }%
\global\let\numberline\originalnumberline}%
\l@subsection}
\makeatother