1

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}
5
  • 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. Mar 5 '16 at 20:00
  • does tabularx always give the same length to all columns ?
    – Cfun
    Mar 5 '16 at 20:01
  • all the ones marked with X, yes Mar 5 '16 at 21:14
  • You would still need something like {\dimexpr 0.2\textwidth - 2\tabcolsep-1.2\arrayrulewidth} 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
    – Cfun
    Mar 6 '16 at 16:51
5

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}

enter image description here

2
  • 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.
    – Cfun
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.