Set width of LaTeX float # in List of X

Using the LaTeX float package, I've created a new float:

\newfloat{schema}{htb}{los}[chapter]
\floatname{schema}{{Schema}}


The list of schemas at the beginning of my document is created with the command

\listof{schema}{List of Schema}


My problem is that LaTeX isn't reserving as much space as I'd like for the schema number in the List of Schemas. When a schema number consists of three digits, like

\numberline {5.14}


then the last digit of this number comes quite close to the first letter of the caption of the schema. (In fact, if the number has four digits, it can actually overlap the caption.)

I tried to come up with a solution using the tocloft package, but I couldn't figure out how to make that work in conjunction with the \newfloat command--it sounds like I should tell tocloft to change a numwidth variable associated with my 'schema' float, but I have not been able to figure out what the name of that variable is (it's not schemanumwidth or anything else obvious). It may be that tocloft just doesn't know about floats created with the float package's \newfloat command.

I finally came up with a dirty hack:

\let\orignumberline\numberline
\renewcommand{\numberline}[1]{\orignumberline{#1}\hspace{1em}}


This wouldn't be too bad if it affected only my List of Schemas, but of course it also affects the chapter and section #s in the ToC, the table #s in the ToT, etc., all of which had perfectly adequate spacing before (and now look a little odd with a too-wide spacing).

This seems like the sort of thing that ought to work out of the box: if I define a new float, and create a list of them, then LaTeX ought to leave enough space between the float # and the float caption in the listing of this float. Am I overlooking something obvious?

-
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Nov 28 '11 at 5:14

migrated from stackoverflow.comNov 28 '11 at 5:02

This question came from our site for professional and enthusiast programmers.

The float package defines the \listof command the does some float checks, sets up the "List of Floats" parameters and calls \@starttoc. A manual definition of the specific "List of Floats" in this case is possible:

\makeatletter
\newcommand{\listofschemas}{%
\@namedef{l@schema}{\@dottedtocline{1}{1.5em}{4em}}
\begingroup\setlength{\parskip}{\z@}%
\@starttoc{\@nameuse{ext@schema}}%
\endgroup%
}%
\makeatother


The most important part here is

\@namedef{l@schema}{\@dottedtocline{1}{1.5em}{4em}}


that uses

\@dottedtocline{<seclevel>}{<indent>}{<numwidth>}


The default for <numwidth> is 2.3em, giving the width of the sectional heading in the "List of Floats". I've modified this to 4em to make it almost twice as wide.

\documentclass{book}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{float}% http://ctan.org/pkg/float
\newfloat{schema}{htb}{los}[chapter]
\floatname{schema}{Schema}%
\makeatletter
\newcommand{\listofschemas}{%
\@namedef{l@schema}{\@dottedtocline{1}{1.5em}{4em}}
\begingroup\setlength{\parskip}{\z@}%
\@starttoc{\@nameuse{ext@schema}}%
\endgroup%
}%
\makeatother
\begin{document}
\listoffigures
\listofschemas
\chapter{A chapter} \lipsum[1]
\begin{figure} \centering test \caption{A figure} \end{figure}% FIGURE
\begin{schema} \centering test \caption{A schema} \end{schema}% SCHEMA
\begin{figure} \centering test \caption{A figure} \end{figure}% FIGURE
\begin{figure} \centering test \caption{A figure} \end{figure}% FIGURE
\begin{schema} \centering test \caption{A schema} \end{schema}% SCHEMA
\chapter{Another chapter} \lipsum[2]
\begin{figure} \centering test \caption{A figure} \end{figure}% FIGURE
\begin{schema} \centering test \caption{A schema} \end{schema}% SCHEMA
\begin{figure} \centering test \caption{A figure} \end{figure}% FIGURE
\begin{figure} \centering test \caption{A figure} \end{figure}% FIGURE
\begin{schema} \centering test \caption{A schema} \end{schema}% SCHEMA
\end{document}


This will be specific to the "List of Schemas".

If you wish to add a vertical gap between entries in the "List of Schemas" to separate schemas by chapter, add

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter

to your document preamble. The etoolbox package is capable of patching commands; in this case, prepending some content before \chapter via \preto\chapter{<stuff>}. Here <stuff> adds up to a 10pt vertical gap between all the defined "List of..." structures (except LoF and LoT). \addvspace takes care of only adding 10pt if needed. For example, if you have a chapter without any schemas in it, you don't want the gap between chapter-wise schemas in the "List of Schemas" to be 20pt. Using the above MWE together with the etoolbox addition yields: