2

I would like to change the first column into three columns, such that I can write three numbers in each row instead of only one. Everything else should stay the same.

\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
    Three numbers stacked? If so, what should the alignment be with respect to the other X-columns? If they should be horizontally spread instead, do you require alignment across the rows? Do you have any restrictions/requirements in terms of the input? Perhaps you can provide an image of the expected output you're after. – Werner Nov 15 '18 at 19:21
1

enter image description here

\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}

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.