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
-
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}
-
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{adjustbox}
\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}
Best Answer
You can use
and
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 usetabularx
at all, and just usem
columns of a fixed width.If you need to span two
X
columns of unknown width you can use