Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LaTeX table positioning

Tags:

latex

People also ask

How do I align a table to the left in LaTeX?

To align the whole object (table) to left, use \begin{flushleft} ... \end{flushleft} . To align the text in cells in a column to left, center or right, use 'l', 'c' or 'r' in the description of your tabular , like bellow.

Why is my table in the middle of the page LaTeX?

Something like \begin{table}[p] (page) could be causing the table to be set on its own page. If you just used [h] (here) then try adding t (top) to it, as if the table runs over a page with just [h] it can default to page.

How do I center align a table in LaTeX?

If you use the table-environment, you just have to set the command \centering to get the table centered.


After doing some more googling I came across the float package which lets you prevent LaTeX from repositioning the tables.

In the preamble:

\usepackage{float}

Then for each table you can use the H placement option (e.g. \begin{table}[H]) to make sure it doesn't get repositioned.


At the beginning with the usepackage definitions include:

\usepackage{placeins}

And before and after add:

\FloatBarrier
\begin{table}[h]
    \begin{tabular}{llll}
      .... 
    \end{tabular}
\end{table}
\FloatBarrier

This places the table exactly where you want in the text.


Table Positioning

Available Parameters

A table can easily be placed with the following parameters:

  • h Place the float here, i.e., approximately at the same point it occurs in the source text (however, not exactly at the spot)
  • t Position at the top of the page.
  • b Position at the bottom of the page.
  • p Put on a special page for floats only.
  • ! Override internal parameters LaTeX uses for determining "good" float positions.
  • H Places the float at precisely the location in the LATEX code. Requires the float package. This is somewhat equivalent to h!.

If you want to make use of H (or h!) for an exact positioning, make sure you got the float package correctly set up in the preamble:

\usepackage{float}
\restylefloat{table}

Example

If you want to place the table at the same page, either at the exact place or at least at the top of the page (what fits best for the latex engine), use the parameters h and t like this:

\begin{table}[ht]
    table content ...
\end{table}

Sources: Overleaf.com


Here's an easy solution, from Wikibooks:

The placeins package provides the command \FloatBarrier, which can be used to prevent floats from being moved over it.

I just put \FloatBarrier before and after every table.


What happens if the text plus tables plus text doesn't fit onto a single page? By trying to force the typesetting in this way, you are very likely to end up with pages that run too short; i.e., because a table cannot by default break over a page it will be pushed to the next, and leave a gap on the page before. You'll notice that you never see this in a published book.

The floating behaviour is a Good Thing! I recommend using [htbp] as the default setting for all tables and figures until your document is complete; only then should think about fine-tuning their precise placement.

P.S. Read the FAQ; most other answers here are partial combinations of advice given there.


If you want to have two tables next to each other you can use: (with float package loaded)

\begin{table}[H]
 \begin{minipage}{.5\textwidth}
  %first table
 \end{minipage}
 \begin{minipage}{.5\textwidth}
  %second table
 \end{minipage}
\end{table}

Each one will have own caption and number. Another option is subfigure package.


You may want to add this to your preamble, and adjust the values as necessary:

 %------------begin Float Adjustment
%two column float page must be 90% full
\renewcommand\dblfloatpagefraction{.90}
%two column top float can cover up to 80% of page
\renewcommand\dbltopfraction{.80}
%float page must be 90% full
\renewcommand\floatpagefraction{.90}
%top float can cover up to 80% of page
\renewcommand\topfraction{.80}
%bottom float can cover up to 80% of page
\renewcommand\bottomfraction{.80}
%at least 10% of a normal page must contain text
\renewcommand\textfraction{.1}
%separation between floats and text
\setlength\dbltextfloatsep{9pt plus 5pt minus 3pt }
%separation between two column floats and text
\setlength\textfloatsep{4pt plus 2pt minus 1.5pt}

Particularly, the \floatpagefraction may be of interest.