![自定义图形列表中自定义浮动环境条目的格式前缀](https://linux22.com/image/450907/%E8%87%AA%E5%AE%9A%E4%B9%89%E5%9B%BE%E5%BD%A2%E5%88%97%E8%A1%A8%E4%B8%AD%E8%87%AA%E5%AE%9A%E4%B9%89%E6%B5%AE%E5%8A%A8%E7%8E%AF%E5%A2%83%E6%9D%A1%E7%9B%AE%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%89%8D%E7%BC%80.png)
我正在处理一份基于report
类别的复杂格式的文档。
\DeclareFloatingEnvironment
我使用基于的newfloat
包定义了一个新的照片图片列表这个答案。我使用基于的包\DeclareTOCStyleEntry
自定义了图形列表中条目的前缀tocbasic
这个答案。我得到了这个结果:
问题是,照片列表还是数字。我尝试过许多论坛上的许多解决方案,但都不起作用。我无法更改类或包,因为它会破坏格式并产生问题。例如,这个答案scrreprt
我无法使用。我还尝试了基于\newfloat
以下float
包(在最后的脚本中注释掉)这个答案但我无法在条目中添加前缀(照片)照片列表也不自定义它,它只显示数字,而不是数字/照片。我也尝试使用\DeclareTOCStyleEntry
但是photograph
它会产生错误:
Package tocbasic Error: toc style `tocline' needs toc style level.
Package tocbasic Error: toc style `tocline' needs toc entry level.
Package tocbasic Error: toc style `tocline' needs entry indent.
Package tocbasic Error: toc style `tocline' needs entry number width.
我使用了\DeclareFloatingEnvironment
after,\DeclareTOCStyleEntry
因为\DeclareFloatingEnvironment
内部使用,\listoffigures
因此在 toc 样式条目之后声明它会继承格式。在 toc 样式条目上方声明它不会显示前缀。
我需要的结果是这样的:
此处附有简化版的 latex 脚本。有什么方法可以更改前缀数字到照片在里面照片列表?
\documentclass[12pt,a4paper]{report}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
entrynumberformat=\figureentryformat{\figurename},
dynnumwidth,
numsep=1em
]{tocline}{figure}
\newcommand\figureentryformat[2]{\textbf{#1\enspace#2.}\hfill}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext=lop,
listname={List of Photographs},
name=Photograph,
placement=tp,
within=chapter,
chapterlistsgaps=on,
]{photograph}
%\usepackage{float}
%\newfloat{photograph}{tbp}{lop}[chapter]
%\floatname{photograph}{Photograph}
%\newcommand{\listofphotograpsname}{List of Photographs}
%\newcommand{\listofphotographs}{%
% \addcontentsline{toc}{chapter}{\listofphotograpsname}
% \listof{photograph}{\listofphotograpsname}
%}
\begin{document}
\tableofcontents
\listoffigures
\begingroup
\let\clearpage\relax
\listofphotographs
\endgroup
\chapter{First chapter}
\begin{figure}
\includegraphics[width=\textwidth]{example-image}
\caption{First dummy figure}
\end{figure}
\begin{figure}
\includegraphics[width=\textwidth]{example-image}
\caption{Second dummy figure}
\end{figure}
\chapter{Second chapter}
\begin{photograph}
\includegraphics[width=\textwidth]{example-image}
\caption{First dummy photo}
\end{photograph}
\begin{photograph}
\includegraphics[width=\textwidth]{example-image}
\caption{Second dummy photo}
\end{photograph}
\end{document}
答案1
此代码使用该包tocloft
来设置两个列表。
\documentclass[12pt,a4paper]{report}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{newfloat}
\usepackage{tocloft} % added <<<<<<<<<<
\newlistof{photograph}{lop}{List of Photograph}% <<<<<<<<<<<<<<<
\DeclareFloatingEnvironment[
fileext=lop,
listname={List of Photographs},
%name=Photograph,
placement=tp,
within=chapter,
chapterlistsgaps=on,
]{photograph}
\renewcommand{\cftfigpresnum}{\bfseries Figure~} % List of FIgures set up <<<<<<<<
\setlength{\cftfignumwidth}{5ex}
\setlength{\cftfigindent}{0ex}
\newlength{\figlen}% a pre figure title length
\settowidth{\figlen}{\bfseries\cftfigpresnum} % the word Figure~
\addtolength{\figlen}{\cftfignumwidth}
\renewcommand{\cftfignumwidth}{\figlen}
\renewcommand{\cftfigaftersnum}{.}
\renewcommand{\cftphotographpresnum}{\bfseries Photograph~} % List of Photograph set up <<<<<<<<<<<<<<<<
\setlength{\cftphotographnumwidth}{5ex}
\setlength{\cftphotographindent}{0ex}
\newlength{\photographlen}% a pre photo title length
\settowidth{\photographlen}{\bfseries\cftphotographpresnum} % the word Photograph~
\addtolength{\photographlen}{\cftphotographnumwidth}
\renewcommand{\cftphotographnumwidth}{\photographlen}
\renewcommand{\cftphotographaftersnum}{.}
\begin{document}
\tableofcontents
\clearpage
\listoffigures
\listofphotographs
\chapter{First chapter}
\begin{figure}
\includegraphics[width=\textwidth]{example-image}
\caption{First dummy figure}
\end{figure}
\begin{figure}
\includegraphics[width=\textwidth]{example-image}
\caption{Second dummy figure}
\end{figure}
\chapter{Second chapter}
\begin{photograph}
\includegraphics[width=\textwidth]{example-image}
\caption{First dummy photo}
\end{photograph}
\begin{photograph}
\includegraphics[width=\textwidth]{example-image}
\caption{Second dummy photo}
\end{photograph}
\end{document}