[Tex/LaTex] Why is the table displayed at the top of the page

floats

I figure this must be a common issue but I could not find a solution.

Here is my code:

\documentclass{article}
\begin{document}

    Text: This text should be above the table, but it is not.
    \begin{table}
        Table: This table should be below the text, but it is not.  
    \end{table} 

\end{document}

Why is the table at the top? Thanks!

Best Answer

table is a floating environment. TeX has special rules for placing floats so that they cause minimal disruption of the surrounding text.

You can give LaTeX hints of how to place your floats. For example, to make LaTeX try to place it where you inserted it, specify the option h (for “here”):

\begin{table}[h]
    Table: This table should be below the text, but it is not.  
\end{table} 

Note that this won’t always work because LaTeX still tries to make the text look nice. Your hint is only that: a hint, not a definite command.

You can force LateX to obey your command to place a floating environment HERE by loading the package float and specifying the option H (capital letter!):

\begin{table}[H]
    Table: This table should be below the text, but it is not.  
\end{table} 

But notice that this can lead to an ugly layout.