Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Nov 28 '11 at 5:02

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

    
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
add comment

1 Answer 1

up vote 4 down vote accepted

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}}
  \float@listhead{List of Schemas}%
  \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.

enter image description here

\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}}
  \float@listhead{List of Schemas}%
  \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
\preto\chapter{\float@addtolists{\protect\addvspace{10pt}}}%
\makeatother

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:

enter image description here

share|improve this answer
    
Wow, 7:30 AM on Monday, about eight hours after I posted--and it works perfectly! Thank you!!! –  Mike Maxwell Nov 28 '11 at 12:54
    
@MikeMaxwell: Note that there is no gap between the schemas from one chapter to the next (as is the case with regular figures/tables). This is also possible. Regardless, if this answered your question, consider upvoting (with the upward pointing arrow to the left of it; you need 15 reputation points before you can upvote) and accepting it (by clicking on the checkmark). –  Werner Nov 28 '11 at 15:45
    
Not sure what you mean by "gap between the schemas"--they're numbered consecutively starting from 1 within each chapter, which is what I wanted. And I "upvoted" and check-marked it :-) –  Mike Maxwell Nov 29 '11 at 4:07
    
@MikeMaxwell: There's a small gap between the figures in each chapter of the LoF (between Figure 1.3 and 2.1 in my example), while there's nothing between the schemas for each chapter. That is the gap I'm referring to. –  Werner Nov 29 '11 at 7:14
    
"Note that there is no gap between the schemas from one chapter to the next... This is also possible." I thought I could figure this out, but no soap. I presume it would be done with a command like "\float@addtolists{\protect\addvspace{10pt}}" (copied from the 'floats' documentation), but I can't figure out where to put this--depending on where I put it, it either has no visible effect, or causes an error. –  Mike Maxwell Dec 2 '11 at 17:16
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.