2

I would like to know how to use \listoffigures in order to have the titles of (sub-)sections in the list. The result would be something like this:

Section 1  
 Subsection 1.1   
   Figure 1 .......... p1   
   Figure 2 .......... p1   
 Subsection 1.2  
   Figure 3 .......... p2   
etc...

Edit: a short example:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}


\begin{document}

\tableofcontents
\newpage
\listoffigures
\newpage

\section{First section}
\subsection{First subsection of first section}
\subsection{Second subsection of first section}
\begin{figure}[htb!]
  \centering
  \includegraphics[]{Figure_1.pdf}
  \caption[Short caption of Figure 1]{Caption of Figure 1}
  \label{fig:Figure_1}
\end{figure}

\section{Second section}
\subsection{First subsection of second section}
\begin{figure}[htb!]
  \centering
  \includegraphics[]{Figure_2.pdf}
  \caption[Short caption of Figure 2]{Caption of Figure 2}
  \label{fig:Figure_2}
\end{figure}

\end{document}

On the first page there is the table of contents. On the second one there is the list of figures. What I would like is a mix of the two, which would give in this example:

1 First section  
  1.1 First subsection of first section  
  1.2 Second subsection of first section   
      1 Short caption of Figure 1 ..................... 3
2 Second section  
  2.1 First subsection of second section
      2 Short caption of Figure 1 ..................... 3

Thanks in advance for your help,
Pierrot

3
  • 1
    Welcome to TeX.SX! Not a really easy problem!
    – egreg
    Apr 29, 2016 at 12:56
  • what is your document class? can you add a minimal example of your code?
    – touhami
    Apr 29, 2016 at 15:46
  • A per - section (but not subsection) approach can be found in my answer to this question here: tex.stackexchange.com/questions/285554/…
    – user31729
    Apr 29, 2016 at 19:21

2 Answers 2

2

If i understand, here is a solution

\documentclass{article}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@sect}{\addcontentsline}%
                      {\ifnum #2>\c@secnumdepth \else
                      \addtocontents{lof}{%
                      \protect\contentsline{#1}{\protect\numberline{\csname the#1\endcsname}%
                      #7}{}}
                      \fi%
                      \addcontentsline}%
                  {}{}                 
\preto\listoffigures{%
\renewcommand*\l@subsection[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \setlength\@tempdima{2.3em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode %\bfseries
      \advance\leftskip\@tempdima
      \hskip -.8em
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}}
\renewcommand*\l@figure{\@dottedtocline{1}{3.8em}{3.2em}}
\makeatother
\begin{document}
\tableofcontents
\newpage
\listoffigures
\newpage
\section{First section}
\subsection{First subsection of first section}
\subsection{Second subsection of first section}
\begin{figure}[htb!]
\rule{5cm}{1cm}
\caption{Foo1}
\end{figure}
\section{Second section}
\subsection{First subsection of second section}
\begin{figure}[htb!]
\rule{5cm}{1cm}
\caption{Foo4}
\end{figure}
\end{document}

enter image description here

4
  • Won't this add a entry to the list of figures even if there's no figure in the relevant subsection?
    – user31729
    Apr 30, 2016 at 10:34
  • @ChristianHupfer yes, is this unwanted?
    – touhami
    Apr 30, 2016 at 11:13
  • @ChristianHupfer see example of the OP this is what he ask for.
    – touhami
    Apr 30, 2016 at 11:15
  • @touhami: Hm, I don't see this actually. If so, I would have just reposted my other solution from the post I linked above, with some modifications.
    – user31729
    Apr 30, 2016 at 11:23
1

I don't think that it is a good idea. figure don't have a clear subsubsection level. But if you want it: with the koma classes it is is easier:

\documentclass[11pt,a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[demo]{graphicx}
\makeatletter
\renewcommand\addtocentrydefault[3]{%
 \tocbasic@addxcontentsline {toc}{#1}{#2}{#3}%
 \tocbasic@addxcontentsline {lof}{#1}{#2}{#3}}
 \renewcommand\l@figure{\@dottedtocline{1}{3.8em}{1.5em}}
\makeatother
\begin{document}

\tableofcontents
\newpage
\listoffigures
\newpage

\section{First section}
\subsection{First subsection of first section}
\subsection{Second subsection of first section}\subsubsection{blalb}
\begin{figure}[htb!]
  \centering
  \includegraphics[]{Figure_1.pdf}
  \caption[Short caption of Figure 1]{Caption of Figure 1}
  \label{fig:Figure_1}
\end{figure}

\section{Second section}
\subsection{First subsection of second section}
\begin{figure}[htb!]
  \centering
  \includegraphics[]{Figure_2.pdf}
  \caption[Short caption of Figure 2]{Caption of Figure 2}
  \label{fig:Figure_2}
\end{figure}

\end{document}

enter image description here

1
  • Thank you, just like the previous answer it works fine too !
    – PierrotDx
    Apr 30, 2016 at 6:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .