0

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:

  1. The table is not centred in the page (it spills into the right margin)
  2. 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}

output table from code above overflowing text block with no line breaks

Willoughby
  • 3,649
Cale M
  • 1
  • Sequences of a single consonant are not words and in most languages hard to hyphenate. So nnnnnnnnn usually will not be hyphenated. PDFLaTeX and XeLaTeX do not hyphenate the first word of a paragraph, box or table column. You can add \hskip 0pt after the \raggedright to change this. But \raggedright does only hyphenate if a single word is wider than the available width. Maybe you want \RaggedRight of package ragged2e. When choosing the widths of the table columns, the column spacing was not taken into account. So the table is several \tabcolsep to wide. – cabohah Oct 04 '23 at 09:43
  • 1
  • Welcome! You might also find tabularx and/or the rotating packages 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:47
  • Thank you for your replies. I have had some success using tabularx and just setting the width to be 1.2\textwidth for example. I am only struggling now to get this table centred, any ideas? – Cale M Oct 05 '23 at 05:41

0 Answers0