70

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.

migrated from stackoverflow.com Feb 26 '14 at 8:52

This question came from our site for professional and enthusiast programmers.

  • 2
    You need \begin{center} ... \end{center} rather than \{center} .. \{\center}. – Aditya Jun 11 '15 at 15:25
83

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}
} 

(note the extra {}).

  • 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} – user1519221 Feb 25 '14 at 21:07
  • 7
    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 9:07
  • @PeterGrill Good point. Added to the answer. Thanks. – herohuyongtao Feb 26 '14 at 9:29
  • 6
    The second option does not appear to work. I would like to include a tabular environment without using floats, but centering it. – tchakravarty May 1 '15 at 19:55
  • 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 5 at 10:28
30

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?

  • The OP does not mention beamer at all? Why do you think that \begin{center}...\end{center} is better? – user31729 Jun 11 '15 at 14:39
  • 6
    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
  • herohuyongtao's answer did not work for me, but this one does (even though I am not using beamer). Thanks. – Stephen Jun 20 '17 at 20:43