我正在使用 LyX,但我将在下面提供 MWE TeX 代码(可能有很多不相关的代码片段,但我不想删除任何可能与问题相关的内容)。
基本上,我最终确定了我想要的输出,除了 LoA 打印看起来比 LoF 低一行。
我可以控制序言,它目前具有以下代码。
\usepackage{algorithm,algpseudocode}
\usepackage{etoolbox}
\usepackage{tocloft}
\patchcmd{\listof}% <cmd>
{\float@listhead}% <search>
{\@namedef{l@#1}{\l@figure}\float@listhead}% <replace>
{}{}% <success><failure>
\preto\figure{%
\ifnum\value{figure}=0\addtocontents{lof}{{\bfseries Chapter \thechapter\vskip10pt}}\fi
}
\preto\table{%
\ifnum\value{table}=0\addtocontents{lot}{{\bfseries Chapter \thechapter\vskip10pt}}\fi
}
\preto\algorithm{%
\ifnum\value{algorithm}=0\addtocontents{loa}{{\bfseries Chapter \thechapter\vskip10pt}}\fi
}
\cftsetindents{figure}{0em}{3.5em}
\cftsetindents{table}{0em}{3.5em}
preto 用于在 LoX 内添加章节标题。
cftsetindents 正在添加一些间距以使 LoX 输出更清晰。
下面,我粘贴了完整的 MWE,后面附有一张以视觉方式展示我的问题的图像。
非常感谢任何能够纠正 LoA 周围间距的帮助。
附注:我确实设法纠正了这问题可以通过使用来解决\usepackage[titles]{tocloft}
,但随后章节标题会错位,而这个问题更难解决。
%% LyX 2.2.1 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[12pt,english]{extreport}
\usepackage{mathpazo}
\usepackage{berasans}
\renewcommand{\ttdefault}{cmtl}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{luainputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=3cm,rmargin=2cm}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{babel}
\usepackage{array}
\usepackage{longtable}
\usepackage{varioref}
\usepackage{float}
\usepackage{textcomp}
\usepackage{multirow}
\usepackage{amstext}
\usepackage{graphicx}
\usepackage{setspace}
\onehalfspacing
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}
\floatstyle{ruled}
\newfloat{algorithm}{tbp}{loa}[chapter]
\providecommand{\algorithmname}{Algorithm}
\floatname{algorithm}{\protect\algorithmname}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{algorithm,algpseudocode}
\usepackage{etoolbox}
\usepackage{tocloft}
%\let\l@table\l@figure
\patchcmd{\listof}% <cmd>
{\float@listhead}% <search>
{\@namedef{l@#1}{\l@figure}\float@listhead}% <replace>
{}{}% <success><failure>
\preto\figure{%
\ifnum\value{figure}=0\addtocontents{lof}{{\bfseries Chapter \thechapter\vskip10pt}}\fi
}
\preto\table{%
\ifnum\value{table}=0\addtocontents{lot}{{\bfseries Chapter \thechapter\vskip10pt}}\fi
}
\preto\algorithm{%
\ifnum\value{algorithm}=0\addtocontents{loa}{{\bfseries Chapter \thechapter\vskip10pt}}\fi
}
\cftsetindents{figure}{0em}{3.5em}
\cftsetindents{table}{0em}{3.5em}
\@ifundefined{showcaptionsetup}{}{%
\PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\AtBeginDocument{
\def\labelitemii{\(\circ\)}
}
\makeatother
\begin{document}
\tableofcontents{}
\pagebreak{}
\listoffigures{}
\pagebreak{}
\listof{algorithm}{List of Algorithms}
\pagebreak{}
\chapter{Background}
\begin{figure}[H]
\caption{Fig1}
\end{figure}
\chapter{System Design}
\begin{figure}[H]
\caption{Fig2}
\end{figure}
\begin{algorithm}[H]
\begin{algorithmic}[1] \If{$x < \mu$} \State{$\hat{x} \leftarrow 0$} \Else{ } \State{$\hat{x} \leftarrow x$} \EndIf \end{algorithmic}\caption{Custom Zero Minus Means Algorithm}
\end{algorithm}
\end{document}
答案1
你可以使用
\usepackage[titles]{tocloft}
并\noindent
在“章节”之前
\preto\figure{%
\ifnum\value{figure}=0\addtocontents{lof}{{\noindent\bfseries Chapter \thechapter\vskip10pt}}\fi
}
\preto\table{%
\ifnum\value{table}=0\addtocontents{lot}{{\noindent\bfseries Chapter \thechapter\vskip10pt}}\fi
}
\preto\algorithm{%
\ifnum\value{algorithm}=0\addtocontents{loa}{{\noindent\bfseries Chapter \thechapter\vskip10pt}}\fi
}
这里还有另一个建议,使用包tocbasic
来代替tocloft
。
\documentclass[12pt,english]{extreport}
\usepackage{mathpazo}
\usepackage{berasans}
\renewcommand{\ttdefault}{cmtl}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[T1]{fontenc}
\usepackage[latin9]{luainputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=2.5cm,bmargin=2.5cm,lmargin=3cm,rmargin=2cm}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{babel}
\usepackage{array}
\usepackage{longtable}
\usepackage{varioref}
\usepackage{float}
\usepackage{textcomp}
\usepackage{multirow}
\usepackage{amstext}
\usepackage{graphicx}
\usepackage{setspace}
\onehalfspacing
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}
\floatstyle{ruled}
\newfloat{algorithm}{tbp}{loa}[chapter]
\providecommand{\algorithmname}{Algorithm}
\floatname{algorithm}{\protect\algorithmname}
%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{algorithm,algpseudocode}
\usepackage{etoolbox}
\usepackage{tocbasic}
\DeclareTOCStyleEntry[
indent=0pt,
numwidth=3.5em,
onstarthigherlevel=\vskip10pt\LastTOCLevelWasLower
]{tocline}{figure}
\DeclareTOCStyleEntry[
level=0,
beforeskip=10pt,
indent=0pt,
numwidth=0pt,
entryformat=\textbf,
linefill=\hfill,
pagenumberformat=\@gobble
]{tocline}{chapterinlistof}
\patchcmd{\listof}% <cmd>
{\float@listhead}% <search>
{\@namedef{l@#1}{\l@figure}\float@listhead}% <replace>
{}{}% <success><failure>
\preto\figure{%
\ifnum\value{figure}=0\addcontentsline{lof}{chapterinlistof}{Chapter \thechapter}\fi
}
\preto\table{%
\ifnum\value{table}=0\addcontentsline{lot}{chapterinlistof}{Chapter \thechapter}\fi
}
\preto\algorithm{%
\ifnum\value{algorithm}=0\addcontentsline{loa}{chapterinlistof}{Chapter \thechapter}\fi
}
\@ifundefined{showcaptionsetup}{}{%
\PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\AtBeginDocument{
\def\labelitemii{\(\circ\)}
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listof{algorithm}{List of Algorithms}
\chapter{Background}
\begin{figure}[H]
\caption{Fig1}
\end{figure}
\chapter{System Design}
\begin{figure}[H]
\caption{Fig2}
\end{figure}
\begin{figure}[H]
\caption{Fig3}
\end{figure}
\begin{algorithm}[H]
\begin{algorithmic}[1] \If{$x < \mu$} \State{$\hat{x} \leftarrow 0$} \Else{ } \State{$\hat{x} \leftarrow x$} \EndIf \end{algorithmic}\caption{Custom Zero Minus Means Algorithm}
\end{algorithm}
\end{document}