[Tex/LaTex] Centering a table that spans in two column document

horizontal alignmenttables

I have a table that spans in two-column document.
The issue is that the table is not center aligned with my \centering command. Futhermore, the table is not fit into the document with 10pt fonts.

How to solve these issues?

enter image description here

\documentclass[10pt, twocolumn]{article}

\usepackage{lipsum}
\usepackage{tabularx, multirow, booktabs}

\begin{document}

\lipsum

{\centering
\begin{table*}[!hbt]
\caption{hello core APIs}\label{tab:apis}
{\small\centering
\begin{tabular}{llll}

\toprule

     {\bf API group} & {\bf Name} & {\bf Parameters} & {\bf output} \\
     \midrule\midrule[.1em]

     \multirow{2}{3.5cm}{Creation} 
         & {\tt createFBFSummary}
         & {\tt summary}, {\tt tableWidth}%, {\tt schema} (optional)  
         & FBF summary \\
     \cmidrule(lr){2-4}
         & {\tt createLabeledSummary}
         & {\tt summary}
         & Labeled summary \\

\midrule[.1em] 

\multirow{2}{3.5cm}{Query} 
    & {\tt query}
    & {\tt summary}, {\tt label}
    & value \\
\cmidrule(lr){2-4}
    & {\tt search}
    & {\tt directory}, {\tt label}
    & (summary, value) pairs \\   
\bottomrule
\end{tabular}
}
\end{table*}
}

\lipsum

\end{document}

Best Answer

The switch \centering is only enforced when it finds the end of a paragraph (an explicit \par or a blank line). Since you're wrapping \centering inside a group and there is no such "end of paragraph" signal before the group closes, the effect of \centering is never enforced.

The solution is to remove the scoping braces {...} since they're not needed here (despite using \small as well). Alternatively, use \begin{center} ... \end{center}, which will insert additional spacing above/below the tabular.

enter image description here

\documentclass[twocolumn]{article}

\usepackage{lipsum}
\usepackage{multirow, booktabs}

\begin{document}

\lipsum

\begin{table*}[t]
  \caption{hello core APIs}
  \small\centering
  \begin{tabular}{llll}

    \toprule

    {\bfseries API group} & {\bfseries Name} & {\bfseries Parameters} & {\bfseries output} \\
    \midrule\midrule[.1em]

    \multirow{2}{3.5cm}{Creation} 
      & {\ttfamily createFBFSummary}
      & {\ttfamily summary}, {\ttfamily tableWidth}%, {\ttfamily schema} (optional)  
      & FBF summary \\
    \cmidrule(lr){2-4}
      & {\ttfamily createLabeledSummary}
      & {\ttfamily summary}
      & Labeled summary \\

    \midrule[.1em] 

    \multirow{2}{3.5cm}{Query} 
      & {\ttfamily query}
      & {\ttfamily summary}, {\ttfamily label}
      & value \\
    \cmidrule(lr){2-4}
      & {\ttfamily search}
      & {\ttfamily directory}, {\ttfamily label}
      & (summary, value) pairs \\   
    \bottomrule
  \end{tabular}
\end{table*}

\lipsum

\end{document}

In the above example, the end of the table* environment constitutes an "end of paragraph" signal.