126

Table does not show up at the same position it was inserted in the TeX file. I got the understanding through bit of reading on this forum that they are floats and they pick the best place on the current or next page.

Because of this the text written below the table in TeX file ends up showing on the previous page. Is there any way to make the table appear in the same place as it was put in the TeX file.

In my case I created a table and below that I wrote "as shown in the above table..." but when I created the PDF it appeared on the previous page and there was no table there. One workaround is referring to the table # but I was wondering if there is any better way. I am using \begin{table}[!ht]

3
  • 1
  • 4
    From my experience, floats seldom pick the right location
    – puk
    Aug 10, 2015 at 7:04
  • In my case, I was using \begin{table*}[ht] and removing the ht completely solved the problem, so \begin{table*}[] and my tables were properly placed in text instead of at the very end of the document
    – Tanel
    Mar 26, 2022 at 21:16

2 Answers 2

152

Suppressing floating is often not the best option. But it may be done, for example using the float package:

\usepackage{float}
...
\begin{figure}[H]
...

Often choosing further placement options would be sufficient, such as

\begin{figure}[!htbp]

Or set a barrier which may not be crossed by floats:

\usepackage{placeins}
...
\FloatBarrier
\begin{figure}[H]
...
2
  • I had to combine these solutions, as well as write \FloatBarrier\clearpage. Also \usepackage{dblfloatfix} for some two-column floats that were moving around. This is for an older version of LaTeX, modern version seems to be fine without all the fuss. Apr 29, 2016 at 11:41
  • 9
    +1 for the option [!htbp], it worked great. The table was always placed at the end of the document, but this option set it in the midst of the text. Jun 11, 2018 at 4:28
20

To avoid discrepancies between phrases like "as shown in the above table" and the actual table position, one may either supress floating of tables or employ the varioref package for "intelligent" cross-referencing. Here's an example using varioref.

\documentclass{article}

\usepackage{varioref}

\begin{document}

\begin{table}
\centering
(Content of first table)
\caption{A table}
\label{tab:first}
\end{table}

\clearpage

For the first topic see the \vpageref[above table][table ]{tab:first}.

OR: For the first topic see table~\vref{tab:first}.

\begin{table}
\centering
(Content of second table)
\caption{Another table}
\label{tab:second}
\end{table}

For the second topic see the \vpageref[above table][table ]{tab:second}.

OR: For the first topic see table~\vref{tab:second}.

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .