Graphics, Figures & Tables\listof for custom floats and page layout

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
lisaclark
Posts: 2
Joined: Wed Sep 21, 2016 3:02 pm

\listof for custom floats and page layout

Post by lisaclark »

Hi,

I am trying to format a list of custom floats ("projects") and have partially succeeded. However, for some reason, I keep getting blank pages in between the chapter heading and the list of entries. This does not happen for \listoffigures and \listoftables however.

My code for the projects and \listof is:

Code: Select all

\documentclass[12pt,a4paper,twoside]{memoir} 
% to write a new list of projects
\usepackage{float}
\floatstyle{plain}
\newfloat{project}{thp}{lop}
\floatname{project}{Project}
\chapterstyle{section} % try also: hangnum, default , section , hangnum , companion , article, demo
\begin{document}

\tableofcontents* % the asterisk means that the contents itself isn't put into the ToC

\chapter{Executive Summary}
\chapter{Chapter 1}

\begin{table}[h!]
  \centering
  \caption{Caption for the table.}
  \label{tab:table1}
  \begin{tabular}{l|c||r}
    1 & 2 & 3\\
    \hline
    a & b & c\\
  \end{tabular}
\end{table}

\begin{project}
        \refstepcounter{project}\label{proj:blah}\addcontentsline{lop}{figure}{\theproject~~{This is an example caption}}       
                \begin{itemize}
                        \item Possible project 
                \end{itemize}
\end{project}

\appendix
\chapter{ List of Tables}
\listoftables

\chapter{ List of Projects}
\listof{project}{}

\end{document}
Why is there a blank page between the heading for "List of Projects" chapter, but not in the "List of Tables"? I have tried using "onepage" option and it doesn't help.

Thanks!
Last edited by cgnieder on Wed Sep 21, 2016 8:00 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

\listof for custom floats and page layout

Post by cgnieder »

Welcome to the forum!

With the memoir class you do not need the float package. memoir has its own commands for defining floats. I admit that it is not quite as easy, though:

Code: Select all

\newfloat[chapter]{project}{lop}{Project}
\renewcommand*\theproject{\thechapter.\arabic{project}}

\newlistof{listofprojects}{lop}{List of Projects}
\newlistentry[chapter]{project}{lop}{0}
\cftsetindents{project}{0em}{2.3em}
In order to have a completely equivalent definition like the table and figure floats one even needs some additional definitions. The following definitions are necessary for floats to behave correctly in front-, main- and backmatter. If you don't use \frontmatter, \mainmatter and \backmatter you can leave them away:

Code: Select all

\g@addto@macro\@memfront@floats{\counterwithout{project}{chapter}}
\g@addto@macro\@memmain@floats{\counterwithin{project}{chapter}}
\g@addto@macro\@memback@floats{%
  \counterwithin{project}{chapter}%
  \setcounter{project}{0}%
}
If you also plan to use the article option then also add the following:

Code: Select all

\ifartopt
  \counterwithout{project}{chapter}
\fi
IMHO those additions should be handled by the \newfloat macro. Maybe we should ask the memoir maintainer whether the class can improved in this aspect…

A complete example:

Code: Select all

\documentclass[12pt,a4paper,twoside]{memoir}

\newfloat[chapter]{project}{lop}{Project}
\renewcommand*\theproject{\thechapter.\arabic{project}}

\newlistof{listofprojects}{lop}{List of Projects}
\newlistentry[chapter]{project}{lop}{0}
\cftsetindents{project}{0em}{2.3em}

\makeatletter
\g@addto@macro\@memfront@floats{\counterwithout{project}{chapter}}
\g@addto@macro\@memmain@floats{\counterwithin{project}{chapter}}
\g@addto@macro\@memback@floats{%
  \counterwithin{project}{chapter}%
  \setcounter{project}{0}%
}
\ifartopt
  \counterwithout{project}{chapter}
\fi

\begin{document}

\tableofcontents*

\chapter{A normal chapter}

\begin{table}[h!]
  \centering
  \caption{Caption for the table.}
  \label{tab:table1}
  \begin{tabular}{l|c||r}
    1 & 2 & 3 \\
   \hline
    a & b & c
  \end{tabular}
\end{table}

\begin{project}
  \caption{This is an example caption.}
  \label{proj:blah}  
  \begin{itemize}
    \item Possible project
  \end{itemize}
\end{project}

\appendix
\listoftables
\listofprojects

\end{document}
The minimized example without additional definitions:

Code: Select all

\documentclass[12pt,a4paper,twoside]{memoir}

\newfloat[chapter]{project}{lop}{Project}
\renewcommand*\theproject{\thechapter.\arabic{project}}

\newlistof{listofprojects}{lop}{List of Projects}
\newlistentry[chapter]{project}{lop}{0}
\cftsetindents{project}{0em}{2.3em}

\begin{document}

\tableofcontents*

\chapter{A normal chapter}

\begin{table}[h!]
  \centering
  \caption{Caption for the table.}
  \label{tab:table1}
  \begin{tabular}{l|c||r}
    1 & 2 & 3 \\
   \hline
    a & b & c
  \end{tabular}
\end{table}

\begin{project}
  \caption{This is an example caption.}
  \label{proj:blah}  
  \begin{itemize}
    \item Possible project
  \end{itemize}
\end{project}

\appendix
\listoftables
\listofprojects

\end{document}
Regards
site moderator & package author
lisaclark
Posts: 2
Joined: Wed Sep 21, 2016 3:02 pm

\listof for custom floats and page layout

Post by lisaclark »

Thank you very much for the solution. It worked and I solved my problem!
Post Reply