答案1
我对这个问题的回答稍作修改:将 \listoffigures 和 \listoftables 重新定义为表格
我使用了命令名称\tableoffigures
,并没有触碰\listoffigures
。
该表是一个tabularx
来自 的长表版本ltablex
,因此如果数字多于一页能够容纳的枚举数量,则表将会分页。
\documentclass{article}
\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}
\usepackage{array}
\usepackage{ltablex}
%\usepackage{longtable}
\usepackage{caption}
\usepackage{letltxmacro}
\usepackage{xparse}
\newif\ifhyperrefloaded
\newcounter{fullfigurecounter}
\newcounter{fulltablecounter}
\usepackage{hyperref}
\makeatletter
\@ifpackageloaded{hyperref}{\hyperrefloadedtrue}{\hyperrefloadedfalse}
\providecommand{\theHtable}{}
\newcommand{\PhantomSection}{%
\ifhyperrefloaded
\phantomsection%
\fi
}
\newcolumntype{A}{>{\centering\arraybackslash}X}
\def\@starttof#1#2{%
\begingroup
\makeatletter
\renewcommand{\arraystretch}{1.5}
% Table format may be changed%%%
\renewcommand{\theHtable}{longtable.\theLT@tables}% Use a different Hyperref name for table due the \refstepcounter{table}- issue with longtable
\bfseries%
\begin{tabularx}{\linewidth}{|p{3cm}|p{6cm}|A|}
\multicolumn{3}{c}{}\tabularnewline
\multicolumn{3}{c}{\Large \bfseries #2}\tabularnewline
\multicolumn{3}{c}{}\tabularnewline
\multicolumn{3}{c}{}\tabularnewline[0.5ex]
\hline
\large Figure No. & \large Title & \large Page \tabularnewline
\hline
\endhead % Repeating head
\@input{\jobname.#1}% Input the ToF or ToT file
\tabularnewline
\hline
\end{tabularx}
\setcounter{table}{0}%
\if@filesw
\expandafter\newwrite\csname tf@#1\endcsname
\immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
\fi
\endgroup
}
\newcommand{\tofiguresname}{\listfigurename}
\newcommand{\totablesname}{Tabellenverzeichnis}
\newcommand{\tableoffigures}{%
\cleardoublepage
\PhantomSection%
\addcontentsline{toc}{section}{\tofiguresname}%
\@starttof{tof}{\tofiguresname}
}%
\newcommand{\tableoftables}{%
\clearpage
\PhantomSection%
\addcontentsline{toc}{section}{\totablesname}%
\@starttof{tot}{\totablesname}%
}%
\def\temp@@a{figure}%
\def\temp@@b{table}%
\LetLtxMacro\captionpkg@caption\caption
\newcommand{\writetofline}[3]{%
\ifnum\value{fullfigurecounter} > 1
\tabularnewline
\protect\hline
\fi
#1 & #2 &
\ifhyperrefloaded
\protect\hyperlink{figure.\thefigure}{#3}%
\else
#3%
\fi
}
\newcommand{\writetotline}[3]{%
\ifnum\value{fulltablecounter} > 1
\tabularnewline
\protect\hline
\fi
#1 & #2 &
\ifhyperrefloaded
\protect\hyperlink{table.\thetable}{#3}%
\else
#3%
\fi
}
\RenewDocumentCommand{\caption}{som}{%
\IfBooleanTF{#1}{%
\captionpkg@caption{#3}%
}{%
\ifx\@currenvir\temp@@a
\stepcounter{fullfigurecounter}%
\else
\ifx\@currenvir\temp@@b
\stepcounter{fulltablecounter}%
\fi
\fi
\IfValueTF{#2}{%
\captionpkg@caption[#2]{#3}%
\ifx\@currenvir\temp@@a
\addtocontents{tof}{\writetofline{\thefigure}{#2}{\thepage}}%
\else
\ifx\@currenvir\temp@@b
\addtocontents{tot}{\writetotline{\thetable}{#2}{\thepage}}%
\fi
\fi
}{%
\captionpkg@caption{#3}%
\ifx\@currenvir\temp@@a
\addtocontents{tof}{\writetofline{\thefigure}{#3}{\thepage}}
\else%
\ifx\@currenvir\temp@@b
\addtocontents{tot}{\writetotline{\thetable}{#3}{\thepage}}%
\fi
\fi
}%
}%
}
\makeatother
\usepackage{pgffor}
\begin{document}
\tableofcontents
\clearpage
\tableoffigures
\clearpage
\section{A section}
\foreach \x in {1,...,20} {%
\begin{figure}
\caption{Irgendein Bild \x}
\end{figure}
\begin{figure}
\caption[Die Sonnenblumen \x]{Irgendein Bild}
\end{figure}
}
\clearpage
\foreach \x in {1,...,6} {%
\begin{table}
\caption[A nice table \x]{A nice table}
\end{table}
}
\clearpage
\foreach \x in {1,...,20} {%
\begin{figure}
\caption[Impressionen \x]{Impressions du Soleil}
\end{figure}
}
\end{document}