[Tex/LaTex] horizontally center table

horizontal alignmenttables

Strangely in this MWE the table is shifted to the left but in my original document I have exactly the same code but the table is centered. Can anyone solve the mystery?

\documentclass{article}

\begin{document}

\begin{table}[H]
\caption{Robustness checks---Organised events}
\begin{tabular}{lc} \hline
VARIABLES & Org. event \\ \hline
 &  \\
Price shock & -0.212 \\
 & (0.177) \\
 &  \\
Observations & 2,226 \\
Number of city\_group & 37 \\
R-squared & -0.021 \\ \hline
\multicolumn{2}{c}{ Robust standard errors in parentheses} \\
\multicolumn{2}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
\end{tabular}
\end{table}

\end{document} 

Best Answer

Adding \centering after \begin{table} will center the table:

enter image description here

Notes:

  • The showframe package was used to add the margins so that the centering effect can be seen.
  • Using centering is preferred over the center environment as the environment adds additional vertical space.

Code:

\documentclass{article}
\usepackage{showframe}

\begin{document}
\begin{table}[H]
\centering
\caption{Robustness checks---Organised events}
\begin{tabular}{lc} \hline
VARIABLES & Org. event \\ \hline
 &  \\
Price shock & -0.212 \\
 & (0.177) \\
 &  \\
Observations & 2,226 \\
Number of city\_group & 37 \\
R-squared & -0.021 \\ \hline
\multicolumn{2}{c}{ Robust standard errors in parentheses} \\
\multicolumn{2}{c}{ *** p$<$0.01, ** p$<$0.05, * p$<$0.1} \\
\end{tabular}
\end{table}
\end{document}