7

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}
1
  • all the answers have good points, but the most important one isn't really highlighted. that is, the table environment floats, so adding any kind of center instruction outside its scope won't affect the position of the table at all. start by moving \centering inside the table environment, and get rid of the now-useless braces. Commented Oct 13, 2016 at 12:57

4 Answers 4

8

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.

5

Some additional suggestions (beyond removing the scope-limiting curly braces), in no particular order:

  • Use a p column type (of width 3.5cm); get rid of the \multicolumn statements

  • Set up a new column type (called t in the code below) for the fixed-width font material in columns 2 and 3; get rid of the individual \tt directives

  • It's not necessary to invoke \small; just typeset the table at the normal document font size

  • Since you're using the macros of the booktabs package, do embrace the package's overall approach to designing tables as well. E.g., use horizontal rules sparingly, and use whitespace instead. The result will be a more "open" looking table.

  • Don't use the deprecated font switching macros \tt and \bf; instead, use \ttfamily and \bfseries.

  • The elements h and b in the placement directive [!hbt] have absolutely no effect on a table* environment. The omissing of the p element is potentially problematic as it prevents the creation of a full-page float and thereby increases the chances that the float will end up at the very end of the document. My advice would be to omit the [!hbt] directive entirely.

enter image description here

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{booktabs, array}
\newcolumntype{t}{>{\ttfamily}l}  % automatic-ttfamily "l" column

\begin{document}
\lipsum[1-3]

\begin{table*}
\caption[hello core APIs]{hello core APIs\strut}\label{tab:apis}
\centering
\renewcommand\arraystretch{1.2}
\begin{tabular}{@{} p{3.5cm} t t l @{}}
\toprule
\bfseries API group & \bfseries\rmfamily Name & \bfseries\rmfamily Parameters & \bfseries output \\
\midrule
Creation
& createFBFSummary  & summary, tableWidth & FBF summary \\
& createLabeledSummary & summary & Labeled summary \\
\addlinespace
Query               & query & summary, label & value \\
& search & directory, label & (summary, value) pairs \\   
\bottomrule
\end{tabular}
\end{table*}

\lipsum[4-13]
\end{document}
2
  • nice answer although [!hbt] does have an effect it is same as [t] so prevents float pages and increases the chance of the float going to the end of the document. The advice not to use it is good though:-) Commented Oct 13, 2016 at 7:02
  • @DavidCarlisle - Thanks for this point; I'll edit my answer accordingly.
    – Mico
    Commented Oct 13, 2016 at 7:19
2

The answers given up to now fix the problem, but go wrong in suggesting “improvements”.

About the main problem, just for completeness:

  1. \centering outside the table environment doesn't affect the environment at all

  2. {\centering...} has no effect, because the paragraph ends after } is scanned, so \centering has already ended its action.

So the format should be

\lipsum

\begin{table*}[t]
\centering\small

\caption{hello core APIs}\label{tab:apis}

\begin{tabular}{llll}
[...]
\end{tabular}

\end{table*}

\lipsum

I prefer to have the formatting instructions at the top; they don't affect the caption anyway.

Now, let's consider the tabular and how it can be improved.

\documentclass[10pt, twocolumn]{article}

\usepackage{lipsum}
\usepackage{booktabs}

\newcommand{\keyw}[1]{\texttt{#1}}

\begin{document}

\lipsum

\begin{table*}
\small\centering

\caption{hello core APIs}\label{tab:apis}

\medskip % not necessary if you load caption

\begin{tabular}{llll}
\toprule
% header
\bfseries API group & \bfseries Name & \bfseries Parameters & \bfseries output \\
% table data
\midrule
Creation
  & \keyw{createFBFSummary}
  & \keyw{summary}, \keyw{tableWidth}%, \keyw{schema} (optional)  
  & FBF summary \\
\cmidrule(lr){2-4}
  & \keyw{createLabeledSummary}
  & \keyw{summary}
  & Labeled summary \\
\midrule
Query
  & \keyw{query}
  & \keyw{summary}, \keyw{label}
  & value \\
\cmidrule(lr){2-4}
  & \keyw{search}
  & \keyw{directory}, \keyw{label}
  & (summary, value) pairs \\   
\bottomrule
\end{tabular}

\end{table*}

\lipsum

\end{document}

Note the personal command for typesetting special words in typewriter type; also \bf and \tt should never be used. Nor double horizontal rules. There's also no need for \multirow: the word "Creation" automatically refers to the blank cell below it.

enter image description here

1

Use the center environment instead of centering ; but I don't know why

\documentclass[10pt, twocolumn]{article}

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

\begin{document}

\lipsum

\begin{table*}[!hbt]
  \caption{hello core APIs}\label{tab:apis}
  \small
  \begin{center}
    \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{center}
\end{table*}
\lipsum

\end{document}

enter image description here

1
  • 2
    the usual advice is not to use center in tables as it adds vertical space and more vertical space is added around the float so you get extra large space. Commented Oct 13, 2016 at 7:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .