将 \listoffigures 和 \listoftables 重新定义为表格

将 \listoffigures 和 \listoftables 重新定义为表格

我的一位朋友的系里要求他按照下图所示格式化他的图表列表(=“Abbildungsverzeichnis”)和表格列表(=“Tabellenverzeichnis”)。有没有办法通过重新定义相应的命令来实现这一点LaTeX?除了标题(~“Kurzüberschrift”)之外,来源(=“Quelle”)也需要包含在列表中。Abbildungsverzeichnis = 图表列表,Tabellenverzeichnis = 表格列表

我已经准备好这个 MWE 作为开始——尽管它距离预期的结果还很远。

\documentclass{scrartcl}

\usepackage{mwe}

\begin{document}

\begin{figure}
\centering
\includegraphics{example-image}
\caption{An awesome image. Source: Thatoneguy, W. (2003)}  
\end{figure}

\begin{table}[ht]
\centering
\begin{tabular}{|c|c|}
\hline
Foo & Bar\\ \hline
Meh & More meh \\ \hline
\end{tabular}
\caption{An awesome table. Source: Someone, A. (2012)}
\end{table}

\listoffigures 

\listoftables

\end{document}

答案1

更新:版本hyperref位于这篇文章的底部。

这个问题已经存在几个月了,但这里有一种tabular方法,即向命令添加代码\caption并使用单独的文件\jobname.tof\jobname.tot\tableoffigures\tableoftables不是\listoffigures\listoftables,即我保持标准\listof...命令不变。

常用\caption命令已扩展为第四个可选参数,其中包含图形或表格的来源,默认为Eigene Darstellung(→ own work)

\@starttof(start table of ...) 命令使用包装longtable器来显示表格并提供分页符。表格的格式可能需要更改为实际规范。

关键条目由\writetoffile和给出\writetotfile(再多做一些努力,可能只是一个命令)

在这里可以找到类似的问题(与其他设置):我需要将 \listoffigures 显示为表格

\documentclass{article}

\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}

\usepackage{biblatex}
\usepackage{longtable}
\usepackage{etoolbox}
\usepackage{letltxmacro}
\usepackage{xparse}

\addbibresource{biblio.bib}

\newcounter{fullfigurecounter}
\newcounter{fulltablecounter}

\makeatletter


