4

So currently, the only way to integrate tables and figure in table of contents is to have them setup after the \tableofcontents using \listoffigures and \listoftables. My professor asked for a report to have those indented in the table of contents.

Basically, I need to achieve this: What I want to achieve but I only seem to be able to achieve this: What I currently get

Here is a copy of my code for this file:

\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}

Here is what the rest of the document looks like: enter image description here

5

Here is a suggestion using tocbasic for the format of the figure and table entries (and for the entry of the TOC in the TOC):

\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}

Result:

enter image description here

  • Right now though, tables are labelled as figures and figures as tables... They just need to be switched right after {tocline}. – Benjamin Chausse Oct 24 '18 at 1:16
  • Oops. I have corrected that now. – esdd Oct 24 '18 at 6:34
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}

enter image description here

update

To obtain this:

enter image description here

use this in preamble:

\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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.