# Trouble manually controlling endfloat's ToC and header behavior

In my thesis, I would like to have

• each figure and table on its own page at the end of each chapter (easy with endfloat)
• The first figure of each chapter begins its own section that goes into the ToC, but no section title appears in the actual document.
• same as the previous point, but with tables
• the page header for the figure and table sections reflects the change

Either I end the document with \processdelayedfloats and:

• the header correctly changes with the Tables section, but Tables stays in the header into the Figures section
• the ToC shows neither Tables nor Figures.

Or I uncomment the last few lines and:

• the Tables header continues into the new section for 1 page, then changes to the new section
• the ToC gets updated, but the page numbers for Figures and Tables are both the first non-float page.
• hyperref links the Figures and Tables ToC entries to neither the page listed nor the first table/figure.

For as awesome the idea of the endfloat package is, it seems to be poorly implemented in my opinion. Any help in this problem (as well as understanding how this package works) would be appreciated.

MWE:

\documentclass[oneside]{memoir}

%%%%%%%%%%%%% stop endfloat from marking both headers %%%%%%%%%%%%%
\usepackage{etoolbox}
\makeatletter
\patchcmd{\efloat@process}{\markboth}{\@gobbletwo}{}{}
\makeatother

\usepackage{lipsum}

\makepagestyle{mainMatter}
\makeoddfoot{mainMatter}{}{\thepage}{}
\makepsmarks{mainMatter}{%
\createmark{section}{right}{nonumber}{}{. \ }
\createmark{chapter}{left}{shownumber}{Chapter }{: \ }}

\usepackage{hyperref}

\begin{document}
\tableofcontents*
\pagestyle{mainMatter}
\chapter{My Chapter}
\section{My Section}
\lipsum[1]
\begin{figure}
\centering
\fbox{{\HUGE a figure}}
\caption{A Figure placed here}\label{fig:a fig}
\end{figure}
\lipsum[1]
\begin{table}
\centering
\caption{Cool table}
\begin{tabular}{lc}
A  & 100 \\
B & 41 \\
C  & 17 \\
X?!  & 0 \\
\end{tabular}
\label{tab:my table 1}
\end{table}

\begin{figure}
\centering
\fbox{{\HUGE another figure}}
\caption{A Figure placed here}\label{fig:a fig 2}
\end{figure}

\begin{table}
\centering
\caption{boring table}
\begin{tabular}{c|c}
A & B \\
\end{tabular}
\label{tab:my table 2}
\end{table}
\lipsum[1]
\processdelayedfloats
\section{Frustrated}
Note that if you uncomment the line below, suddenly the ToC gets updated (incorrectly) and the next page has a new header.
\lipsum[1-8]

\end{document}

• Did you ever thought of improving endfloat? I'm sure Jeffrey Goldberg would appreciate it. (At least he did when I have improved endfloat.) – Axel Sommerfeldt Jul 7 '13 at 5:37
• I have no idea how to program TeX. Is there a good resource for learning how? Everything I've done with TeX code has been extremely slow and haphazard (as the example below shows). The solution I found took me hours to work out and I have no idea if it even works in the general case. This was my first time using etoolbox, even. – DocBuckets Jul 7 '13 at 15:20
• Oh, so I got a wrong impression of your skills. It's a pity because Jeffrey does not improve his package anymore and I simply don't even have enough time for my very own packages -- but of course I'm willing to answer questions about implementation details. (If you want to learn TeX, I recommend "TeX by Topic" which you should get by "texdoc texbytopic".) – Axel Sommerfeldt Jul 8 '13 at 7:06

I have no idea what I'm doing, but I figured it out! The key is to:

• disable the mark both (as in the original MWE)
• enable the heads option so endfloat tries to load the \section* command...
• but first replace the \section* command in endfloat.sty with \phantomsection\addcontentsline{toc}{section}{\@nameuse{#2section}}\markright

• the problem I was having with hyperref in the ToC is fixed by \phantomsection
• The right header is replaced with \@nameuse{#2section, which is either Figures or Tables depending on the floats. without the heads option, endfloat will skip this part.
• Every figure and table is centered on its page and there are no blank pages before/after the floats thanks to the constant redefining of the default placement (thanks to \AtBeginTables, \AtBeginFigures, and \efloatseparator )

• The last float will occur before any more text as \processdelayedfloats now includes a \FloatBarrier

• The inclusion of \FloatBlock means this fix requires the memoir class. Alternatively, the placeins package can be used to substitute \FloatBarrier for \FloatBlock and (I assume) will have the same result.

Here's the new MWE that does just what I wanted it to do. I hope it's ok to answer one's own question here.

EDIT although this fix worked in my MWE, it does not work in my actual document. Maybe it's because some of the captions are long, there are other packages loaded, or I am using include to load chapters. For whatever reason, I still have this issue.

\documentclass[oneside]{memoir}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\efloat@process}{\markboth}{\@gobbletwo}{}{}
\patchcmd{\processdelayedfloats}{\processotherdelayedfloats}{\processotherdelayedfloats\FloatBlock}{}{}
\makeatother
\AtBeginTables{\setfloatlocations{table}{h}\null\vfill}
%
\AtBeginFigures{\setfloatlocations{figure}{h}\null\vfill}

\AtBeginDelayedFloats{}
\renewcommand{\efloatseparator}{\vfill\setfloatlocations{table}{p}\setfloatlocations{figure}{p}}

\usepackage{lipsum}

\makepagestyle{mainMatter}
\makeoddfoot{mainMatter}{}{\thepage}{}
\makepsmarks{mainMatter}{%
\createmark{section}{right}{nonumber}{}{. \ }
\createmark{chapter}{left}{shownumber}{Chapter }{: \ }}

\usepackage{hyperref}

\begin{document}
\tableofcontents*
\pagestyle{mainMatter}
\chapter{My Chapter}
\section{My Section}
\lipsum[1]

\begin{figure}
\centering
\fbox{{\HUGE a figure}}
\caption{A Figure placed here}\label{fig:a fig}
\end{figure}
\lipsum[1]

\begin{table}
\centering
\caption{Cool table}
\begin{tabular}{lc}
A  & 100 \\
B & 41 \\
C  & 17 \\
X?!  & 0 \\
\end{tabular}
\label{tab:my table 1}
\end{table}

\begin{figure}
\centering
\fbox{{\HUGE another figure}}
\caption{A Figure placed here}\label{fig:a fig 2}
\end{figure}

\begin{table}
\centering
\caption{boring table}
\begin{tabular}{c|c}
A & B \\
\end{tabular}
\label{tab:my table 2}
\end{table}

\lipsum[1]
\processdelayedfloats

\section{HURRAY!}
I deserve a beer.
\lipsum[1-8]

\end{document}