Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I get a “list of figures” of the following type?

List of figures

enter image description here

Exactly, this list of figures is set as a table. I know this cannot be obtained by the command \listoffigures directly, but our thesis needs this format. I can get this type by making a real table and using cross referencing, but I prefer getting it with \listoffigures or other simple commands.

share|improve this question
    
Which documentclass do you use? Do you load any packages which influence the list of figures? Please add a minimal working example (MWE) that illustrates your problem. –  Marco Daniel Apr 18 '12 at 17:01
    
I am sorry. I use '\documentclass{book}'. I just want to get the type talked above. It does not matter what documentclass is used. BTW, my english is very poor, so please forgive me for my syntax error. –  XIAO Lishun Apr 19 '12 at 4:39
add comment

2 Answers 2

up vote 19 down vote accepted

You can try this one; the important code is between \makeatletter and \makeatother

\documentclass{book}
\makeatletter

\renewcommand\listoffigures{%
    \chapter*{\listfigurename}%
      \@mkboth{\MakeUppercase\listfigurename}%
              {\MakeUppercase\listfigurename}%
    \begingroup\let\addvspace\@gobble
    \raggedbottom\offinterlineskip\def\l@figure{\xiao@figure}\parindent\z@
    \hrule
    \vrule\vrule width \z@ height 1.2\ht\strutbox depth 1.2\dp\strutbox
    \makebox[\dimexpr3cm-0.8pt\relax][c]{\bfseries Number}\vrule
    \parbox{\dimexpr\textwidth-6cm}{\normalbaselines\centering {\large\strut}\bfseries Caption{\large\strut}}\vrule
    \makebox[\dimexpr3cm-0.8pt\relax][c]{\bfseries Page}\vrule
    \hrule
    \@starttoc{lof}%
    \endgroup
    }
