4

In the following code an error

!h' float specifier changed to !ht`

I think because my tables span multiple pages. How can I get them to display properly one after the other?

\documentclass{article}
\begin{document}
\section{Database Design} 

\begin{table}[!h]
\centering
    \begin{tabular}{ | l |  l |}
    \hline
    Field & Type \\ \hline
    id & Primary key \\ \hline
    firstName & String \\ \hline
    lastName & String \\ \hline
    email & String \\ \hline
    password & String \\ \hline
    \end{tabular}
\caption{User2}
\end{table}

\begin{table}[!h]
\centering
    \begin{tabular}{ | l |  l |}
    \hline
    Field & Type \\ \hline
    id & Primary key \\ \hline
    firstName & String \\ \hline
    lastName & String \\ \hline
    email & String \\ \hline
    password & String \\ \hline
    \end{tabular}
\caption{User}
\end{table}

\begin{table}[!h]
\centering
    \begin{tabular}{ | l |  l |}
    \hline
    Field & Type \\ \hline
    id & Primary key \\ \hline
    title & String \\ \hline
    postedAt & Date\\ \hline
    email & String \\ \hline
    author & Foreign key from 'User' table\\ \hline
    tags & Foreign key from 'Tag' table\\ \hline
    \end{tabular}
\caption{Post}
\end{table}

\begin{table}[!h]
\centering
    \begin{tabular}{ | l |  l |}
    \hline
    Field & Type \\ \hline
    id & Primary key \\ \hline
    author& String \\ \hline
    content& String \\ \hline
    postedAt & Date\\ \hline 
    post& Foreign key from 'Post' table\\ \hline
    \end{tabular}
\caption{Comment}
\end{table}

\begin{table}[!h]
\centering
    \begin{tabular}{ | l |  l |}
    \hline
    Field & Type \\ \hline
    id & Primary key \\ \hline
    name & String
    \end{tabular}
\caption{Tag}
\end{table}

\begin{table}[!h]
\centering
    \begin{tabular}{ | l |  l |}
    \hline
    id & Primary key \\ \hline
    Field & Type \\ \hline
    post& Foreign key from 'PostTag' table\\ \hline
    tag& Foreign key from 'Tag' table\\ \hline
    \end{tabular}
\caption{PostTag}
\end{table}


\end{document}

Torbjørn T.
  • 206,688

2 Answers2

5

If you need to output the tables at a particular place, without any other things sneaking in between them, do not use floats then.

Captions can be used even without floats, if one uses \captionof from the caption package. See also this question Label and caption without float

amorua
  • 1,928
4

When TeX cannot put the table [h]ere because it is on a page break, it will always switch to something else.

For this case, I guess that a good option is loading a package

\usepackage{float}

and then using the [H] position specifier (capital 'H') (cannot be used with other ones, cannot be used with !):

\begin{table}[H]
...
\end{table}

This specifier means:

  • here and only here;

  • move to the next page if the table does not fit here, and leave the current page short.

Generally, using [H] is frowned upon, but when a whole section comprises more-or-less only tables, it seems a reasonable solution.

yo'
  • 51,322