143

I have got a simple code to generate table in Latex.

\begin{tabular}{ | c | c | c | }
  \hline
  symbol & value & unit \\ \hline            
  $z Na$ & 11 & - \\ \hline      
  $z F$ & 9 & - \\ \hline      
  $Emax Na$ & 0.545 & $[MeV]$ \\ \hline
\end{tabular}

This code is good, but I would like to add this table to my document in Latex and have this table centered. The point is that table would be in the middle not on the left nor on the right but in the middle. I tried this, but it didn't work:

\{center}
\begin{tabular}{ | c | c | c | }
  \hline
  symbol & value & unit \\ \hline            
  $z Na$ & 11 & - \\ \hline      
  $z F$ & 9 & - \\ \hline      
  $Emax Na$ & 0.545 & $[MeV]$ \\ \hline
\end{tabular}
\{\center}

I appreciate the answer.

2 Answers2

179

You can just add \centering right after \begin{table} to center the table:

\begin{table}
\centering
\begin{tabular}
...
\end{tabular}
\end{table}

As commented by @PeterGrill, if you are not using floats (i.e., \begin{table}, \end{table}), then you will need to group it:

{
\centering
\begin{tabular} 
... 
\end{tabular}\par
} 

Note that \par and the extra {}.

rhody
  • 1,020
  • Unfortunately it doesn't work:

    \begin{tabular}{ | c | c | c | } \centering \hline symbol & value & unit \ \hline
    $z Na$ & 11 & - \ \hline
    $z F$ & 9 & - \ \hline
    $Emax Na$ & 0.545 & $[MeV]$ \ \hline \end{tabular}

    –  Feb 25 '14 at 21:07
  • 8
    The \centering should be outside of \begin{tabular} ... \end{tabular}. If you are not using floats (i.e., \begin{table}, \end{table}), then you will need to group it: {\centering\begin{tabular} ... \end{tabular}} (note the extra {}). – Peter Grill Feb 26 '14 at 09:07
  • @PeterGrill Good point. Added to the answer. Thanks. – herohuyongtao Feb 26 '14 at 09:29
  • 8
    The second option does not appear to work. I would like to include a tabular environment without using floats, but centering it. – tchakravarty May 01 '15 at 19:55
  • 4
    If the second option doesn't work for you, try \begin{center} \end{center} instead of { } as mentioned in @Walton's answer. – Mahmoud Elfar May 05 '19 at 10:28
  • this does not work for me with \begin{table}[!ht] \centering \begin{tabularx}{6in} the table still starts at the same x position on the page and then travels off the page – user1709076 Oct 19 '19 at 12:14
  • Personally, this doesn't work for me. The centering just doesn't happen. Walton's answer worked for me. –  Jan 05 '20 at 02:18
  • This does not work if the table is wider than the space (e.g. the column of the page). In that case, it is not centered, but left aligned. I think this was possible to center via resizebox or adjustbox or so. I use \begin{adjustbox}{width=1.\width,center} .... See also. – Albert May 08 '20 at 14:31
  • {\centering ...} doesn't work for me either, it doesn't center the table - and my table is not very wide. – Ela782 Apr 14 '21 at 10:27
  • 5
    You must use \par before closing the group with }. source So, it'll be {\centering \begin{tabular}...\end{tabular} \par } – burny Nov 19 '21 at 21:43
49

You can also use \begin{center} ... \end{center}. This works better with beamer for example because {\centering ... } messes with the size of the table for some reason. The new code would be:

\begin{center}
\begin{tabular}{ | c | c | c | }
  \hline
  symbol & value & unit \\ \hline
  $z Na$ & 11 & - \\ \hline
  $z F$ & 9 & - \\ \hline
  $Emax Na$ & 0.545 & $[MeV]$ \\ \hline
\end{tabular}
\end{center}

More on the difference between \begin{center} and \centering:
When should we use \begin{center} instead of \centering?

Dennis
  • 819
  • 9
  • 17
Walton
  • 599
  • 4
  • 5
  • The OP does not mention beamer at all? Why do you think that \begin{center}...\end{center} is better? –  Jun 11 '15 at 14:39
  • 14
    I brought up beamer as an example of a difference I noticed. I don't necessarily think it's better for this situation, but no one has mentioned it as an option yet. – Walton Jun 11 '15 at 14:55
  • 5
    {\centering ... } doesn't center the table for me - and \begin{center}...\end{center} adds a huge margin around the top/bottom of the table. – Ela782 Apr 14 '21 at 10:27