\def\xiao@figure#1#2{\xiao@figurei#1{#2}}
\long\def\xiao@figurei\numberline#1#2#3{%
  \vrule\vrule width \z@ height 1.2\ht\strutbox depth 1.2\dp\strutbox
  \makebox[\dimexpr3cm-0.8pt\relax][c]{Fig.\ #1}\vrule
  \parbox{\dimexpr\textwidth-6cm}{\normalbaselines\centering {\large\strut}#2{\large\strut}}\vrule
  \makebox[\dimexpr3cm-0.8pt\relax][c]{#3}\vrule
  \hrule
  \hskip-.4pt
  \hrule
  \nobreak
}
\makeatother

\begin{document}
\frontmatter
\listoffigures
\mainmatter
\chapter{A}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\clearpage
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\clearpage
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\clearpage
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\begin{figure}
\caption{Caption which is very
very very very very very very very very
very very very very very very very very
very very very very very very very very
long}
\end{figure}
\begin{figure}
\caption{Caption}
\end{figure}
\end{document}

The compiled example shows also a page break. Here I show only a small part.

enter image description here


Some comments about \xiao@figure and \xiao@figurei.

The entry in the .lof file for the first figure is

\contentsline {figure}{\numberline {1.1}{\ignorespaces Caption}}{1}

and \contentsline{figure} is first translated into \l@figure, according to the definition of \contentsline. Then, becauso of our redefinition of \listoffigures, LaTeX transforms \l@figure into \xiao@figure, so the main input becomes

\xiao@figure{\numberline {1.1}{\ignorespaces Caption}}{1}

The first argument to \xiao@figure is now

\numberline {1.1}{\ignorespaces Caption}

and the second one is 1 (after stripping braces around arguments). Thus the next replacement is

\xiao@figurei\numberline {1.1}{\ignorespaces Caption}{1}

and next the definition of \xiao@figurei is looked at: it has to be followed by \numberline (which is removed) and has three arguments

1.1
\ignorespaces Caption
1

and now the main part of the work can be done, because we have correctly identified the contents of the three table cells.


With hyperref the \contentsline macro has a different definition. Supporting links seems to be quite difficult, unfortunately.

In order to get a successful compilation (without links), you can do as follows:

\documentclass{book}

\let\latexcontentsline\contentsline
\usepackage{hyperref}

\makeatletter

\renewcommand\listoffigures{%
    \chapter*{\listfigurename}%
      \@mkboth{\MakeUppercase\listfigurename}%
              {\MakeUppercase\listfigurename}%
    \begingroup\let\addvspace\@gobble
    \raggedbottom\offinterlineskip\def\l@figure{\xiao@figure}\parindent\z@
    \let\contentsline\latexcontentsline
    \hrule
    \vrule\vrule width \z@ height 1.2\ht\strutbox depth 1.2\dp\strutbox
    \makebox[\dimexpr3cm-0.8pt\relax][c]{\bfseries Number}\vrule
    \parbox{\dimexpr\textwidth-6cm}{\normalbaselines\centering {\large\strut}\bfseries Caption{\large\strut}}\vrule
    \makebox[\dimexpr3cm-0.8pt\relax][c]{\bfseries Page}\vrule
    \hrule
    \@starttoc{lof}%
    \endgroup
    }
\def\xiao@figure#1{\xiao@figurei#1}
\long\def\xiao@figurei\numberline#1#2#3#4{%
  \vrule\vrule width \z@ height 1.2\ht\strutbox depth 1.2\dp\strutbox
  \makebox[\dimexpr3cm-0.8pt\relax][c]{Fig.\ #1}\vrule
  \parbox{\dimexpr\textwidth-6cm}{\normalbaselines\centering {\large\strut}#2{\large\strut}}\vrule
  \makebox[\dimexpr3cm-0.8pt\relax][c]{#3}\vrule
  \hrule
  \hskip-.4pt
  \hrule
  \nobreak
}
\makeatother
share|improve this answer
    
Thanks a lot. This is what I want. Very nice work! –  XIAO Lishun Apr 19 '12 at 4:29
    
I have some doubts about the definition of \xiao@figurei and \xiao@figure. \xiao@figurei has three parameters but \xiao@figure has only two. How to assign the two to the three? –  XIAO Lishun Aug 31 '12 at 9:09
    
@XIAOLishun I've added some explanation; TeX is a "macro expansion" language, so sometimes its workings are a bit obscure. :) –  egreg Aug 31 '12 at 9:32
    
@ egreg Thanks a lot. I will study your codes for a moment in order to revise them for what I want. Maybe, there are also some questions for you. It is so nice of you. –  XIAO Lishun Aug 31 '12 at 10:27
    
@ egreg Well, there comes a problem again. After PDFLaTeX my .tex, there are some other generated codes. The LOF file includes the codes like \contentsline {figure}{\numberline {1--1}{\ignorespaces Logo of \TeX}}{4}{section.1.3}. I do not want the code {section.1.3} because LaTeX warns me that "Use of \xiao@figure doesn't match its definition". I think the reason is {section.1.3}. How to realize this? –  XIAO Lishun Aug 31 '12 at 15:27
show 2 more comments

I want to provide an other approach. Therefor I am using the advantages of the core language expl3. The output will be created with longtable. So you can define your header and it allows page breaks.

First of all I want to give thanks to Joseph Wright for his improvements.

\documentclass{report}
\usepackage{array,longtable}
\usepackage{xparse}

\ExplSyntaxOn
\tl_new:N \g_listoffigures_storelines_tl
\DeclareDocumentCommand \mynumberline { m m }
    {
     \tl_set:Nn \l_tmpa_tl {Figure~#1}
     \tl_set:Nn \l_tmpb_tl {#2}
    }  
\DeclareDocumentCommand \mylatfigure { m m }
 {
     #1
  \tl_gput_right:Nx \g_listoffigures_storelines_tl
   {
     \exp_not:V \l_tmpa_tl \exp_not:N &
     \exp_not:V \l_tmpb_tl \exp_not:N &
     \exp_not:n { #2 \\ \hline }
   }
  }
\DeclareDocumentCommand \UseEntries {}
{
      \tl_use:N  \g_listoffigures_storelines_tl  
}
\ExplSyntaxOff

\makeatletter    
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{\dimexpr #1 \relax}}
\renewcommand\listoffigures{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\listfigurename}%
      \@mkboth{\MakeUppercase\listfigurename}%
              {\MakeUppercase\listfigurename}%
    \begingroup
    \let\l@figure\mylatfigure
    \let\numberline\mynumberline
    \let\addvspace\@gobble
    \@starttoc{lof}%
    \begin{longtable}{@{}|C{2.5cm}|C{\linewidth-5cm}|C{2.5cm-6\tabcolsep-4\arrayrulewidth}|@{}}\hline
     \textbf{Number} & \textbf{Caption} & \textbf{Page} \\\hline\endhead
     \UseEntries
   \end{longtable}%  
   \endgroup
   \if@restonecol\twocolumn\fi
    }
\makeatother



\begin{document}
\listoffigures

\listoftables
\chapter{foo}
Text
\begin{figure}[!ht]
\caption{caption}
\end{figure}
\begin{table}[!ht]
\caption{caption}
\end{table}
\clearpage
\addtocounter{page}{24}
\chapter{foo}
Text
\begin{figure}[!ht]
\caption{The logo of \TeX}
\end{figure}
\clearpage

\chapter{foo}
Text
\begin{figure}[!ht]
\caption{Some figures of \LaTeX}
\end{figure}
\end{document}

Of course you can combine the expl3 part with the redefinition of \listoftables However I don't want to mix expl3 with LaTeX2e-macros.

enter image description here

share|improve this answer
2  
Very nice work; this has the advantage that the header is automatically repeated at page breaks. –  egreg Apr 18 '12 at 20:04
    
Perfect! But I do not understand your code very well. I should learn more. –  XIAO Lishun Apr 19 '12 at 4:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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