1

I'm using the article document class (as a base) and the caption package. I essentially need to change my LoF format from the default

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

to the following:

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

I also need to do the same for my LoT format.

By label I mean the numbers indicating the index of the figure/table.

I'm assuming it's not possible to get the desired output while still using the labels, so how would I move the labels into their captions, remove the labels themselves, and remove the indent? (If it is possible to "inline" the label with its caption then that's all I need.)

If it's not possible to modify \listoffigures and \listoftables to do so, how would I create the needed environments to do so?

Edit: My revised version of the Peter Wilson's answer using 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}

Edit2: How do I move the label or flush the caption left with tocbasic instead of 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}
6
  • Your question is very unclear, you should provide a small complete test document. It appears that the only thing you want to do is prefix the entries with Figure but that seems completely unrelated to processing of \label Commented Nov 20, 2018 at 16:55
  • I'm using the term "label" informally to refer to the figure numbers. I want to do something similar to tex.stackexchange.com/q/12865/156666, but I want the "Figure <number>." to be inline with the caption. Commented Nov 20, 2018 at 17:16
  • but still you are asking how to modify your existing code without saying what that is, caption formatting is highly dependent on the document class you are using and any related packages such as caption that you may have loaded. So not really possible to suggest anything just from the ascii sketch shown. Commented Nov 20, 2018 at 17:24
  • By default tocloft makes no changes to the ToC. It only makes changes to the ToC, LoF, or LoT that you tell it to. Please show your code. Commented Nov 20, 2018 at 19:02
  • @TakingItCasual don't link to an external site, your question and any answers are archived here forever and will not make sense if they are based on a changing link, make a small test document preferably using a standard class that shows the problem and say what output you want and add it to the question as a code block. Commented Nov 20, 2018 at 19:06

2 Answers 2

2

Try this (less any typos):

\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}

All the fiddling about with lengths is to make the LoF and LoT multiline entries print with the second and later lines aligned with (in your words) the label.

Read the tocloft documentation (> texdoc tocloft) for more information.

4
  • Any idea how to get rid of the "Overfull \hbox" warnings I'm getting for every LoF and LoT entry? Commented Nov 21, 2018 at 8:51
  • @TakingItCasual The number (and whatever you add to it) is typeset in an \hbox of given width (\cftfignumwidth in this case) followed by the caption text in a rectangular format. As you want the number and text be be all left justified this can be done with a zero \cftfignumwidth and hence the overfull warnings. The typeset output is OK except if you use a draft class option. Perhaps someone else will be able to help you but I think that on the whole you have got something that works. Commented Nov 23, 2018 at 19:25
  • Is there a way to do this with tocbasic (e.g. with \DeclareTOCStyleEntry)? I've edited my question with a MWE. Commented Jun 25, 2020 at 8:51
  • @TakingItCasual I have no idea. I have never used tocbasic and am unlikely to ever do so. --- GOM Commented Jun 25, 2020 at 17:48
1

A wrapper command to insert the string into \caption's short-form option can be used:

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .