I have the following code which defines a table in a paper I'm writing:
\begin{table}[t]
\centering
\def\arraystretch{1.5}
\begin{tabular}{ *{5}{>{\centering\arraybackslash}m{0.2\textwidth}} }
\hline \hline
Atom Pair & \ch{D0} (eV) & $\alpha$ (1/\AA) & \ch{r0} (\AA) & Cut Off (\AA) \\
\hline
Fe-Fe & 0.764 & 1.5995 & 2.7361 & 12 \\
Fe-Ti & 0.8162 & 1.448 & 2.914 & 12 \\
Fe-Nd & 0.6036 & 1.6458 & 3.188 & 12 \\
Nd-Nd & 0.312 & 0.945 & 4.092 & 12 \\
Nd-Ti & 0.4964 & 1.440118 & 3.4309 & 12 \\
Ti-Ti & 0.6540 & 1.2118 & 3.3476 & 12 \\
Sm-Sm & 0.2365 & 1.16433 & 3.8485 & 12 \\
Sm-Ti & 0.5219 & 1.98644 & 3.3129 & 12 \\
Sm-Fe & 0.5891 & 1.48848 & 3.1394 & 12 \\
Sm-Co & 0.5686 & 1.47399 & 3.1725 & 12 \\
Ti-Co & 0.7527 & 1.40291 & 2.9331 & 12 \\
Co-Co & 0.6774 & 1.64306 & 2.7093 & 12 \\
\hline \hline
\end{tabular}
\caption{Table of all the values used for the Morse potentials used for the following study.}
\label{tab:morse_potential_values_rt12}
\end{table}
To avoid any ambiguity, the \ch
command is part of the chemical formula package, the documentation for which is here: https://latex-cookbook.net/chemistry/ . It seems to me that by defining each column with >{\centering\arraybackslash}m{0.2\textwidth}
I should have a table that fits the width of the text section of the page. However, when I create this table I get the following:
As you can see from the red lines which roughly match where the margin is, the right hand side has flowed over, although the caption below hasn't. Why is this?
Best Answer
By setting the usable width of each column to
0.2\textwidth
, the total width of each column becomes0.2\textwidth+2\tabcolsep
, as LaTeX by default inserts\tabcolsep
of whitespace padding on each side. Since thetabular
environment contains 5 columns, its total width is\textwidth+10\tabcolsep
. In many document classes, the default value of\tabcolsep
is6pt
;10\tabcolsep
thus amounts to60pt
, i.e., roughly .83in or 2.1cm. Having the table protrude into the right-hand margin by that amount is definitely noticeable!One could go about fixing this situation by reducing the width of each
m
-type column to0.2\textwidth-2\tabcolsep
. However, I would like to recommend that you switch to atabular*
environment (with target width\textwidth
), employl
,c
, andS
-type columns, and let LaTeX adjust the amount of intercolumn whitespace automatically so as to "fill up" the width of the text block. TheS
column type, which is provided by thesiunitx
package, is very handy for aligning numbers on their explicit or implicit decimal markers.