2

I want to create a table with one column in the first row, followed by 4 columns in the second row. I have attached the image of the desired table structure. The image does not show a vertical line in the last column of row 2. I need a vertical line in the final table. Below is the code from wiki Latex Tables. However, the table structure is not the same. How to get the desired table structure?

\usepackage{multirow}

\begin{tabular}{cc|c|c|c|c|l} \cline{3-6} 

& & \multicolumn{4}{ c| }{Primes} \\ \cline{3-6} 
& & 2 & 3 & 5 & 7 \\ \cline{1-6}
\multicolumn{1}{ |c  }{\multirow{2}{*}{Powers} } & 
\multicolumn{1}{> |c| }{504} & 3 & 2 & 0 & 1 &     \\ \cline{2-6} 
\multicolumn{1}{ |c }{} & 
\multicolumn{1}{ |c| }{540} & 2 & 3 & 1 & 0 &     \\ \cline{1-6} 
\multicolumn{1}{ |c  }{\multirow{2}{*}{Powers}} & 
\multicolumn{1}{ |c| }{gcd} & 2 & 2 & 0 & 0 & min \\ \cline{2-6}
\multicolumn{1}{ |c }{}                        & 
\multicolumn{1}{ |c| }{lcm} & 3 & 3 & 1 & 1 & max \\ \cline{1-6} 
\end{tabular}

enter image description here

1
  • What are all these \ multicolumn{1}{|c|}` for?
    – Bernard
    Feb 3, 2020 at 21:08

2 Answers 2

4

Unnecessarily complicated. Try this way:

mwe

\documentclass{article}
\begin{document}
\begin{tabular}{|l|l|l|l|}\cline{1-1}
    11 \\\hline
    21 & 22 & 23 & 24\\\hline
\end{tabular}
\end{document}
3
  • Thanks Fran. The catch is \cline{1-1}. Otherwise, it's a four-column table. Feb 3, 2020 at 21:13
  • 2
    @TriptiAgrawal The "trick" is also make only one cell in the first row, i.e. without add any &. The \cline only control the width of the first horizontal line, but not the vertical lines.
    – Fran
    Feb 3, 2020 at 21:19
  • Ok, Fran. I got it. Feb 3, 2020 at 21:30
2

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{llll}[hvlines,corners=NE] % NE: north-east
  11 \\
  21 & 22 & 23 & 24\\
\end{NiceTabular}
\end{document}

Output of the above code

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.