Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following code:

\section{Database Design}

\begin{center}
\begin{table}
    \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}
\end{center}

There are a few alignment problems:

  1. The table seems to be floating top left above my section
  2. My caption is centered and out of line with the table

How can I center my table and have it placed below my 'Database Design' section?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

You should use \centering inside table environment to center the table. Also the placement options [htbp] can be used to influence the placement of the table. An exclamation ! like [!h] will force latex to place here.

\documentclass{article}
\begin{document}
\section{Database Design} 
%    
\begin{table}[!h] %%,---- note the placement option
\centering    %%,------command here for 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}
\end{document} 

Also avoid using \begin{center}.....\end{center} as it will add extra vertical space (that may be unwanted in some cases like this). Instead use \centering.

For a more stricter placement pl. consult float package that provides an option H means definitely here (as opposed to h meaning here if possible). For more details consult the documentation of float (texdoc float) page no. 4.

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.