Strategies For Keeping Latex Tables And Figures Close To Their References
The Problem of Separated Visuals
One common frustration when writing papers and reports in LaTeX is the problem of visual elements like figures, tables, charts, graphs, and diagrams ending up separated from their textual references. Given LaTeX's automated placement algorithms, these visual elements can easily end up placed pages away from where they are referenced in the text. This separation decreases readability and causes annoyance for readers who have to flip pages back and forth.
LaTeX by default tries to place floats like figures and tables at the top or bottom of pages based on space availability and page composition considerations. However, this auto-placement behavior can often lead to visuals and their textual references becoming distantly separated if there are not convenient float placement locations near the references. The key to avoiding this problem lies in understanding and utilizing LaTeX's float placement tools to exert more manual control.
Strategies for Placement
Several built-in LaTeX packages provide tools for controlling float placement. The float package contains options for manually specifying locations for figures and tables in relation to their textual references. For example, the [H] specifier can be used to indicate that a particular visual element should be placed precisely "here" rather than letting LaTeX automatically calculate placement. There is also the placeins package which provides additional location specifiers like [htbp] for forcing figures directly at the insertion point on the page rather than floating to the top or bottom.
By actively controlling float placement relative to references, separation issues can be minimized or eliminated entirely. Some strategies include setting global preferences in the document preamble for figures and tables to be placed in sections rather than floats to keep them embedded directly amongst the text. \ keepfloats can be used to attempt placing all following figures and tables only at the end of sections containing their references. Manual placement overrides like {[H]} and \FloatBarrier can also resolve any remaining figure or table separation from specific references by forcing them to appear at the precise textual location.
Manual Placement Controls
Manually overriding LaTeX's automated float placement is key to keeping figures, tables, diagrams, charts, and other visual elements close to their textual references. The H placement specifier indicates "here" - it should be placed exactly where it was referenced in the source text. For example, {Figure \ref{fig1}[H]} tells LaTeX to position that figure right at that location on the page rather than floating it elsewhere. There is also the \begin{figure*}[H] syntax for wider multi-column figures.
Visual elements can also be manually placed by inserting them directly in the text inside \begin{center} tags without using figure floats at all. While this looks slightly awkward in the raw source code, it provides precise placement control. Equations can be positioned directly in the text in this same inline manner as well. These manual techniques may require some adjustments to paragraph spacing and page break limits to prevent separated orphan figure fragments.
Additional strict pagebreak controls like \FloatBarrier, \clearpage, and \afterpage can help prevent headings, text paragraphs, or figures from becoming isolated on separation-prone page boundaries. Insert enough forced page breaks around visual elements and their in-text references and LaTeX will have no choice but to keep them co-located on the same page - but use judiciously.
Formatting Options
The float formatting and style can be configured to make them easier to visually identify for readers and cite for authors. Applying distinctive rules, borders, backgrounds, alignment, spacing above/below, and captions facilitates both text references to specific figure or table numbers as well as reader comprehension of their connection to the discussion.
For tables, packages like booktabs provide commands for adding rules, borders, row spacing adjustment, and column alignment to enable optimally legible formatting that identifies them for citation purposes. Tables can also be manually sized with parameters like \begin{tabularx}(column specs) to force them to fit on a single page alongside text rather than extending to potentially distant pages.
Figure captions can be formatted directly below the image with "bottom" placement and made highly visible by adjusting the font size and weight along with background coloration. The \label and \ref system connects captions to explicit in-text references such as "See Figures 3 and 5 for the results...". This clarifies the interrelation of figures and writing when they become separated.
When Automation Fails
Despite best efforts with strategic float placement and formatting, you may end up with some stubborn figures, tables or even multipage plate sections that absolutely refuse to locate anywhere remotely close to their reference locations in the text. When even \begin{figure*}[H], \FloatBarrier, \clearpage etc have failed to get these wayward float elements to group coherently with the referencing content, more extreme measures are called for.
A brute force method is to insert \clearpage commands preemptively at logical break points in each section to completely flush all floats. Then re-insert all the figures/tables manually with [H] exactly where referenced. This forces LaTeX to compose the page content in situ rather than attempting automated composition. For multipage plates, the afterpage package can force plates to locate just after their textual description on the next page. As a last resort, sections can define page break min/max limits through \setcounter{sectionPages}{min-max} though watch for unintended effects.
Having figures run over multiple pages is another scenario where proximity to text references rapidly diminishes. For multipage visuals, consider converting portions to table data or splitting into discrete single-page figures for placement control. Multi-image spanning figures can occupy their own dedicated Plate section extracted out of the body text flow and forced to the end as an appendix if positioning proves highly problematic.
Occasionally you may just have to settle for a bit of unavoidable separation between figures and heavily positi