1
\section{Main section}

\subsection{Some subsection}

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{lllll}
x & y & z & a &  \\
0 & 0 & 0 & 0 &  \\
0 & 0 & 0 & 0 &  \\
0 & 0 & 0 & 0 & 
\end{tabular}
\end{table}

Test text test text.

For some reason this table is shows up before "Main section" even though I typed it after the section header. What is the reason for this?

Sean Hill
  • 121
  • Because you put it into a floating environment? ;-) My usual answer for this: Drop the table environment and use \captionof{table}{...} instead of \caption{...}, this requires the caption package (which is a good idea anyway) –  Dec 27 '15 at 21:32
  • try \begin{table}[!htb] –  Dec 27 '15 at 21:32
  • @ChristianHupfer What is a "floating environment"? – Sean Hill Dec 27 '15 at 21:34
  • Actually, even \begin{table}[h] is enough in this case. – Alenanno Dec 27 '15 at 21:34
  • @SeanHill: Look at your title: You have experienced what a floating environment is ;-) –  Dec 27 '15 at 21:35
  • Wow, [!htb] and [h] worked! What does that do and why did it resolve this issue? – Sean Hill Dec 27 '15 at 21:35
  • @ChristianHupfer What constitutes a floating environment then? If I use \begin{equation} that seems to "stick" fine, but when I do \begin{table} suddenly it "floats" up to the top of a page? – Sean Hill Dec 27 '15 at 21:36
  • 1
    @SeanHill: Unless defined otherwise, figure and table are the basic floating environments. Other packages define new ones or with the package float there will be new floats available, if really needed. I suggest to read an introductory book on LaTeX. –  Dec 27 '15 at 21:37
  • @SeanHill h means "here". If you add tb, it can be placed at the top of the current page (or next page) or at the bottom of the current page (or next page). – Alenanno Dec 27 '15 at 21:38
  • @Alenanno The option [h] is automatically changed into [ht] – egreg Dec 27 '15 at 21:43
  • @egreg Yeah, but not with all documentclasses, right? I mean, most of them. – Alenanno Dec 27 '15 at 21:47
  • @Alenanno It's done by the LaTeX kernel. – egreg Dec 27 '15 at 21:50
  • @Alenanno: the float mechanism is in latex.ltx already, so it's no special invention of a class. I think it's the same for all standard classes, but maybe I am wrong. Do you have an example? –  Dec 27 '15 at 21:50
  • @ChristianHupfer Mh I had read so in an answer here time ago. I don't have a particular example. :P – Alenanno Dec 27 '15 at 21:54
  • @Alenanno: Well, it might be possible anyway... –  Dec 27 '15 at 21:55

0 Answers0