Page LayoutIndenting when using \addcontentsline{toc}{figure}

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
activematt
Posts: 5
Joined: Sun Mar 27, 2011 9:28 am

Indenting when using \addcontentsline{toc}{figure}

Post by activematt »

I am attempting to add figures to my table of contents using \addcontentsline{toc}{figure} however in the toc they appear left justified. Is there a way to shift the figure right, or a more elegant way of doing this?

Code: Select all

\usepackage[titles,subfigure]{tocloft}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%defines Table of Contents Indents
\renewcommand{\cftsecindent}{0 em}
\renewcommand{\cftsecnumwidth}{2.4 em}

\renewcommand{\cftsubsecindent}{2.4 em}
\renewcommand{\cftsubsecnumwidth}{3.0 em}

\renewcommand{\cftsubsubsecindent}{4.7 em}
\renewcommand{\cftsubsubsecnumwidth}{4.7 em}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newlength\mylength
\settowidth\mylength{figure\hspace*{3em}}
\addtolength\cftfignumwidth{\mylength}
\renewcommand\cftfigpresnum{figure} 


\begin{document}  % START THE DOCUMENT!

\section{Abstract}
\section{Contents}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setcounter{tocdepth}{4}
\tableofcontents
\addtocounter{figure}{4}

\newpage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}
\section{Methods}
\subsection{\large Apparatus}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	\begin{figure}[H]
	  \centering
	  \subfloat{\label{fig:1}\includegraphics[width=6in,height=4in]{Apparatus.png}} \\                
	  \caption{Shaky Table Apparatus Schematic\hspace*{3em}}
	\end{figure}

\addcontentsline{toc}{figure}{Figure 1:Shaky Table Apparatus Schematic}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document} %
Thanks in advance! Im sorry if my post is too lengthy, this is my first! Open to constructive criticism!
Last edited by activematt on Sun Mar 27, 2011 10:01 pm, edited 3 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Indenting when using \addcontentsline{toc}{figure}

Post by localghost »

I have two questions.
  1. Why don't you just use \listoffigures to get a LoF?
  2. Why do you insert a sub-float in a figure environment with only one image?
activematt wrote:[…] Im sorry if my post is too lengthy, this is my first! Open to constructive criticism!
View topic: Avoidable mistakes


Best regards and welcome to the board
Thorsten
activematt
Posts: 5
Joined: Sun Mar 27, 2011 9:28 am

Re: Indenting when using \addcontentsline{toc}{figure}

Post by activematt »

1) I may just include a toc and lof separately, however my professor requested that the figures be listed in the toc, for faster reference.

2) the report will contain many images
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Indenting when using \addcontentsline{toc}{figure}

Post by localghost »

activematt wrote:1) I may just include a toc and lof separately, however my professor requested that the figures be listed in the toc, for faster reference. […]
You have to choose one of the given heading levels to get the figure inserted properly into the ToC (see code below).
activematt wrote:2) the report will contain many images
That's not the point. You don't need to declare a sub-float inside a float if there is only one object (see code below).

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage[titles]{tocloft}
\usepackage{blindtext}

% define ToC indents
\renewcommand{\cftsecindent}{0em}
\renewcommand{\cftsecnumwidth}{2.4em}
\renewcommand{\cftsubsecindent}{2.4em}
\renewcommand{\cftsubsecnumwidth}{3.0em}
\renewcommand{\cftsubsubsecindent}{4.7em}
\renewcommand{\cftsubsubsecnumwidth}{4.7em}

%\newlength\mylength
%\settowidth\mylength{Figure\hspace*{3em}}
%\addtolength\cftfignumwidth{\mylength}
%\renewcommand\cftfigpresnum{Figure} 

\begin{document}
  \tableofcontents

  \blinddocument

  \begin{figure}[!ht]
    \centering
    \rule{0.75\textwidth}{0.5\textwidth}
    \caption{Dummy figure}\label{fig:dummy}
    \addcontentsline{toc}{subsubsection}{\figurename\ \ref{fig:dummy}: Dummy figure}
  \end{figure}
\end{document}
activematt
Posts: 5
Joined: Sun Mar 27, 2011 9:28 am

Indenting when using \addcontentsline{toc}{figure}

Post by activematt »

This Seems To Work Well!

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage[titles]{tocloft}
%\usepackage{blindtext}
\usepackage{graphicx} % For images

% define ToC indents
\renewcommand{\cftsecindent}{0em}
\renewcommand{\cftsecnumwidth}{2.4em}
\renewcommand{\cftsubsecindent}{2.4em}
\renewcommand{\cftsubsecnumwidth}{3.0em}
\renewcommand{\cftsubsubsecindent}{4.7em}
\renewcommand{\cftsubsubsecnumwidth}{4.7em}



\begin{document}
  \tableofcontents

\section{Intro}
  %\blinddocument
  
\subsection{Equipment}

  \begin{figure}[!ht]
    \centering
    \includegraphics[width=6in,height=4in]{Apparatus.png}
    \caption{Apparatus}\label{fig:Apparatus}
    \addcontentsline{toc}{subsubsection}{\figurename\ \ref{fig:Apparatus}: Shaky Table Apparatus}
  \end{figure}
\end{document}
Thx for all the help!
Post Reply