\def\@starttof#1#2{%
  \begingroup
  \makeatletter
  \renewcommand{\arraystretch}{1.5}
  % Table format may be changed%%%
  \begin{longtable}{|p{2cm}|p{6cm}|p{7cm}|}
    \hline
    \multicolumn{3}{c}{}\tabularnewline
    \multicolumn{3}{c}{\Large \bfseries #2}\tabularnewline
    \multicolumn{3}{c}{}\tabularnewline
    \hline
    \multicolumn{3}{c}{}\tabularnewline[0.5ex]
    \hline
    \large Nummer  & \large Kurz\"uberschrift & \large Quelle \tabularnewline
    \hline
    \endhead % Repeating head
    \@input{\jobname.#1}%  Input the ToF or ToT file 
    \tabularnewline
  \hline
  \end{longtable}
  \setcounter{table}{0}%
  \if@filesw
  \expandafter\newwrite\csname tf@#1\endcsname
  \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
  \fi
  \endgroup
}



\newcommand{\tableoffigures}{%
  \cleardoublepage
  \@starttof{tof}{Abbildungs- und Quellenverzeichnis}
}%


\newcommand{\tableoftables}{%
  \clearpage
  \@starttof{tot}{Tabellenverzeichnis}%
}%


\def\temp@@a{figure}%
\def\temp@@b{table}%

\LetLtxMacro\captionpkg@caption\caption

\newcommand{\writetofline}[3]{%
  \ifnum\value{fullfigurecounter} > 1
  \tabularnewline
  \protect\hline
  \fi
  \figurename\ #1 & #2 & #3 
}

\newcommand{\writetotline}[3]{%
  \ifnum\value{fulltablecounter} > 1
  \tabularnewline
  \protect\hline
  \fi
  \tablename\ #1 & #2 & #3 
}


\RenewDocumentCommand{\caption}{somO{Eigene Darstellung}}{%
  \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}{#4}}%
      \else
      \ifx\@currenvir\temp@@b
      \addtocontents{tot}{\writetotline{\thetable}{#2}{#4}}%
      \fi
      \fi
    }{%
      \captionpkg@caption{#3}%
      \ifx\@currenvir\temp@@a
      \addtocontents{tof}{\writetofline{\thefigure}{#3}{#4}}%
      \else%
      \ifx\@currenvir\temp@@b
      \addtocontents{tot}{\writetotline{\thetable}{#3}{#4}}%
      \fi
      \fi
    }%
  }%
}




\makeatother

\usepackage{pgffor}
\begin{document}

\tableoffigures
\clearpage
\tableoftables
\clearpage

\foreach \x in {1,...,20} {%
  \begin{figure}
    \caption{Irgendein Bild}
  \end{figure}
  \begin{figure}
  \caption[Die Sonnenblumen]{Irgendein Bild}[Vincent van Gogh]
  \end{figure}
}
\clearpage

\foreach \x in {1,...,6} {%
  \begin{table}
    \caption[A nice table]{A nice table}[Me!]
  \end{table}
}

\clearpage

\foreach \x in {1,...,20} {%
  \begin{figure}
  \caption[Impressionen]{Impressions du Soleil}[Monet]
  \end{figure}
}


\printbibliography
\end{document}

biblio.bib文件包含在每个 TeX 发行版中。

在此处输入图片描述

更新(由于要求第四列包含页码)

此外,hyperref现在也支持

\documentclass{article}

\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}

\usepackage{biblatex}
\usepackage{array}
\usepackage{longtable}
\usepackage{caption}
\usepackage{letltxmacro}
\usepackage{xparse}

\newif\ifhyperrefloaded

\addbibresource{biblio.bib}

\newcounter{fullfigurecounter}
\newcounter{fulltablecounter}

\usepackage[hypertexnames=true]{hyperref}

\makeatletter

\@ifpackageloaded{hyperref}{\hyperrefloadedtrue}{\hyperrefloadedfalse}

\newcommand{\PhantomSection}{%
  \ifhyperrefloaded
  \phantomsection%
  \fi
}


\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
  \begin{longtable}{|p{2cm}|p{6cm}|p{5.5cm}|>{\raggedleft}p{1cm}|}
    \hline
    \multicolumn{4}{c}{}\tabularnewline
    \multicolumn{4}{c}{\Large \bfseries #2}\tabularnewline
    \multicolumn{4}{c}{}\tabularnewline
    \hline
    \multicolumn{4}{c}{}\tabularnewline[0.5ex]
    \hline
    \large Nummer  & \large Kurz\"uberschrift & \large Quelle & Seite \tabularnewline
    \hline
    \endhead % Repeating head
    \@input{\jobname.#1}%  Input the ToF or ToT file 
    \tabularnewline
  \hline
  \end{longtable}
  \setcounter{table}{0}%
  \if@filesw
  \expandafter\newwrite\csname tf@#1\endcsname
  \immediate\openout \csname tf@#1\endcsname \jobname.#1\relax
  \fi
  \endgroup
}


\newcommand{\tofiguresname}{Abbildungs- und Quellenverzeichnis}
\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}[4]{%
  \ifnum\value{fullfigurecounter} > 1
  \tabularnewline
  \protect\hline
  \fi
  \figurename\ #1 & #2 & #3 &
  \ifhyperrefloaded 
  \protect\hyperlink{figure.\thefigure}{#4}%
  \else
  #4%
  \fi
}

\newcommand{\writetotline}[4]{%
  \ifnum\value{fulltablecounter} > 1
  \tabularnewline
  \protect\hline
  \fi
  \tablename\ #1 & #2 & #3 & 
  \ifhyperrefloaded 
  \protect\hyperlink{table.\thetable}{#4}%
  \else
  #4%
  \fi
}


\RenewDocumentCommand{\caption}{somO{Eigene Darstellung}}{%
  \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}{#4}{\thepage}}%
      \else
      \ifx\@currenvir\temp@@b
      \addtocontents{tot}{\writetotline{\thetable}{#2}{#4}{\thepage}}%
      \fi
      \fi
    }{%
      \captionpkg@caption{#3}%
      \ifx\@currenvir\temp@@a
      \addtocontents{tof}{\writetofline{\thefigure}{#3}{#4}{\thepage}}
      \else%
      \ifx\@currenvir\temp@@b
      \addtocontents{tot}{\writetotline{\thetable}{#3}{#4}{\thepage}}%
      \fi
      \fi
    }%
  }%
}




\makeatother

\usepackage{pgffor}
\begin{document}
\tableofcontents
\clearpage

\tableoffigures
\clearpage
\tableoftables
\clearpage

\section{A section}


\foreach \x in {1,...,20} {%
  \begin{figure}
    \caption{Irgendein Bild}[\cite{Lam94}]
  \end{figure}
  \begin{figure}
    \caption[Die Sonnenblumen]{Irgendein Bild}[Vincent van Gogh]
  \end{figure}
}
\clearpage

\foreach \x in {1,...,6} {%
  \begin{table}
    \caption[A nice table]{A nice table}[Me!]
  \end{table}
}

\clearpage

\foreach \x in {1,...,20} {%
  \begin{figure}
  \caption[Impressionen]{Impressions du Soleil}[Monet]
  \end{figure}
}


\printbibliography
\end{document}

相关内容