# All figures at end of section (or Chapter) but in the order they were cited in the text

I've been trying to do this for so long, it would make my life so much easier.

I have a *.tex file containing all the details of the figures in a chapter (but not necessarily in the right order), because the first thing I do when I'm writing is make all the figures, but I don't know what order I'll need them.

Then I want to be able to reference this file at a particular point so I insert:

\input{figures.tex}


and all the figures appear, and that's great, but the thing is, I want them to be ordered by the location that they are first cited in the text, because I make the figures first, and I'm not sure what order I will use them.

Up till now I end up scouring the document finding the references and ordering the figure order at the end manually, but this isn't very efficient.

Alternatively can anyone suggest another workflow/method that would enable me to achieve something similar. (like maybe inserting the figures at a particular place but them only appearing at the end in a section I designate) Cheers!

edit:

So this is my main tex file

\documentclass{article}
\usepackage{graphicsx}
\begin{document}

\section{the text}
text text text \ref{justafig} more text \ref{asecondfig}

\section{the figures}

\input{figures}

\end{document}


then this is figures.tex

\begin{figure}[tbp]%one column
\centering{
\includegraphics[width=160mm]{./figa.png}}
\caption{the caption}
\label{asecondfig}
\end{figure}

\begin{figure}[tbp]%one column
\centering{
\includegraphics[width=160mm]{./figb.png}}
\caption{the caption}
\label{justafig}
\end{figure}


But this inserts the figures in the order then are in figures.tex and I want them in the order they are cited in the text

• Welcome to TeX.SX! The magic word is MWE -- Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Aug 27 '14 at 19:40
• If you cite (\ref?) a figure, it has a definite counter value (say Figure 10). If this your first figure cited, it will become Figure 1 effectively, is that correct? How do you track, which figure is cited first? – user31729 Aug 27 '14 at 19:51
• You missed \usepackage{graphicx} (or in this case better \usepackage[demo]{graphicx} in your main.tex And remove the\figure command in your figures.tex – user31729 Aug 27 '14 at 19:55
• Oh yeah, they're just typos I have/don't have those in the actual source I'm using – Tom Aug 27 '14 at 20:00
• While thinking about your question, I asked myself: How to reorder figure environments in a file? ;-) – user31729 Aug 27 '14 at 20:01

Use a tex file for each figures details and insert using \input{figdetails} at the correct point in the text.
Add the package endfloat at the start of the document.