4

Using the array and multirow packages, I was successfully able to run LaTeX and getting a table environment I desired. (I changed some column names and data values for asking query.) My problem is that I am not getting a horizontal line (within the columns of the table) below the multicolumn for Constants and System values. How to do it using the LaTeX packages? Kindly help me on this! I have enclosed the LaTeX code.. Thanks a lot !!

Best wishes Sundar

LaTeX program :

\documentclass{article}
\usepackage{array,multirow}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of "X" type
\setlength{\extrarowheight}{1pt}
\begin{document}

\begin{table*}
 \caption{System, Constants, Spectral Values and $D_L$}
\label{my-label}
\begin{center}
\begin{tabular}{|c|c|c|c|c|p{1.2cm}|c|c|c|c|c|c|} \hline
\multirow{2}{*}{System} & \multicolumn{4}{c|}{Constants} & $XYZ $& \multicolumn{4}{c|}{Spectral Values} & \multirow{2}{*}{$D_{L}$}& \multirow{2}{*}{Figure} \\
  & $\alpha$ & $\beta$ & $\gamma$ & $\delta$ &   & $z_1$ & $z_2$ & $z_3$ & $z_4$ &  &  \\[2mm] \hline
Ergodic & $6$ & $3$ & $2$ & $4$ & $\alpha = 2$ & $0$ & $1$ & $2$ & $3$ & $0$ & 5 (a) \\[2mm]
  \hline
\end{tabular}
\end{center}
\end{table*}
\end{document}

3 Answers 3

3

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{caption}
\usepackage{nicematrix}

\begin{document}

\begin{table*}
\caption{System, Constants, Spectral Values and $D_L$}
\label{my-label}
\centering
\begin{NiceTabular}[hvlines]{*{12}{c}}
\Block{2-1}{System}  & \Block{1-4}{Constants} & & & & \Block{2-1}{} $XYZ$ & \Block{1-4}{Spectral Values} & & & & \Block{2-1}{$D_{L}$} & \Block{2-1}{Figure} \\
 & $\alpha$  & $\beta$ & $\gamma$ & $\delta$ & & $z_1$ & $z_2$ & $z_3$ & $z_4$ & & \\
Ergodic & $6$ & $3$ & $2$ & $4$ & $\alpha=2$ & $0$ & $1$ & $2$ & $3$ & $0$ & 5 (a)  \\
\end{NiceTabular}
\end{table*}

\end{document}

Output of the above code

4

A possible solution with tblr environment of the new LaTeX3 package tabularray:

\documentclass{article}

\usepackage{caption}
\usepackage{tabularray}

\begin{document}

\begin{table*}
\caption{System, Constants, Spectral Values and $D_L$}
\label{my-label}
\centering
\begin{tblr}{
  colspec = {|c|c|c|c|c|c|c|c|c|c|c|c|},
  cell{1}{1,Y,Z} = {r=2}{m}, % multirow
  cell{1}{6} = {r=2}{h},     % multirow
  cell{1}{2,7} = {c=4}{c},   % multicolumn
  hlines,
}
System  & Constants &         &          &          & $XYZ$      & Spectral Values &       &       &       & $D_{L}$ & Figure \\
        & $\alpha$  & $\beta$ & $\gamma$ & $\delta$ &            & $z_1$           & $z_2$ & $z_3$ & $z_4$ &         &        \\
Ergodic & $6$       & $3$     & $2$      & $4$      & $\alpha=2$ & $0$             & $1$   & $2$   & $3$   & $0$     & 5 (a)  \\
\end{tblr}
\end{table*}

\end{document}

enter image description here

2
  • I was not able to run your LaTeX code and I was getting some error message.. But you say this works in "new LaTeX 3 package".. I am using "MikTeX Revision 2.9.5845" for Windows, and this was not compiling.. I got the answer from Mico and I fixed the Table. I give this reply only as my feedback to you. Thanks!
    – Dr. Sundar
    Sep 2, 2021 at 8:18
  • Sorry, you need MiKTeX version 2021, since it is a new package,
    – L.J.R.
    Sep 2, 2021 at 8:21
4

In a narrow sense, the issue you're facing can be solved by inserting the instructions

\cline{2-5} \cline{7-10}

after the first header line.

However, I'd like to encourage you to rearrange the table to give it a more open and appealing "look", mostly by (a) omitting all vertical bars and (b) using the line-drawing macros of the booktabs package instead of \hline and \cline.

enter image description here

\documentclass{article}
\usepackage{booktabs,array,multirow}
\begin{document}

\begin{table}[ht] % original form, with two \cline directives
\setlength{\extrarowheight}{1pt}
 \caption{System, Constants, Spectral Values and $D_L$}
\label{my-label}
\begin{center}
\begin{tabular}{|c|c|c|c|c|p{1.2cm}|c|c|c|c|c|c|} \hline
\multirow{2}{*}{System} & \multicolumn{4}{c|}{Constants} & $XYZ $& \multicolumn{4}{c|}{Spectral Values} & \multirow{2}{*}{$D_{L}$}& \multirow{2}{*}{Figure} \\
\cline{2-5} \cline{7-10}
  & $\alpha$ & $\beta$ & $\gamma$ & $\delta$ &   & $z_1$ & $z_2$ & $z_3$ & $z_4$ &  &  \\[2mm] \hline
Ergodic & $6$ & $3$ & $2$ & $4$ & $\alpha = 2$ & $0$ & $1$ & $2$ & $3$ & $0$ & 5 (a) \\[2mm]
  \hline
\end{tabular}
\end{center}
\end{table}

\begin{table}[h] % modified for a more open "look"  
\caption{Same table, but with a more open and less busy ``look''\strut}
\label{my-label}
\centering
\begin{tabular}{@{} l *{4}{c} p{1.2cm} *{6}{c} @{}} 
\toprule
System 
& \multicolumn{4}{c}{Constants} 
& $XYZ$ 
& \multicolumn{4}{c}{Spectral Values} 
& $D_{L}$ 
& Figure \\
\cmidrule(lr){2-5} \cmidrule(lr){7-10}
& $\alpha$ & $\beta$ & $\gamma$ & $\delta$ & & $z_1$ & $z_2$ & $z_3$ & $z_4$ \\ 
\midrule
Ergodic & $6$ & $3$ & $2$ & $4$ & $\alpha = 2$ & $0$ & $1$ & $2$ & $3$ & $0$ & 5(a) \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
1
  • Dear Mico: Thank you, your comment was highly useful. I successfully completed the table now.
    – Dr. Sundar
    Sep 2, 2021 at 8:12

You must log in to answer this question.

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