[Tex/LaTex] Booktabs help alignment

booktabshorizontal alignment

For some strange reason, the right column is left aligned in contrast with the other columns. I'm not seeing what I did wrong. This is due in 3 hours, but I haven't noticed it until now. Please help if you can. Very much appreciated!

\documentclass[letterpaper]{article}
\special{papersize=8.5in,11in}
\usepackage{mathtools}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{array}
\usepackage[margin=1in]{geometry}
\setlength{\parskip}{1em}

\begin{document}
\begin{table}[h!]

\renewcommand\arraystretch{2}
\begin{center}
\caption{Processed data (rate of reaction)}
\vspace{.5 em}
    \begin{tabular}{@{}lccl@{}}
        \toprule

                             & \renewcommand\arraystretch{1.5} \begin{tabular}[c]{@{}c@{}} moles of $\ce{Mg_{(s)}}  \hspace{1mm} \left(  \si{mol} \right)$ \\ $\left( \pm \hspace{1mm} 20 \% \right)$ \end{tabular}   &  \renewcommand\arraystretch{1.5} \begin{tabular}[c]{@{}c@{}}time $\left( \si{s} \right)$ \\ $\left( \pm 0.01 \hspace{1mm} \si{s} \right)$ \end{tabular} & \renewcommand\arraystretch{1.5} \begin{tabular}[c]{@{}c@{}} reaction rate $ \left( \si{mol.s^{-1}} \right)$ \\ $\left( \pm \hspace{1mm} 20 \% \right)$ \end{tabular} \\ 

        \midrule \renewcommand\arraystretch{2}

one piece of $\ce{Mg}$ ribbon & $2 \times 10^{-3}$                                                                                                           & 17.04                                                                                                                &   $1 \times 10^{-4}$                  \\

small cut up pieces of $\ce{Mg}$ & $2 \times 10^{-3}$                                                                                                                 & 16.03                                                                                                                &  $1 \times 10^{-4}$                  \\

        \bottomrule

    \end{tabular}
\end{center}
\end{table}
\end{document}

I've put my preamble and the entire table.

Edit: code

Here's a picture.

booktabs help

Best Answer

The last column is left aligned, because by using the l alignment specifier, you tell it t be so. if you want it to be centred, use c

I would suggest a couple of changes to simplify your code:

  • you are loading the siunitx package, but don't use it. For example instead of $1 \times 10^{-4}$ simply write \num{1e-4}. Or \SI{0.01}{s} to automatically get the correct spacing between number an unit without hard coding lengths that will scale badly with the font.

  • using nested tables for the multiline heads seems very complicate. The makecell package has nice solutions for that

  • use \centering instead of the center environment to prevent additional spaces

  • instead of manually messing with the spacing between caption and table, the caption package will automatically give a nice looking space

  • replace all you \left( and \right) with (), they are not necessary in the context you are using them (which is true most of the time)

  • using [h!] is basically a guarantee for suboptimal placement of your table. Let latex do what it can best and use [htbp]


\documentclass[letterpaper]{article}
\special{papersize=8.5in,11in}
\usepackage{mathtools}
\usepackage[version=4]{mhchem}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{array}
\usepackage[margin=1in]{geometry}
\usepackage{makecell}
\renewcommand\theadset{\def\arraystretch{1.5}\normalsize}%
\usepackage{caption}

\setlength{\parskip}{1em}

\begin{document}

\begin{table}[h!]
    \renewcommand\arraystretch{2}
    \caption{Processed data (rate of reaction)}
    \centering
    \begin{tabular}{@{}lccc@{}}
        \toprule
        &
        \thead{moles of $\ce{Mg_{(s)}}$ (\si{mol})\\$(\pm \SI{20}{\percent})$} &
        \thead{time (\si{s})\\$(\pm \SI{0.01}{s})$} &
        \thead{reaction rate (\si{mol.s^{-1}})\\$(\pm \SI{20}{\percent})$}\\
        \midrule
        one piece of $\ce{Mg}$ ribbon & \num{2e-3} & \num{17.04} & \num{1e-4}\\
        small cut up pieces of $\ce{Mg}$ & \num{2e-3} & 16.03 & \num{1e-4}\\
        \bottomrule
    \end{tabular}
\end{table}

\end{document}

enter image description here

Related Question