Word Wrap in Table Cell in BOOKTABS Tables

booktabstableswordbreak

In a Nutshell:

How can you provide word wrap in left-aligned table cell when you are using the package bookstabs?

My Problem in Detail:

I am writing a scientific paper to be (hopefully) published in an ACM magazine. The document class includes the package booktabs: https://ctan.org/pkg/booktabs and the style guide does not allow to use other table styles.

Before that, in a draft document, I had this table, using the package tabularray:

\documentclass{article}
\usepackage{tabularray} % <-- line 2
\begin{document}
\begin{table}
    \begin{tblr}{X[l]X[l]rrr} % <-- line 5
        \hline
        Authors/Editors & Title & Pages & Year & Ref. \\
        \hline
        David Salomon and Giovanni Motta & 
        Handbook of Data Compression & 1,370 & 2010 & [1] \\
        Colt McAnlis and Aleks Haecky & 
        Understanding Compression: Data Compression 
        for Modern Developers & 241 & 2016 & [2] \\
        \hline
    \end{tblr} % <-- line 15
\end{table}
\end{document}

It produces this table:

table made with package tabularray
fig 1: table made with package tabularray

Then I tried it in the ACM template that uses booktabs and I failed. Here is an example code using this package. Only lines 2, 5 and 15 are different (marked with comments):

\documentclass{article}
\usepackage{booktabs} % <-- line 2
\begin{document}
\begin{table}
    \begin{tabular}{llrrr} % <-- line 5
        \hline
        Authors/Editors & Title & Pages & Year & Ref. \\
        \hline
        David Salomon and Giovanni Motta & 
        Handbook of Data Compression & 1,370 & 2010 & [1] \\
        Colt McAnlis and Aleks Haecky & 
        Understanding Compression: Data Compression 
        for Modern Developers & 241 & 2016 & [2] \\
        \hline
    \end{tabular} % <-- line 15
\end{table}
\end{document}

Here is the result:

table made with package booktabs
fig 2: table made with package booktabs and llrrr

There is no word wrap and the table is too wide to fit on the page. It is cut off at the right side.

With tabularray I can specify word wrap in a left-aligned table cell with the parameter X[l] (in line 5). When I try this with booktabs I get an error message ("LaTeX Error: Illegal character in array arg") and table cells without word wrap and centered text:

second version using booktabs
fig 3: table made with package booktabs and X[l]X[l]rrr

When I replace X[l] with l I get what you can see in figure 2 (without an error).

On https://ctan.org/pkg/booktabs is a documentation of the package booktabs which is 18 pages long, but it nowhere mentions column widths, word wrap or similar topics. In fact all 18 pages deal only with one topic: the thickness of horizontal lines, which is not very helpful.

Here is my question:

Please can you tell me, what I must do to create a table with word wraps as shown in my first example, but for the package bookstabs?

Best Answer

The problem is not with you using booktabs but that you have not specified how you want the columns to be set. Use p{width} for a column with multiple text lines.

% booktabsprob.tex  SE 640799

\documentclass{article}
\usepackage{booktabs} % <-- line 2
\begin{document}
\begin{table}
%    \begin{tabular}{llrrr} % <-- line 5
    \begin{tabular}{lp{4cm}rrr} % <-- line 5
        \hline
        Authors/Editors & Title & Pages & Year & Ref. \\
        \hline
        David Salomon and Giovanni Motta & 
        Handbook of Data Compression & 1,370 & 2010 & [1] \\
        Colt McAnlis and Aleks Haecky & 
        Understanding Compression: Data Compression 
        for Modern Developers & 241 & 2016 & [2] \\
        \hline
    \end{tabular} % <-- line 15
\end{table}
\end{document}

enter image description here

Related Question