# how to fit merged columns/rows content to the appropriate cell width (tabularx)?

This is a follow-up question to how to fit merged columns/rows content to the appropriate cell width?

I am looking to make the same table but using the environment tabularx rather than tabular.

the cells should have the same width (50% 50%) whatever their contents.

Here is my attempt:

\documentclass[a4paper]{report}
\usepackage{multirow}
\usepackage{array}
\usepackage{tabularx}
\begin{document}
\begin{table}[h]
\begin{center}
\renewcommand{\arraystretch}{2}
\begin{tabularx}{\textwidth}{|X|X|X|X|X|}
\hline
\multirow{2}{1cm}{longlonglong line long} & \multirow{2}{3,5cm}{longlong text} & \multirow{2}{3cm}{a very longgggggggg line here} & \multicolumn{2}{c|}{A very longlong long line here longgggg}\\
\cline{4-5}
&   &   & should be equal 50\% & should be equal 50\%\\
\hline
\end{tabularx}
\end{center}
\end{table}
\end{document}

• there really isn't much point to tabularx if all the columns are X, it forces tex to typeset the table multiple times iterating to the optimum column width, when you know in advance that the optimum width is a fifth of the text width. – David Carlisle Mar 5 '16 at 20:00
• does tabularx always give the same length to all columns ? – SAM Mar 5 '16 at 20:01
• all the ones marked with X, yes – David Carlisle Mar 5 '16 at 21:14
• You would still need something like {\dimexpr 0.2\textwidth - 2\tabcolsep-1.2\arrayrulewidth} – John Kormylo Mar 6 '16 at 15:18
• I think i asked a bad question, maybe i'd better just use the environment tabular and specify every column width manually, in thise case – SAM Mar 6 '16 at 16:51

I've split the too columns which were a bit too long with a \\. Then I manually set the new definition for a Z column to be ~20% of the page size. Also I used RaggedRight to make it a bit better as well as booktabs. I still find it ugly

\documentclass[a4paper]{report}
\usepackage{multirow}
\usepackage{array,booktabs,ragged2e}
\newcolumntype{Z}{>{\RaggedRight}p{0.18\textwidth}}
\begin{document}
\begin{table}[h]
\begin{center}
\renewcommand{\arraystretch}{2}
\begin{tabular}{@{}ZZZZZ@{}}
\toprule
\multirow{2}{1cm}{longlonglong line long} & \multirow{2}{3cm}{longlong text} & \multirow{2}{3cm}{a very longgggggggg\\ line here} & \multicolumn{2}{c}{A very longlong long line here longgggg}\\
\cmidrule{4-5}
&   &   & should be equal 50\% & should be equal 50\%\\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}


• I found it ugly myself also, it's an old question i think i used tabular  at the end; by the way i don't think the 50% is fulfilled anyway thanks. – SAM Jun 4 '17 at 21:55
• @SAM it was done on a spree to answer unanswered questions. I gave it my best: although not perfect, an answer is better than none, and can be a starting point for those who might find your question in searches – Moriambar Jun 4 '17 at 22:17