![如何在多列中使用多行合并 tabularx 单元格](https://linux22.com/image/416534/%E5%A6%82%E4%BD%95%E5%9C%A8%E5%A4%9A%E5%88%97%E4%B8%AD%E4%BD%BF%E7%94%A8%E5%A4%9A%E8%A1%8C%E5%90%88%E5%B9%B6%20tabularx%20%E5%8D%95%E5%85%83%E6%A0%BC.png)
我使用了一个代码,我有一个使用 tabularx 创建的表,但问题是,我想通过使用tabularx
并使用来创建下表textwidth
我不会改变我的代码结构和表格的宽度:
\documentclass[twocolumn]{svjour3}
\usepackage{graphicx}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X} % new
\usepackage{enumitem} % new
\newlist{tabitem}{itemize}{1} % <-- defined new list
\setlist[tabitem]{nosep, % <-- new list setup
leftmargin=*,
label=$\bullet$,
before=\begin{minipage}[t]{\linewidth},
after=\end{minipage}
}
\begin{table} [htp]
\setcellgapes{2pt}
\centering
\makegapedcells
\setlength\tabcolsep{1pt}
\begin{table} [htp]
\setcellgapes{4pt}
\centering
\makegapedcells
\setlength\tabcolsep{2pt}
\begin{tabularx}{\linewidth}
{| L L|
p{0.18\textwidth} |
p{0.18\textwidth} |
}
\hline
\multicolumn{2}{c}{ \multirow{2}{=} {\centering A}} &
\multirow{2}{=} {\centering TextTextText} &
\multirow{2}{=} {\centering TextTextText}
\\
\hline
\hline
\multicolumn{2}{c}{ {\centering MADM}} &
\multirow{2}{=} {\centering T} &
\multirow{2}{=} {\centering T}
\\
\hline
\end{tabularx}
\end{table}
答案1
\documentclass[twocolumn]{svjour3}
\usepackage{graphicx}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X} % new
\usepackage{enumitem} % new
\newlist{tabitem}{itemize}{1} % <-- defined new list
\setlist[tabitem]{nosep, % <-- new list setup
leftmargin=*,
label=$\bullet$,
before=\begin{minipage}[t]{\linewidth},
after=\end{minipage}
}
\begin{document}
\begin{table}[!htp]
\setcellgapes{2pt}
\centering
\makegapedcells
\begin{tabularx}{\linewidth}{|l|l|X|X|}
\hline
\multicolumn{2}{|l|}{A} & TextTextText & TextTextText \\ \hline
\multicolumn{2}{|l|}{MADM} & T & T \\ \hline
\multirow{2}{*}[-2pt]{AAAA} & \multirow{2}{*}[-2pt]{AAA} & T & T \\ \cline{3-4}
& & T & T \\ \hline
\end{tabularx}
\end{table}
\end{document}
如果您希望在该两栏文档中使用页面宽度的表格,请使用带星号的表格版本 ( \begin{table*}[!htb] .. \end{table*}
):
答案2
\documentclass{scrartcl}
\usepackage{makecell, multirow, tabularx}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{color, colortbl}
\begin{document}
\begin{table}[htbp!]
\centering
\caption{Caption}
\label{tab:my_label}
\begin{tabular}{|l|l|c|c|}
\hline
\multicolumn{2}{|c|}{A} & TextTextText & TextTextText \\
\hline
\multicolumn{2}{|c|}{MADM} & T & T \\
\hline
\multirow{2}{*}{AAA} & \multirow{2}{*}{AAA} & T & T \\
\cline{3-4}
& & \cellcolor{yellow!50} T & T \\
\hline
\end{tabular}
\end{table}
\end{document}
产量
如果您想指定宽度,您可以考虑修改,例如如下所示:
\begin{tabular}{|p{0.1\textwidth}|p{0.1\textwidth}|c|c|}
答案3
编辑:
从序言中删除了未使用的包和样式定义,添加了包hhline
并改进了 MWE 代码:
\documentclass[twocolumn]{svjour3}
\usepackage{graphicx}
\usepackage[column=0]{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\usepackage{hhline, % new
multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X} % new
\usepackage[table]{xcolor} % new
\usepackage{xparse} % new
\NewExpandableDocumentCommand\mcl{O{1}m}
{\multicolumn{#1}{|c|}{#2}}
\begin{document}
\begin{table} [htp]
\centering
\setlength\tabcolsep{2pt}
\begin{tabularx}{\linewidth}{| 0{L} | 0{L}| *{2}{0{p{0.15\textwidth}} |}}
\hline
\mcl[2]{A} & TextTextText & TextTextText \\
\hline
\mcl[2]{MADM}
& T & T \\
\hline
\multirow{2}{=}{AAAA}
& \multirow{2}{=}{AAA}
& T & T \\
\hhline{|~|~|-|-|}
& \mcl[1]{}
& \cellcolor{yellow!30}{T}
& T \\
\hline
\end{tabularx}
\end{table}
\end{document}
答案4
具有(≥ 6.0){NiceTabularX}
。nicematrix
\documentclass[twocolumn]{svjour3}
\usepackage{graphicx}
\usepackage{nicematrix}
\begin{document}
\renewcommand{\arraystretch}{1.4}
\noindent
\begin{NiceTabularX}{\linewidth}{llXX}[hvlines,colortbl-like]
\Block[l]{1-2}{A} && TexttEXTtext & TextTextText \\
\Block[l]{1-2}{MADM} && T & T \\
\Block{2-1}{AAAA} & \Block{2-1}{AAA} & T & T \\
& & \cellcolor{yellow!30} T & T
\end{NiceTabularX}
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。