图表列表 - 如何将标题标签移至标题本身

图表列表 - 如何将标题标签移至标题本身

我正在使用article文档类(作为基础)和caption包。我本质上需要将我的 LoF 格式从默认格式更改为

List of Figures  
1 Multiline caption multiline caption multiline caption multiline caption multiline caption
  multiline caption multiline caption
2 Multiline caption multiline caption multiline caption multiline caption multiline caption
  multiline caption multiline caption

更改为以下内容:

List of Figures
Figure 1. Multiline caption multiline caption multiline caption multiline caption multiline
caption multiline caption multiline caption
Figure 2. Multiline caption multiline caption multiline caption multiline caption multiline
caption multiline caption multiline caption

我也需要对我的 LoT 格式执行相同的操作。

标签是指指示图形/表格索引的数字。

我假设在仍然使用标签时不可能获得所需的输出,那么我该如何将标签移动到其标题中,删除标签本身,并删除缩进?(如果可以将标签与其标题“内联”,那么这就是我所需要的。)

如果无法修改\listoffigures\listoftables执行此操作,我该如何创建所需的环境?

编辑:我使用以下方法修改了 Peter Wilson 的答案tocloft

\renewcommand{\@tocrmarg}{2.5pc plus1fil} % Set ToC/LoF/LoT entries to ragged-right
% Set formatting for the LoF ande LoT (fig/tab numbers >999 will clip caption)
\newlength{\mylen}
% Set formatting for LoF
\renewcommand{\cftfigpresnum}{Figure } % goes before figure number
\renewcommand{\cftfigaftersnum}{.} % Goes after figure number
\settowidth{\mylen}{\cftfigpresnum} % space required to print \cftfigpresnum
\addtolength{\mylen}{\cftfignumwidth} % plus space for the number
\renewcommand{\cftfigaftersnumb}{\hspace{\mylen}} % add space after the zero-spaced number
\cftsetindents{figure}{0pc}{0pc} % Remove caption indent, and flush entries with title
\setlength{\cftbeforefigskip}{0.5pc} % Add small gap between LoF entries
% Set formatting for LoT
\renewcommand{\cfttabpresnum}{Table }
\renewcommand{\cfttabaftersnum}{.}
\settowidth{\mylen}{\cfttabpresnum}
\addtolength{\mylen}{\cfttabnumwidth}
\renewcommand{\cfttabaftersnumb}{\hspace{\mylen}}
\cftsetindents{table}{0pc}{0pc}
\setlength{\cftbeforetabskip}{0.5pc}

编辑2:我如何移动标签或用tocbasic而不是将标题左移tocloft?MWE:

\documentclass{article}
%\documentclass[listof=totoc,listof=leveldown]{scrartcl}
\usepackage{lipsum}
\usepackage{hyperref}% Used in actual project, provides \phantomsection

\usepackage[justification=raggedright,singlelinecheck=false]{caption}
\usepackage{float}
\usepackage{pgffor}
\usepackage{tocbasic}
%\tocbasicautomode % What does this do?
\newcommand*{\addfigdot}[1]{\figurename\ #1\unskip.\hfil}
\newcommand*{\addtabdot}[1]{\tablename\ #1\unskip.\hfil}
\DeclareTOCStyleEntries[
    %breakafternumber,% Somehow manages to flush at least the first line left?
    beforeskip=.5pc,% Add space between entries
    indent=0pc,% Remove basic indent
    entrynumberformat=\addfigdot,% Reformat prefix to "Figure <num>. "
    raggedentrytext,% Disable caption justification in LoF
    dynnumwidth% Needed to properly align caption with prefix
]{tocline}{figure,table}
\DeclareTOCStyleEntry[entrynumberformat=\addtabdot]{tocline}{table}

\begin{document}
\tableofcontents

\section{Figures and Tables}
\foreach\n in {1,...,3}{\begin{figure}[H]\caption{\lipsum[\n][1-3]}\end{figure}}
\foreach\n in {1,...,3}{\begin{table}[H]\caption{\lipsum[\n][1-3]}\end{table}}

% Print LoF and LoT, and add them to ToC
\cleardoublepage
\phantomsection\addcontentsline{toc}{section}{\listfigurename}
\listoffigures
\cleardoublepage
\phantomsection\addcontentsline{toc}{section}{\listtablename}
\listoftables
\end{document}

答案1

试试这个(尽量避免拼写错误):

\documentclass{article}
\usepackage{tocloft}
\newlength{\mylen} % a scratch length
\renewcommand{\cftfigpresnum}{Figure } % goes before figure number
\settowidth{\mylen}{\cftfigpresnum} % space required to print \cftfigpresnum
\addtolength{\mylen}{\cftfignumwidth} % plus space for the number
\setlength{\cftfignumwidth}{0em} % but make this zero 
\renewcommand{\cftfigaftersnumb}{\hspace{\mylen}} % add space after the zero-spaced number
\renewcommand{\cfttabpresnum}{Table } % repeat above for Tables
\settowidth{\mylen}{\cfttabpresnum}
\addtolength{\mylen}{\cfttabnumwidth}
\setlength{\cfttabnumwidth}{0em}
\renewcommand{\cfttabaftersnumb}{\hspace{\mylen}}

\begin{document}
\section{A section}
Some text

\begin{figure}
\centering
A FIGURE
\caption{A very long caption for a figure where the caption will extend over one
         line in the LoF hopefully like this}
\end{figure}
\begin{table}
\centering
A TABLE
\caption{Table caption}
\end{table}

\end{document}

对长度的所有调整都是为了让 LoF 和 LoT 多行条目打印时第二行及后续行与标签对齐(用您的话来说)。

阅读tocloft文档(> texdoc tocloft)以了解更多信息。

答案2

\caption可以使用包装命令将字符串插入到短格式选项中:

\documentclass{article}

\usepackage{lipsum}
\usepackage{float}
\usepackage{etoolbox}
\usepackage[listformat=empty]{caption} % Remove figure/table numbers from LoF/LoT
\usepackage{tocloft}
    % Add spacing between LoF/LoT entries
    \setlength{\cftbeforefigskip}{0.5pc}
    \setlength{\cftbeforetabskip}{0.5pc}
    % Remove LoF/LoT indents
    \cftsetindents{figure}{0pc}{0pc}
    \cftsetindents{table}{0pc}{0pc}

\newcommand\makecaptioncmd[1]{%
    \newcommand\mycaption[1]{{\caption[#1 {##1}]{{##1}}}}}
\AtBeginEnvironment{figure}{%
    \makecaptioncmd{\figurename\ \thefigure.}}
\AtBeginEnvironment{table}{%
    \makecaptioncmd{\tablename\ \thetable.}}

\begin{document}
\begin{figure}[H]\mycaption{\lipsum[1][1-3]}\end{figure}
\begin{figure}[H]\mycaption{\lipsum[2][1-3]}\end{figure}
\begin{table}[H]\mycaption{\lipsum[3][1-3]}\end{table}
\begin{table}[H]\mycaption{\lipsum[4][1-3]}\end{table}
\listoffigures
\listoftables
\end{document}

相关内容