[Tex/LaTex] How to split columns into 2

splittablestwo-column

I want the first row to stay normal and then every row after that should be split into 2 columns. I've done it on Microsoft word to show exactly what I want. I tried used multicolumn but couldn't get it to work correctly.

Table

\begin{center}
\begin{tabular}{ |c|c|c|c|c|c|c|c| } 
    \hline
    B    & B 1 & B 2 & B3 & B4 & B5 & B6 & B 7 \\
    \hline
    1   & 12 & 12 & 12 & 12 &12  &12& 12\\ 
    \hline
    2   & 12& 12& 12& 12&12& 12& 12\\ 
    \hline
    3   & & & & & & & \\ 
    \hline
    4   & & & & & & &\\ 
    \hline
    5   & & & & & & &\\ 
    \hline
    6   & & & & & & & \\ 
    \hline
    7   & & & & & & &\\ 
    \hline
\end{tabular}
\end{center}

Best Answer

  • your table code fragment doesn't reproduce showed table. for this it ha defined one column less as needed (you have defined only 8 columns, but showed table has 9)
  • for help to people who like to help you, y\documentclass{...} and ending with `\end{document}, which show your problem. it should have in preamble loaded all to your problem relevant packages (if any needed)
  • as i mentioned in comment, cells cant be split, but can be merged. so solution in general in your case is use command \multicolumn{2}{c}{...} which merge tvo columns and cell's content align in its middle.
  • without knowing content of your table your code snippet can be converted into mwe as follows:

\documentclass{article}

\begin{document}
    \begin{center}
\begin{tabular}{| *{9}{c|} }
    \hline
B    & \multicolumn{2}{c|}{x}
            & \multicolumn{2}{c|}{z}
                    & \multicolumn{2}{c|}{w}
                            & \multicolumn{2}{c|}{t}                \\
    \hline
1   &   12  &   12  &   12  &   12  &   12  &   12  &   12  &   12  \\
    \hline
2   &   12  &   12  &   12  &   12  &   12  &   12  &   12  &   12  \\
    \hline
3   &       &       &       &       &       &       &       &       \\
    \hline
\end{tabular}
    \end{center}
\end{document}

enter image description here

  • however, your table can be written on many diferent way. one of them is usebooktabs packages for horizontal rules where needed, omit vertical riles and for example use modified X columns from package `tabularx:

\documentclass{article}
\usepackage{booktabs, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
    \begin{center}
\begin{tabularx}{\linewidth}{ c *{8}{C} }
    \toprule
B    & \multicolumn{2}{c}{x}
            & \multicolumn{2}{c}{z}
                    & \multicolumn{2}{c}{w}
                            & \multicolumn{2}{c}{t}                \\
    \midrule
1   &   12  &   12  &   12  &   12  &   12  &   12  &   12  &   12  \\
2   &   12  &   12  &   12  &   12  &   12  &   12  &   12  &   12  \\
3   &       &       &       &       &       &       &       &       \\
    \bottomrule
\end{tabularx}
    \end{center}
\end{document}

enter image description here