1

I am trying to get \multicolumn to work with lists inside tabularx, but the text itself does not occupy all of the space available. The answers to similar questions I found do not seem to work in this case. How can the list content be forced to use multiple columns (as the text does when just using \lipsum[1][1] inside the \multicolumn argument instead of the list)?

This is my current code:

\documentclass{scrartcl}

\usepackage{lipsum}
\usepackage{enumitem}

\usepackage{tabularx}
\usepackage{array}

% Define own columns, using a snippet from https://tex.stackexchange.com/a/204284/ in this case.
\newcolumntype{C}{>{\hsize=3\hsize\centering\arraybackslash}X}
\newcolumntype{D}{>{\hsize=2\hsize\centering\arraybackslash}X}
\newcolumntype{E}{>{\hsize=3\hsize\raggedright\arraybackslash}X}
\newcolumntype{F}{>{\hsize=2\hsize\raggedright\arraybackslash}X}

\begin{document}

\begin{tabularx}{\linewidth}{
    |X
    *{4}{|X|}
    X|
}
    \hline
    \multicolumn{6}{|c|}{Some text} \\
    \hline
    \multicolumn{2}{|D}{Column 1} & \multicolumn{2}{|D}{Column 2} & \multicolumn{2}{|D|}{Column 3} \\
    \hline
    \multicolumn{2}{|F}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[1][1]
        \item Item 2
    \end{itemize}} &
    \multicolumn{2}{|F}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[2][2]
        \item Item 2
    \end{itemize}} &
    \multicolumn{2}{|F|}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[3][3]
        \item Item 2
    \end{itemize}} \\
    \hline
    \multicolumn{3}{|C}{Column 1} & \multicolumn{3}{|C|}{Column 2} \\
    \hline
    \multicolumn{3}{|E}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[1][1]
        \item Item 2
    \end{itemize}} &
    \multicolumn{3}{|E|}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[2][2]
        \item Item 2
    \end{itemize}} \\
    \hline
\end{tabularx}

\end{document}

output

2 Answers 2

1

a different approach: combination of two (vertically) successive tables which gives desired result. for column headers is used \thead command from the makecell package:

\documentclass{scrartcl}
\usepackage{enumitem}
\usepackage{makecell, tabularx}
\renewcommand\theadfont{\normalsize}
\renewcommand\theadgape{}

\usepackage{lipsum} % for dummy text
\begin{document}
{
\centering
\setlist[itemize]{nosep,
                  leftmargin = 0pt,
                  label      = \empty,
                  before     = \vspace{-0.4\baselineskip},
                  after      = \vspace{-\baselineskip}
                    }
% first table with three columns
\begin{tabularx}{\linewidth}{|*{3}{>{\raggedright\arraybackslash}X|}}
    \hline
\multicolumn{3}{|c|}{Some text} \\
    \hline
\thead{Column 1}    & \thead{Column 2} & \thead{Column 3} \\
    \hline
    \begin{itemize}
    \item \lipsum[1][1]
    \item Item 2
    \end{itemize}   &   \begin{itemize}
                    \item \lipsum[2][2]
                    \item Item 2
                        \end{itemize}   &   \begin{itemize}
                                        \item \lipsum[3][3]
                                        \item Item 2
                                            \end{itemize}
\end{tabularx}\\[-1pt]
% second table two three columns
\begin{tabularx}{\linewidth}{|*{2}{>{\raggedright\arraybackslash}X|}}
    \hline
\thead{Column 1}    & \thead{Column 2}                  \\
    \hline
    \begin{itemize}
    \item \lipsum[1][1]
    \item Item 2
    \end{itemize}   &   \begin{itemize}
                    \item \lipsum[2][2]
                    \item Item 2
                        \end{itemize}                   \\
    \hline
\end{tabularx}
}
\end{document}

enter image description here

1

Redefining the E and F columntypes as p columns seems to solve the problem:

\documentclass{scrartcl}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{array}
\usepackage{multirow}
\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
% Define own columns, using a snippet from https://tex.stackexchange.com/a/204284/ in this case.
\newcolumntype{C}{>{\hsize=3\hsize\centering\arraybackslash}X}
\newcolumntype{D}{>{\hsize=2\hsize\centering\arraybackslash}X}
\newcolumntype{E}{>{\Centering\arraybackslash\compress}p{\dimexpr\linewidth/2-4\tabcolsep-2\arrayrulewidth}}
\newcolumntype{F}{>{\RaggedRight\arraybackslash\compress}p{\dimexpr\linewidth/3-2\tabcolsep-2\arrayrulewidth}}

\begin{document}

\begin{tabularx}{\linewidth}{
    |X
    *{4}{|X|}
    X|
}
    \hline
    \multicolumn{6}{|c|}{Some text} \\
    \hline
    \multicolumn{2}{|D}{Column 1} & \multicolumn{2}{|D}{Column 2} & \multicolumn{2}{|D|}{Column 3} \\
    \hline
    \multicolumn{2}{|F}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[1][1]
        \item Item 2 aa bb cc dd ee f f g g h h i i kk ll
    \end{itemize}}
    &
    \multicolumn{2}{|F}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[2][2]
        \item Item 2
    \end{itemize}} &
    \multicolumn{2}{|F|}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[3][3]
        \item Item 2
    \end{itemize}} \\
    \hline
    \multicolumn{3}{|C}{Column 1} & \multicolumn{3}{|C|}{Column 2} \\
    \hline
    \multicolumn{3}{|E}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item Lorem ipsum dolor sit amet, consec\-te\-tuer adipiscing elit.
        \item Item 2
    \end{itemize}} &
    \multicolumn{3}{|E|}{\begin{itemize}[leftmargin=0mm,label=\empty]
        \item \lipsum[2][2]
        \item Item 2
    \end{itemize}} \\
    \hline
\end{tabularx}

\end{document} 

enter image description here

2
  • Where do the different factors for the calculation of the column width come from? The first one seems to be the number of columns, but I am unsure about the others.
    – epR8GaYuh
    Commented May 4, 2019 at 17:01
  • 1
    You're vright for the first factor. For the other terms, for a multicolumn{2}, you save 2\tabcolsep for the middle of the mullticolumn; plus the thickness of the verical rules declared in the table preamble.
    – Bernard
    Commented May 4, 2019 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .