调整多列中的列

调整多列中的列

我想将第一列改为三列,这样我可以在每行中写三个数字,而不是只写一个。其他一切都应保持不变。

\documentclass{article} 
\usepackage{tabularx} 
\usepackage{caption}
\usepackage{showframe} 

\newcommand{\thead}[1]{\begin{tabular}[t]{c}#1\end{tabular}} 

\begin{document} 
\begin{table} 
\centering 
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}p{#1}}  
\begin{tabularx}{\textwidth}{|c|*4{X|}} 
\hline 
& \multicolumn{2}{c|}{\thead{here a longer text is written}} 
& \multicolumn{2}{c|}{\thead{here also a longer text is written}} \\ 
\cline{2-5} 
\thead{A\\number} & left & right & left & right \\ 
\hline 
1 & X & X & X & X\\ 
2 & X & X & X & X\\ 
3 & X & X & X & X\\ 
4 & X & X & X & X\\ 
\hline 
\end{tabularx} 
\end{table} 
\end{document}

答案1

在此处输入图片描述

\documentclass{article} 
\usepackage{tabularx} 
\usepackage{caption}
\usepackage{showframe} 

\newcommand{\thead}[1]{\begin{tabular}[t]{c}#1\end{tabular}} 

\begin{document} 
\begin{table} 
\centering 
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}p{#1}}  
\begin{tabularx}{\textwidth}{|*{3}{c|}*{4}{X|}} 
\hline 
\multicolumn{3}{|c|}{}
&\multicolumn{2}{c|}{\thead{here a longer text\\ is written}} 
& \multicolumn{2}{c|}{\thead{here also a longer\\ text is written}}
\\ 
\cline{4-7} 
\multicolumn{3}{|c|}{\thead{3\\numbers}} &
 left & right & left & right \\ 
\hline 
1&11&21 & X & X & X & X\\ 
2&12&22 & X & X & X & X\\ 
3&13&23 & X & X & X & X\\ 
4&14&24 & X & X & X & X\\ 
\hline 
\end{tabularx} 
\end{table} 
\end{document}

相关内容