# force floats to end of pdf, but keep numbering per chapter (two versions of document pdf)

I have a lot of my figures in floats, and LaTeX puts them on good places in the pdf. But for my students it would be great if I could produce a second pdf-version of the same text, without the figures in the text, and all the figures in a separate document. Why?

• figures are in colour, so students can print these figures on a better quality printer.
• Also, while studying, it is for some students more comfortable to have the figures separate to the text, because I often refer to a figure that appears a few pages earlier then the second or third reference in the text. Of course, the numbering (like "fig. 2.1") should be kept unchanged, so the numbering in both versions of the document stays the same.

I tried using endfloat, pushing all the floats to the end, but then all the numbers start with the number of the last chapter (e.g. 2.1, where it orig. was 1.1). In the example below, the "first version" (which is OK) is produced: the figures are placed in the text by LaTeX, and this placement is fine.

I'm trying to make the second version, just by uncommenting the two lines that are commented in the example. Then you'll see that figures in fact are pushed to the end as desired, but numbers change (undesired, because different from first version).

\documentclass[a4paper,oneside,dutch]{book}

%\usepackage[nomarkers, nolists]{endfloat} %these two lines should be uncommented
%\renewcommand{\efloatseparator}{\mbox{}} %these two lines should be uncommented

\begin{document}
\chapter{first chapter}
\section{first section}
Some text referring to this figure, with a number that shows the figure belongs to chapter one: fig.~\ref{fig: 050}.
\begin{figure}
\begin{centering}
{\fboxsep 14pt\fbox{}}
\par\end{centering}
\caption{\label{fig: 050}figure in chapter one}
\end{figure}
Some other text referring to another figure int the same chapter: fig.~\ref{fig: 052}
\begin{figure}
\begin{centering}
{\fboxsep 14pt\fbox{}}
\par\end{centering}
\caption{\label{fig: 052}another figure in chapter one}
\end{figure}
\chapter{second chapter}
Some text in chapter two, so referring to a fig. with numbering that shows the figure is part of chapter two: fig.~\ref{fig: 054}.
\begin{figure}
\begin{centering}
{\fboxsep 14pt\fbox{}}
\par\end{centering}
\caption{\label{fig: 054}this figure belongs to chapter two}
\end{figure}
\end{document}


Is there a workaround? Or another simple way to achieve this? I've had a suggestion to use "preview", but this doesn't seem to solve my problem as a whole... Or is it wishfull thinking to be able to produce the two desired versions?

• You should really make it easy for us to help you by providing a minimal example that replicates your current setup. Something we can copy-and-paste-and-compile and see exactly what you're currently dealing with. – Werner Dec 19 '17 at 7:42
• Does it help? tex.stackexchange.com/questions/3491/… – Ignasi Dec 19 '17 at 7:57
• Crosspost on LaTeX.org – Johannes_B Dec 19 '17 at 11:07

You could try something like this (it assumes that the figures are really at the end with endfloat):

\documentclass{book}
\usepackage{etoolbox}
\usepackage[nomarkers]{endfloat}
\makeatletter
{
\efloat@condopen{fff}
\pretocmd\@chapter{\immediate\write\efloat@postfff{\noexpand\stepcounter{chapter}}}{}{\fail}
\AtBeginFigures{\setcounter{chapter}{0}}
}{}
\makeatother
\usepackage{hyperref}
\begin{document}
\chapter{A}
\begin{figure}
\caption{a figure in chapter 1}\label{fig:1}
\end{figure}

\begin{figure}
\caption{a second figure in chapter 1}
\end{figure}

see \ref{fig:1} and \ref{fig:2}

\chapter{B}
\begin{figure}
\caption{a figure in chapter 2}
\end{figure}

\begin{figure}
\caption{a second figure in chapter 2}\label{fig:2}
\end{figure}

\end{document}

• Great! For the tables, I used "\AtBeginTables{\setcounter{chapter}{...}}". 2 smaller problems: *I have to change the values for the "setcounter{chapter}" to "-4" for the figures and "4" for the tables :-). This seems to be dependent wether I add a table-of-contents/table-of-figures/chapter-without-numer-as-preface/... before the first "real" chapter. Also the first appearance of a table seems to matter? I'm obiously missing something fundamental here... *I also use fancyheaders, is there a way to use these adapted headerstyle also in the part where the figures are? – Stef Pillaert Dec 19 '17 at 18:56
• It should be \@chapter and not \chapter to avoid problems with unnumbered chapter. And if you want to move tables too, you must add line for ttt similar to the one for fff. – Ulrike Fischer Dec 19 '17 at 21:30
• This is perfect! – Stef Pillaert Dec 20 '17 at 7:17