[Tex/LaTex] Place table at end of chapter

floats

I have a very large tabular which I want placed at the end of my chapter. I need it inside a float because I want a caption. I could simply put the code at the end of the chapter and use [h] or even [h!] placement modifier. But I'd prefer to keep the code at a different location in the text. I do not want to use a package like endfloat since this is the only float I wish to stick at the end of a chapter.

Best Answer

The following setup delays the placement of a single float to the end of a chapter. The environ package allows to capture the contents of an environment into a macro (see How can one pass the contents of a LaTeX environment to a macro?). Making sure that any banked/stored float is flushed \AtEndDocument.

enter image description here

\documentclass{book}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{environ}% http://ctan.org/pkg/environ
\let\chapendfigure\relax
\let\oldchapter\chapter
\renewcommand{\chapter}{\chapendfigure\oldchapter}
\AtEndDocument{\chapendfigure}
\NewEnviron{chapendfig}{%
  \global\let\chapendfigureBODY\BODY%
  \gdef\chapendfigure{%
      \begin{figure}\chapendfigureBODY\end{figure}%
        \let\chapendfigure\relax%
    }%
}
\begin{document}
\chapter{A chapter}
\begin{figure}
  \centering\rule{.8\textwidth}{.2\textwidth}\caption{A figure}
\end{figure}
\begin{chapendfig}
  \centering\rule{.8\textwidth}{.2\textwidth}\caption{Another figure}
\end{chapendfig}
%\show\chapendfigure
%\show\chapendfigureBODY
\lipsum[1-25]
\chapter{Another chapter}
\end{document}

The final figure positioning can be changed inside the \chapendfigure macro (defined inside the chapendfig environment. Even though the above example delays a figure, it can be used for table (or any other float) as well.

Related Question