我正在写一篇硕士论文,我想创建一个按章节排序的表格和图片列表,并清晰显示章节名称。我的表格(和图片)的编号已按章节进行,这很好。
我已经看到一些与此相关的主题,但这一切似乎都非常复杂和不可思议,需要重新定义功能,最重要的是,它只涉及书籍(和章节,我没有……)。我以为这会相当简单,而且我发现自己已经浏览网页很长时间了。
您有什么简单的解决方案吗?附件是我希望表格列表的样子。
非常感谢 Guillaume
答案1
更新--改进版本--2014年9月12日
更新——在这里可以找到类似的问题:在图片列表中添加章节名称
我也在那里提供了解决方案,部分基于expl3
功能。
这是一个可能的解决方案。可能还有其他(更简单的?)解决方案。
特征
EnableSectionsInLOFT
全局启用部分分隔符,\DisableSectionsInLOFT
全局禁用它们。在 documentstart 中,默认情况下启用它。- 默认情况下,附录部分不会在 LOT/LOF 中列为分隔符
- 在 \appendix 之后使用
\captionsetup{list=no}
,以防止在 LOF/LOT 中完全列出表格/图片 \EnableAppendixSectionInLOF
并\EnableAppendixSectionInLOT
启用从附录部分生成部分分隔符。有相应的\Disable....
宏用于禁用此功能EnableAppendixLOFT
全局启用附录部分分隔符,\DisableAppendixLOFT
禁用此功能。\loftsectionbeforeskipamount
可以通过为长度和提供其他值来更改上下分隔符的间距\loftsectionafterskipamount
。目前两者默认为\medskip
。
我会解释我做了什么。
每次
\section
使用命令时,它都应该向其中写入一行list of figures
,但前提是存在一些数字。为了实现这一点,必须对
\section
命令进行一些工作——根据需要重新定义它——否则,它的行为将符合预期。为了避免\tableofcontents
抱怨,\section*
也必须“重新定义”。这会很好,所有这一切都可以与等等一起进行,但是这被:-( --> 走很长且艰难的路 ;-)
\xpatchcmd
的内部定义所阻止。\section
图形仅限于当前部分,不能浮动到上一节/下一节的文本“空间”中——这是通过
\Floatbarrier
- 数字计数器存储到文件名中
\jobname.figcount
,并在下一阶段读取(参见下面阶段的定义) - 我决定使用
\addtocontents
`\addcontentsline 来代替,以便更清楚地区分之前的部分和图形列表。
以上所有评论table
也同样适用于柜台。
阶段定义
第一阶段-->计数器值写入外部文件
第二阶段 --> 计数器值被读入,部分条目被添加到 LOF/LOT
- 第三阶段 --> lof/loc 的必要更新阶段
有3编译的阶段 —— LaTeX 必须运行三次!
请勿删除\jobname.tabcount
和\jobname.figcount
中间!
\documentclass[paper=a4,12pt]{scrartcl}%
\usepackage[demo]{graphicx}%
\usepackage{etoolbox}%
\usepackage{blindtext}%
\usepackage{caption}%
\usepackage{placeins}%
\usepackage{assoccnt}%
\usepackage{morewrites}%
\makeatletter
% Get some file handles first
\newwrite\figurecountsout%
\newwrite\tablecountsout%
\newread\figurecountsin%
\newread\tablecountsin%
% The number of runs...
\newcounter{numberofruns}%
\newcommand{\secfig@@voidstage}{0}%
\newcommand{\secfig@@writecounterstage}{1}%
\newcommand{\secfig@@readcounterstage}{2}%
\newcommand{\secfig@@writecontentstage}{2}%
\newcommand{\secfig@@resetstage}{3}%
\newlength{\loftsectionbeforeskipamount}%
\newlength{\loftsectionafterskipamount}%
\setlength{\loftsectionafterskipamount}{\medskipamount}%
\setlength{\loftsectionbeforeskipamount}{\medskipamount}%
\newcommand{\loftsectionbeforeskip}{\vspace{\loftsectionbeforeskipamount}}%
\newcommand{\loftsectionafterskip}{\vspace{\loftsectionafterskipamount}}%
\newtoggle{SectionsInLOFT}%
\newcommand{\EnableSectionsInLOFT}{%
\settoggle{SectionsInLOFT}{true}%
}%
\newcommand{\DisableSectionsInLOFT}{%
\settoggle{SectionsInLOFT}{false}%
}%
\EnableSectionsInLOFT%
\newtoggle{AppendixSectionsInLOF}%
\newtoggle{AppendixSectionsInLOT}%
\settoggle{AppendixSectionsInLOF}{true}%
\settoggle{AppendixSectionsInLOT}{true}%
\newcommand{\EnableAppendixSectionInLOF}{%
\settoggle{AppendixSectionsInLOF}{true}%
}%
\newcommand{\EnableAppendixSectionInLOT}{%
\settoggle{AppendixSectionsInLOT}{true}%
}%
\newcommand{\EnableAppendixLOFT}{%
\EnableAppendixSectionInLOF%
\EnableAppendixSectionInLOT%
}%
\newcommand{\DisableAppendixSectionInLOT}{%
\settoggle{AppendixSectionsInLOT}{false}%
}%
\newcommand{\DisableAppendixSectionInLOF}{%
\settoggle{AppendixSectionsInLOF}{false}%
}%
\newcommand{\DisableAppendixLOFT}{%
\DisableAppendixSectionInLOF%
\DisableAppendixSectionInLOT%
}%
\apptocmd{\appendix}{\DisableAppendixLOFT}%
% Needed for correct number of sections
\newcounter{totalsections}
\DeclareAssociatedCounters{section}{totalsections}%
% numberofruns = 1 --> write figcount file --> no adding to lof
% numberofruns = 2 --> Read fig counters file and decide if a section entry is to be done
% numberofruns = 3 --> Last update run to the toc, do neither read nor write! Set the counter of runs to 0 then.
\@addtoreset{figure}{section}%
\@addtoreset{table}{section}%
\let\LaTeXStandardSection\section%
\newcommand{\unstarredsection@@noopt}[1]{%
% Call the command without option - long title will become 'short' title
\unstarredsection@@opt[#1]{#1}%
}%
\newcommand{\StoreCounterValue}[1]{%
\immediate\expandafter\write\csname #1countsout\endcsname{%
\number\value{#1}%
}%
}%
\newcommand{\LoadAllStoredCounterValues}[1]{%
\ifnumequal{\number\value{#1}}{\secfig@@readcounterstage}{% Only read, if value is \secfig@@readcounterstage%
\read\figurecountsin to \lastsectionfigures
\read\tablecountsin to \lastsectiontables%
}{}%
}%
\newcommand{\loftsectioncontentsline}[1]{%
\loftsectionbeforeskip\textbf{\large\thesection~#1}\loftsectionafterskip
}%
\newcommand{\unstarredsection@@opt}[2][]{%
\iftoggle{SectionsInLOFT}{%
\FloatBarrier%
\gdef\lastsectionfigures{0}%
\gdef\lastsectiontables{0}%
\ifnumequal{\number\value{numberofruns}}{\secfig@@writecounterstage}{% Only write, if counter has value 1
\gdef\lastsectionfigures{\number\value{figure}}%
\gdef\lastsectionfigures{\number\value{table}}%
\ifnumequal{\number\value{totalsections}}{0}{%
}{%
\StoreCounterValue{figure}%
\StoreCounterValue{table}%
}%
}{%
\LoadAllStoredCounterValues{numberofruns}%
}%
}{%
}%
% \phantomsection Use here if hyperref is needed
\LaTeXStandardSection[#1]{#2}%
\iftoggle{SectionsInLOFT}{%
\ifnumequal{\number\value{numberofruns}}{\secfig@@writecontentstage}{% Only make an entry in stages >= 2
\ifnumgreater{\lastsectionfigures}{0}{%
\typeout{Writing a section entry for \thesection{}to the LOF}%
\iftoggle{AppendixSectionsInLOF}{%
\addtocontents{lof}{\loftsectioncontentsline{#1}}%
}{}%
}{%
\typeout{No figures in \thesection!}
}%
\ifnumgreater{\lastsectiontables}{0}{%
\typeout{Writing a section entry for \thesection{}to the LOT}%
\iftoggle{AppendixSectionsInLOT}{%
\addtocontents{lot}{\loftsectioncontentsline{#1}}%
}{}%
}{%
\typeout{No tables in \thesection!}
}%
}{}%
}{%
}% End of \iftoggle{SectionsInLOFT}%
}%
\newcommand{\unstarredsection}{%
\@ifnextchar[{%
\unstarredsection@@opt%
}{%
\unstarredsection@@noopt%
}%
}%
\newcommand{\starredsection}[1]{%
\LaTeXStandardSection*{#1}%
}%
\renewcommand{\section}{%
\@ifstar{%
\starredsection%
}{%
\unstarredsection%
}%
}%
\AtBeginDocument{%
\iftoggle{SectionsInLOFT}{%
\typeout{Previous Stage \number\value{numberofruns}}%
\stepcounter{numberofruns}%
\typeout{Current Stage is now \number\value{numberofruns}}%
\ifnumequal{\number\value{numberofruns}}{\secfig@@writecounterstage}{%
\immediate\openout\figurecountsout=\jobname.figcount
\immediate\openout\tablecountsout=\jobname.tabcount
}{%
\openin\figurecountsin=\jobname.figcount%
\openin\tablecountsin=\jobname.tabcount%
}%
}{%
% Nothing to be done!
}%
}%
\AtEndDocument{%
\iftoggle{SectionsInLOFT}{%
\ifnumequal{\number\value{numberofruns}}{\secfig@@resetstage}{%
\setcounter{numberofruns}{\secfig@@voidstage} % Reset counters afterwards.
}{}%
\immediate\write\@auxout{%
\string\setcounter{numberofruns}{\number\value{numberofruns}}
}
% Write the last figure counter value to the file!
\ifnumequal{\number\value{numberofruns}}{\secfig@@writecounterstage}{%
\StoreCounterValue{figure}%
\StoreCounterValue{table}%
\immediate\closeout\figurecountsout%
\immediate\closeout\tablecountsout%
}%
\immediate\closein\figurecountsin% Close input file
\immediate\closein\tablecountsin% Close input file
}{%
% no Sections in lof/lot
}%
}%
\makeatother
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}%
\renewcommand{\thetable}{\arabic{section}.\arabic{table}}%
\EnableSectionsInLOFT%
\begin{document}
\tableofcontents%
\listoffigures
\listoftables
\clearpage
\section{First}
\blindtext
\begin{figure}[!ht]
\begin{center}
\includegraphics[scale=1]{somefig}%
\caption{First}
\end{center}
\end{figure}
\begin{figure}
\begin{center}
\includegraphics[scale=1]{somefig}%
\caption{Second}
\end{center}
\end{figure}
\begin{table}
\begin{tabular}{ccc}
a & small table \tabularnewline
\end{tabular}
\caption[Small Table]{First small table}
\end{table}
\section{Second}
\begin{figure}
\caption{Third}
\end{figure}
\begin{figure}
\caption{Fourth}
\end{figure}
\begin{figure}
\caption{Fifth}
\end{figure}
\begin{figure}
\caption{Sixth}%
\end{figure}
\section{Without figures}
\section[One with another title]{A very long, long, long section title}
\begin{figure}
\caption{Seventh}
\end{figure}
\begin{figure}
\caption[Eight]{Eight Section}%
\end{figure}
\section{Another section without figures}%
\blindtext
\section[Yippie]{Last one}%
\begin{table}
\caption{dummy table}%
\end{table}
\appendix
\captionsetup{list=no}
\section{First Appendix Section}
\begin{figure}
\caption{Appendix Figure}
\end{figure}
\begin{table}
\caption[]{dummy table in appendix}
\end{table}
\section{Second Appendix Section}
\begin{figure}
\caption{Appendix Figure Nr. 2}
\end{figure}
\begin{table}
\caption{Dummy table in appendix }
\end{table}
\end{document}
如果值得将其制作成包,请提供反馈。