我试图\multicolumn
使用 中的列表tabularx
,但文本本身并未占据所有可用空间。我找到的类似问题的答案似乎在这种情况下不起作用。如何强制列表内容使用多列(就像在参数\lipsum[1][1]
内部\multicolumn
而不是列表内使用时文本所做的那样)?
这是我当前的代码:
\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}
答案1
一种不同的方法:组合两个(垂直)连续的表以得到所需的结果。对于列标题,使用包\thead
中的命令 makecell
:
\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}
答案2
将E
和F
列类型重新定义为p
列似乎可以解决问题:
\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}