4

In the following table, I want to use 2 columns under D & 3 columns under F. How to do this?

\begin{table}[]
    \centering
    \begin{tabular}{|c|cc|c|}
     \hline
      
    A    & \multicolumn{2}{c|}{B}  & C\\
     \hline
                              &  D & F & \\
      \hline
      
      \hline
    \end{tabular}
    \caption{}
    \label{tab:my_label}
\end{table}
3
  • Is this the expected output? i.sstatic.net/peOjl.png
    – leandriis
    Sep 28, 2021 at 18:10
  • Yes, I want that.
    – user12290
    Sep 28, 2021 at 18:18
  • Should the 7 cells in the bottom row all have the exact same width?
    – Mico
    Sep 28, 2021 at 18:38

3 Answers 3

6

enter image description here

\documentclass{article}
\begin{document}

    \begin{tabular}{|c|c|c|c|c|c|c|}
      \hline
      A    & \multicolumn{5}{c|}{B}                           & C\\
      \hline
           &  \multicolumn{2}{c|}{D} & \multicolumn{3}{c|}{F} & \\
      \hline
           & 1 & 2                   & 1 & 2 & 3              & \\
      \hline
    \end{tabular}

\end{document}
5

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}[hvlines]{ccccccc}
A & \Block{1-5}{B} &&&&& C \\
  & \Block{1-2}{D} && \Block{1-3}{F} \\
  & 1 & 2 & 1 & 2 & 3 
\end{NiceTabular}

\end{document}

Output of the above code

3

For sake of completeness let me add solution by use of the new LaTeX-3 package tabularray:

\documentclass{article}
\usepackage{tabularray}

\begin{document}
\begin{table}[ht]
\centering
    \begin{tblr}{hlines, vlines, cells={c}}
A   & \SetCell[c=5]{c}  B
        &   &   &   &   & C \\
    & \SetCell[c=2]{c}  D
        &   & \SetCell[c=3]{c}  F
                &   &   &   \\
    & 1 & 2 & 1 & 2 & 3 &   \\
    \end{tblr}
\end{table}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .