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

  • 1
    Aren't you explicitly telling it to be left aligned by lccl? – samcarter Oct 11 at 11:15
  • @samcarter Idk, I just went to tablesgenerator.com/# and typed in the table. What should it be changed to? – Ilyankor Oct 11 at 11:16
  • try lccc if you want it to be centred. – samcarter Oct 11 at 11:17
  • 1
    (tablesgenerator explains why the code is so strange...) – samcarter Oct 11 at 11:17
  • 1
    I would also suggest to not use a center environment, but simply \centering to prevent the additional vertical spacing. – samcarter Oct 11 at 11:19
up vote 3 down vote accepted

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

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.