0

I'm working on a table right now and I would really like to center it to make it look neater. Only problem is after I import the array package, and then use the m{width} function. It doesn't seem to do anything. Any idea why? Here's the code and picture of the table.
Also, there's these error markers and are all saying the same thing as the one highlighted in the code below. What do these mean, I've been trying to figure that out but cant seem to find a solution.

\begin{table}[htpb]
\centering
\begin{tabular}{m{2.5cm}|m{2.5cm}p{2.5cm}p{2.5cm}p{2.5cm}}
\multicolumn{2}{l}{\textbf{Reduced data}} \\ \cline{1-2}
{} & Average Mass [kg]$\pm$0.0001 & Average Radius [m]$\pm$0.00001 & Experimental Height [m]$\pm$0.00305 & Theoretical Height [m]\\
\hline
Ball Type    &                          &                             &                                 & \\ \hline
Table Tennis &                  0.00248 &                     0.01871 &                         0.24831 &   0.34973 $\pm$0.00519 \\
Racquet      &                  0.04172 &                     0.02803 &                         0.51206 &   0.70837 $\pm$0.00787 \\
Squash       &                  0.02382 &                     0.01978 &                         0.09103 &   0.12059 $\pm$0.01629 \\
\end{tabular}
\end{table}

enter image description here

-Thanks

  • Does switching all the p columns to m columns do what you want? – Torbjørn T. Oct 04 '15 at 21:10
  • m does not centre the content in the space of the cell, it aligns the vertical centre of the content with the baseline of the row, so it doesn't do anything useful for a one line entry. and aligns the centre of the 2-line heading of column 2 with the first line of the p columns, which again is not wanted here. – David Carlisle Oct 04 '15 at 21:25

3 Answers3

1

enter image description here

\documentclass{article}
\usepackage{graphicx,amsmath,booktabs}
\begin{document}

\begin{table}[htpb]
\centering\small
\begin{tabular}{l*{4}c}
\toprule
&\multicolumn{4}{c}{\textbf{Reduced data}} \\ \cmidrule{2-5}
& Average    & Average   & Experimental & Theoretical \\
& Mass [kg]  & Radius [m]& Height [m]           & Height [m]  \\
\textbf{Ball Type} & $\pm$0.0001 & $\pm$0.00001 & $\pm$0.00305 &  \\ \midrule
Table Tennis &  0.00248  &  0.01871 &   0.24831 &   0.34973 $\pm$0.00519 \\
Racquet      &  0.04172  &  0.02803 &   0.51206 &   0.70837 $\pm$0.00787 \\
Squash       &  0.02382  &  0.01978 &   0.09103 &   0.12059 $\pm$0.01629 \\ \bottomrule
\end{tabular}
\end{table}

\end{document}
AboAmmar
  • 46,352
  • 4
  • 58
  • 127
  • @DavidCarlisle -- Thank you, that was \begin{tabularx}{\linewidth}{l*{4}C} with custom newcolumntype{C} defined as centered Xat first, and at a last-moment edit, I just removed the capital C leaving out other parts. – AboAmmar Oct 04 '15 at 22:24
1

Sligthly modified AboAmmar answer ... by help of makecell package for setting column heads in two lines you can obtain:

enter image description here

\documentclass[a4paper,12pt]{article}

    \usepackage{booktabs,makecell}

    \begin{document}
\begin{table}[h]
    \centering
    \begin{tabular}{l*{4}{c}}
    \toprule
    &   \multicolumn{4}{c}{\textbf{Reduced data}}                       \\
    \cmidrule{2-5}
    &   \thead{Average Mass\\ {[kg]$\pm$0.0001}} 
        &   \thead{Average Radius\\ {[m]$\pm$0.00001}}
            &   \thead{Experimental Height\\ {[m]$\pm$0.00305}}
                &   \thead{Theoretical Height\\ {[m]}}\\
\hline
Ball Type    &          &           &           &                        \\ 
    \midrule
Table Tennis &  0.00248 &   0.01871 &   0.24831 &   0.34973 $\pm$0.00519 \\
Racquet      &  0.04172 &   0.02803 &   0.51206 &   0.70837 $\pm$0.00787 \\
Squash       &  0.02382 &   0.01978 &   0.09103 &   0.12059 $\pm$0.01629 \\
    \bottomrule
    \end{tabular}
\end{table}
    \end{document}

If ypu like to have column heads in the same font size as whole table, than you need to add in preamble (after loading makecell package):

 \renewcommand\theadfont{\normalsize}

Edit: And version, if you like to have column headers in three lines and merged 2nd and 3th table row:

\documentclass[a4paper,12pt]{article}
    \usepackage{booktabs,makecell}
\renewcommand\theadfont{\normalsize}

    \begin{document}
\begin{table}[h]
    \centering
    \begin{tabular}{l*{4}{c}}
    \toprule
    &   \multicolumn{4}{c}{\textbf{Reduced data}}                       \\
    \cmidrule{2-5}
\thead{~\\~\\ \textbf{Ball Type}}
    &   \thead{Average\\ Mass\\ {[kg]$\pm$0.0001}} 
        &   \thead{Average\\ Radius\\ {[m]$\pm$0.00001}}
            &   \thead{Experimental\\ Height\\ {[m]$\pm$0.00305}}
                &   \thead{Theoretical\\ Height\\ {[m]}}\\
    \midrule
Table Tennis &  0.00248 &   0.01871 &   0.24831 &   0.34973 $\pm$0.00519 \\
Racquet      &  0.04172 &   0.02803 &   0.51206 &   0.70837 $\pm$0.00787 \\
Squash       &  0.02382 &   0.01978 &   0.09103 &   0.12059 $\pm$0.01629 \\
    \bottomrule
    \end{tabular}
\end{table}
    \end{document}

enter image description here

Zarko
  • 296,517
0

currently add a new columntyp to your code.

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} % zentriert mit Breitenangabe

Otherwise provide a MWE.