Foreword
We all know the two floating environmentstable
and figure
which almost all document classes provide. Every once in a while there is the need for another floating environment. For example chemists often need something like a scheme
environment. Although the latter is easily obtained using the chemmacros
package and its scheme
module I want to show the several methods I know for defining new floats.
Manual definition
The manual definition is a bit tedious as there need to be quite a number of internal macros defined for a float type. The code below demonstrates this for a float named “scheme” defined analogous to howarticle.cls
defines figure
or table
:
\documentclass{article}
\makeatletter
\newcounter{scheme}% the counter
\renewcommand*\thescheme{\arabic{scheme}}% the default format for the counter
\newcommand*\fps@scheme{tbp}% default floating options
\newcommand*\ftype@scheme{4}% float type number, needs to be a power of 2;
% \ftype@figure=1, \ftype@table=2
\newcommand*\ext@scheme{los}% extension of file for the list of schemes
\newcommand*\fnum@scheme{\schemename\nobreakspace\thescheme}% used in caption
\newcommand*\schemename{Scheme}% the name
\newcommand*\listschemename{List of schemes}% the name of the list
\newenvironment{scheme}{\@float{scheme}}{\end@float}% the environment
\newenvironment{scheme*}{\@dblfloat{scheme}}{\end@dblfloat}% the starred
% version for twocolumn documents
\newcommand*\listofschemes{% the list of schemes
\section*{\listschemename}
\@mkboth
{\MakeUppercase\listschemename}
{\MakeUppercase\listschemename}
\@starttoc{\ext@scheme}
}
\let\l@scheme\l@figure % layout of list is the same as for figures
\makeatother
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
\makeatletter
\newcounter{scheme}% the counter
\renewcommand*\thescheme{\arabic{scheme}}% the default format for the counter
\newcommand*\fps@scheme{tbp}% default floating options
\newcommand*\ftype@scheme{4}% float type number, needs to be a power of 2;
% \ftype@figure=1, \ftype@table=2
\newcommand*\ext@scheme{los}% extension of file for the list of schemes
\newcommand*\fnum@scheme{\schemename\nobreakspace\thescheme}% used in caption
\newcommand*\schemename{Scheme}% the name
\newcommand*\listschemename{List of schemes}% the name of the list
\newenvironment{scheme}{\@float{scheme}}{\end@float}% the environment
\newenvironment{scheme*}{\@dblfloat{scheme}}{\end@dblfloat}% the starred
% version for twocolumn documents
\newcommand*\listofschemes{% the list of schemes
\section*{\listschemename}
\@mkboth
{\MakeUppercase\listschemename}
{\MakeUppercase\listschemename}
\@starttoc{\ext@scheme}
}
\let\l@scheme\l@figure % layout of list is the same as for figures
\makeatother
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
Using the newfloat package
Thenewfloat
is by the same author as the popular caption
and subcaption
packages. If you are using the caption
package anyway then this is definitely the choice for defining new floating environments. You’ll be able to use the full power of both packages for customization. Also: the code is a lot easier:
\documentclass{article}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext = los ,
listname = {List of schemes} ,
name = Scheme
]{scheme}
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
\usepackage{newfloat}
\DeclareFloatingEnvironment[
fileext = los ,
listname = {List of schemes} ,
name = Scheme
]{scheme}
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
Using KOMA-Script
Instead of thenewfloat
package you can use the tocbasic
package which is used by any KOMA-Script class. So if you are using such a class like scrartcl
or scrbook
you don’t have to load the package. The code is similarly easy. The following code indicates that there are a number of options for customization:
\documentclass{article}
\usepackage{tocbasic}% or a KOMA-Script class like `scrartcl'
\DeclareNewTOC[
type = scheme ,
% types = schemes ,
float ,
% name = Scheme ,
% listname = {List of Schemes}
]{scheme}
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
\usepackage{tocbasic}% or a KOMA-Script class like `scrartcl'
\DeclareNewTOC[
type = scheme ,
% types = schemes ,
float ,
% name = Scheme ,
% listname = {List of Schemes}
]{scheme}
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
With the memoir class
Thememoir
class also brings its own mechanism for defining floats. Unfortunately it is not as straightforward as you would think and also not as easy as the manual says. The following definition is analogous to memoir
‘s definition of figure
.
\documentclass{memoir}
\newfloat[chapter]{scheme}{los}{Scheme}
\renewcommand*\thescheme{\thechapter.\arabic{scheme}}
\newlistof{listofschemes}{los}{List of schemes}
\newlistentry[chapter]{scheme}{los}{0}
\cftsetindents{scheme}{0em}{2.3em}
\makeatletter
\addtodef\@memfront@floats{\counterwithout{scheme}{chapter}}
\addtodef\@memmain@floats{\counterwithin{scheme}{chapter}}
\addtodef\@memback@floats{\counterwithin{scheme}{chapter}\setcounter{scheme}{0}}
\makeatother
\ifartopt
\counterwithout{scheme}{chapter}
\fi
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
\newfloat[chapter]{scheme}{los}{Scheme}
\renewcommand*\thescheme{\thechapter.\arabic{scheme}}
\newlistof{listofschemes}{los}{List of schemes}
\newlistentry[chapter]{scheme}{los}{0}
\cftsetindents{scheme}{0em}{2.3em}
\makeatletter
\addtodef\@memfront@floats{\counterwithout{scheme}{chapter}}
\addtodef\@memmain@floats{\counterwithin{scheme}{chapter}}
\addtodef\@memback@floats{\counterwithin{scheme}{chapter}\setcounter{scheme}{0}}
\makeatother
\ifartopt
\counterwithout{scheme}{chapter}
\fi
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
Using the floatrow package
According to documentation of thefloatrow
package the following code should work:
\documentclass{article}
\usepackage{floatrow}
\DeclareNewFloatType{scheme}{name=Scheme}
\newcommand*\listofschemes{\listof{scheme}{List of schemes}}
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
\usepackage{floatrow}
\DeclareNewFloatType{scheme}{name=Scheme}
\newcommand*\listofschemes{\listof{scheme}{List of schemes}}
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
floatrow
package. However, I haven’t been able to debug it.
Using the float package
Thefloat
package is the oldest of the packages in this lists but it still works:
\documentclass{article}
\usepackage{float}
\newfloat{scheme}{hbp}{los}
\floatname{scheme}{Scheme}
\newcommand*\listofschemes{\listof{scheme}{List of schemes}}
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
\usepackage{float}
\newfloat{scheme}{hbp}{los}
\floatname{scheme}{Scheme}
\newcommand*\listofschemes{\listof{scheme}{List of schemes}}
\begin{document}
\begin{scheme}
\caption{bla bla}
\end{scheme}
\listofschemes
\end{document}
Hi Clemens,
let’s suppose that I have a memoir class document, and I need to add two (or more) types of schemes.
1
\begin{scheme}
\caption{Basic Scheme type}
\end{scheme}
2
\begin{otherScheme}
\caption{Other Scheme type}
\end{otherScheme}
How to create two types of lists apart for each type of schemes?
I tried to replicate same code with different names and now I have two lists with identical content and they share the same title (of the second list). This way is wrong, right? Can you suggest where to dig?
You probably used the same file for the list. I used .los in the example (spelling list of schemes). You might use .lox or something else for your second float.