We all know the two floating environments [cci_latex]table[/cci_latex] and [cci_latex]figure[/cci_latex] 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 [cci_latex]scheme[/cci_latex] environment. Although the latter is easily obtained using the [cci_latex]chemmacros[/cci_latex] package and its [cci_latex]scheme[/cci_latex] 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 how [cci_latex]article.cls[/cci_latex] defines [cci_latex]figure[/cci_latex] or [cci_latex]table[/cci_latex]:
[cce_latex]\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}[/cce_latex]
Many details are hardcoded here which means the code isn’t really flexible. But on the other hand it doesn’t need to be as it can be changed at any time (supposing you have it in your preamble).
Using the newfloat package
The [cci_latex]newfloat[/cci_latex] is by the same author as the popular [cci_latex]caption[/cci_latex] and [cci_latex]subcaption[/cci_latex] packages. If you are using the [cci_latex]caption[/cci_latex] 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:
[cce_latex]\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}[/cce_latex]
Using KOMA-Script
Instead of the [cci_latex]newfloat[/cci_latex] package you can use the [cci_latex]tocbasic[/cci_latex] package which is used by any KOMA-Script class. So if you are using such a class like [cci_latex]scrartcl[/cci_latex] or [cci_latex]scrbook[/cci_latex] 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:
[cce_latex]\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}[/cce_latex]
Floats defined this way obey KOMA-Script’s options for further customization
With the memoir class
The [cci_latex]memoir[/cci_latex] 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 [cci_latex]memoir[/cci_latex]’s definition of [cci_latex]figure[/cci_latex].
[cce_latex]\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}[/cce_latex]
Using the floatrow package
According to documentation of the [cci_latex]floatrow[/cci_latex] package the following code should work:
[cce_latex]\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}[/cce_latex]
But in fact it doesn’t. While the floating environment itself is defined and works the list stays empty. This strongly suggests a bug in the [cci_latex]floatrow[/cci_latex] package. However, I haven’t been able to debug it.
Using the float package
The [cci_latex]float[/cci_latex] package is the oldest of the packages in this lists but it still works:
[cce_latex]\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}[/cce_latex]
I usually don’t recommend it – mostly for personal reasons – but it is usable and makes the list complete.
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.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
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.