I am very much new to LaTeX and am unfamiliar with a lot of terms and usage. Nonetheless, I am attempting to put this table into a document. I am having two problems:
- The table is not centred in the page (it spills into the right margin)
- Long words (e.g. phenanthroline in column 1) are not auto-hyphenating
I am using the array package as I have seen it suggested for setting the column widths to auto wrap text, which seems to have been successful so far. I am also using booktabs just for the top, mid and bottom ruled lines.
I have come across this answer which seems similar to my problem and produces a result that looks good, but I can't quite understand how it works / what is being done with makecell package.
Any clarification or suggestions would be greatly appreciated!
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage[version=4]{mhchem}
\usepackage{array}
\usepackage{booktabs}
...
\begin{document}
...
\begin{table}
\centering
\renewcommand\arraystretch{1.8}
\caption{Peak wavelength and absorbance measurements, calculated \(\Delta_O\) and \(\epsilon\) values}
\label{tab:results-5.2}
\begin{tabular}[t]{>{\raggedright}p{0.135\linewidth}>{\raggedright}p{0.125\linewidth}>{\raggedright}p{0.125\linewidth}>{\raggedright}p{0.115\linewidth}>{\raggedright}p{0.115\linewidth}>{\raggedright}p{0.135\linewidth}>{\raggedright}p{0.125\linewidth}>{\raggedright\arraybackslash}p{0.125\linewidth}}
\toprule
Ligand & [complex] \([M]\) & Colour & \(\lambda_{max,1}\) \([nm]\) & \(\lambda_{max,2}\) \([nm]\) & Absorbance & \(\Delta_O\) \([eV]\) & \(\epsilon\) \([M^{-1} cm^{-1}]\) \\
\midrule
\ce{H2O} (II) & nnnnnnnnn & short text &nnnnn &nnnnn &nnnnn &nnnn &nnnn \\
\ce{glycine} & nnnnnnnnn & short text &nnnnn &nnnnn &nnnnn &nnnn &nnnnn \\
\ce{C_2O_4^{2-}} & nnnnnnnnn & short text &nnnnn &nnnnn &nnnnn &nnnn &nnnnn \\
\ce{CO_3^{2-}} & nnnnnnnnn & long long long long long long long text &nnnnn &nnnnn &nnnnn &nnnn &nnnn \\
\ce{H_2O} (III) & nnnnnnnnn & short &nnnnn &nnnnn &nnnnn &nnnn &nnn \\
\ce{1,10-phen\-anthroline} & nnnnnnnnn & short &nnnnn &nnnnn &nnnnnn &nnnn &nnn \\
\ce{NO2^{-}} & nnnnnnnnn & long long long long text &nnnnn &nnnnn &nnnnn &nnnn &nnnn \\
\bottomrule
\end{tabular}
\end{table}
...
\end{document}

nnnnnnnnnusually will not be hyphenated. PDFLaTeX and XeLaTeX do not hyphenate the first word of a paragraph, box or table column. You can add\hskip 0ptafter the\raggedrightto change this. But\raggedrightdoes only hyphenate if a single word is wider than the available width. Maybe you want\RaggedRightof packageragged2e. When choosing the widths of the table columns, the column spacing was not taken into account. So the table is several\tabcolsepto wide. – cabohah Oct 04 '23 at 09:43tabularxand/or therotatingpackages useful. The former will calculate widths of columns for you and the latter can be used to turn a table sideways. – cfr Oct 05 '23 at 01:47tabularxand just setting the width to be1.2\textwidthfor example. I am only struggling now to get this table centred, any ideas? – Cale M Oct 05 '23 at 05:41