# Justified text and multicolumn size in tabularx

I'd like to create table with (a lot of) justified text and some multicolumns. My example is below. It works more or less... but

1. I get lots of underfull \hbox notices, which I think it's because the text is not flushedleft... how do I get rid of them? (I don't want my text flushed left}

2. I am not sure about how I did the multicolumn, I just want it to span over two columns. Is there a better way of doing it?

I saw this What is the correct way to calculate \multicolumn size when using tabularx? but the mulitcolumn does not look quite right to me.

Thanks!

\documentclass[a4paper,11pt,fleqn]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tabularx,calc}
\usepackage{array}
\usepackage{multicol}%,tocbibind, ,fullpage,lastpage,framed}
\usepackage{multirow,booktabs}

\def\tabularxcolumn#1{m{#1}} %defines the X column to use m (\parbox[c]) instead of p (parbox[t]).

\begin{document}

\begin{table}
\setlength{\extrarowheight}{5 pt}
\begin{center}
\begin{tabularx}{\linewidth}{  X  X  X }
\toprule
\multicolumn{1}{c}{A} & \multicolumn{1}{c}{B}  & \multicolumn{1}{c}{C} \\
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus
&
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus
&
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus\\

\multicolumn{2}{m{0.66\linewidth-2\tabcolsep}}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus} &
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus\\

\bottomrule
\end{tabularx}
\end{center}
\end{table}
\end{document}


• I find find any problem with your code. The underfull \hboxes might just be because you're using "Lorem ipsum..." text, for which hyphenation is not properly defined, coupled with the fact that your column width is fairly small. – Werner Jun 5 '14 at 17:16
• I do have the same problem when I type real words! – esperluette Jun 5 '14 at 17:26
• Then it's a result of the narrow columns. Do they need to be so narrow? What about adjusting the page boundary margins using geometry? – Werner Jun 5 '14 at 17:28
• mmm I am not sure, I don't think they are narrow, they are just 3 column as wide as the page with linewidth. – esperluette Jun 5 '14 at 17:33
• but I think you are right @Werner. It is probably an hyphenation problem due to having text in 'narrow' columns. I can't make them any larger and I don't want to change my page margins. I think if I want justified text like that in a table I will have to keep the notices. In fact if I do raggedright like David suggested I don't get the warnings... but not even the text like I want it. Thanks! – esperluette Jun 5 '14 at 17:52

You can use

 \begin{tabularx}{\linewidth}{*3{>{\sloppy\arraybackslash} X }}


and

\multicolumn{2}{m{0.66\linewidth-2\tabcolsep}}{\sloppy Lorem...


use a ragged setting in the narrow columns to avoid the warnings, such as \raggedright instead of \sloppy. Or modify the value of \hbadness within the table (\hbadness=...)

the multiclolumn width setting is sort of OK as you know in advance the widths, as you have XXX but that implies you could (and perhaps should) do the same at the top level and not use tabularx at all, and just use m columns of a fixed width.

If you need to span two X columns of unknown width you can use

   \multicolumn{2}{>{\sloppy\setlength\hsize{\dimexpr 2\hsize+2\tabcolsep\relax}}X}{Lorem..}

• Thanks for the quick reply. The raggedright solution does not work for me because I want my text justified like in the example. The other solution '\multicolumn{2}{X}{\setlength\hsize{2\hsize+2\tabcolsep} Lorem...' gives me errors! With 'tabular' and 'm' columns it works setting ' \begin{tabular}{ m{3.5cm} m{3.5cm} m{3.5cm} }' and '\multicolumn{2}{m{7cm+2\tabcolsep}}{Lorem...}' but I still get the notices about the underfull '\hbox' – esperluette Jun 5 '14 at 17:19
• @esperluette ok replace \raggedright by whatever paragraph setting you want eg \sloppy – David Carlisle Jun 5 '14 at 18:27
• @DavidCarlise I get the same number of bad boxes as in the original case. Is there a way I can maybe relax the constraints just within the table so I don't see the warnings? (and just see other more important ones!) Otherwise I think it looks ok... even if the text is a little "stretched" – esperluette Jun 5 '14 at 20:14
• @esperluette lots of ways tex.stackexchange.com/questions/50830/… – David Carlisle Jun 5 '14 at 21:02
• @DavidCarlise Thank you very much, adding a \hbadness=10000 (!!) after \begin{table} did the trick! And does not change the settings for the rest of the document. – esperluette Jun 6 '14 at 12:35