1

How can I achieve this table in latex

enter image description here

As of now this is the result

enter image description here

by using this code

\begin{table}[]
    \centering
    \caption{My caption}
    \label{my-label}
    \begin{tabular}{|l|l|l|l|l|l|l|l|}
    \hline
    \multirow{2}{*}{Criteria} & \multirow{2}{*}{Expected} &  \multicolumn{3} 
     {l|}{Actual } & \multirow{2}{*}{Matching Rate} \\ \cline{3-7}
  &  & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 \\ \cline{3-7} \hline
    \end{tabular}
\end{table}
2

3 Answers 3

3

Something like this?

\documentclass[10pt,a4paper]{article}
\usepackage{multirow}
\begin{document}
\begin{table}[]
    \begin{tabular}{|c|c|c|c|c|c|c|c|}
        \hline
        \multirow{2}{*}{\textbf{Criteria}}                                                               & \multirow{2}{*}{\textbf{Expected}}                                 & \multicolumn{5}{c|}{\textbf{Actual}}                                                                                                                                                                                                                                                                           & \multirow{2}{*}{\textbf{\begin{tabular}[c]{@{}c@{}}Matching\\ rate\end{tabular}}} \\ \cline{3-7}
        &                                                                    & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 1\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 2\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 3\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 4\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 5\end{tabular}} &                                                                                   \\ \hline
        \multicolumn{1}{|l|}{\begin{tabular}[c]{@{}l@{}}The device can\\ detect drowsiness\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}2 to 3 \\ seconds\end{tabular}} & 2 sec                                                      & 3 sec                                                      & 2 sec                                                      & 2 sec                                                      & 2 sec                                                      & 100\%                                                                             \\ \hline
        \multicolumn{7}{|r|}{\textbf{Functionality}}                                                                                                                                                                                                                                                                                                                                                                                                                                           & \textbf{100\%}                                                                    \\ \hline
    \end{tabular}
\end{table}
\end{document}

to get:

enter image description here

2
  • can you fix the spacing sir? I'm a little bit confuse to it thanks
    – Beginner
    Feb 1, 2019 at 8:09
  • @Raaja I will look into that. And, do you mean the first and second rows? Feb 1, 2019 at 8:12
1

For information, here is a way to create that table with {NiceTabular} of nicematrix.

\documentclass[10pt,a4paper]{article}
\usepackage{geometry}
\usepackage{nicematrix}

\begin{document}

\begin{table}
\centering
\begin{NiceTabular}{m[l]{2.7cm}cccccccccc}[hvlines,cell-space-limits=3pt]
\RowStyle[nb-rows=2]{\bfseries}
\Block[c]{2-1}{Criteria} & \Block{2-1}{Expected} & \Block{1-5}{Actual} &&&&& \Block{2-1}{Matching \\ rate} \\
& & \Block{}{Trial\\ 1} & \Block{}{Trial\\ 2} & \Block{}{Trial\\ 3} & \Block{}{Trial\\ 4}  &  \Block{}{Trial\\ 5} \\
The device can detect drowsiness & \bfseries \Block{}{2 to 3 \\ seconds} 
& 2 sec & 3 sec & 2 sec & 2 sec & 2 sec & 100\% \\
\RowStyle{\bfseries}
\Block[r]{1-7}{Functionality} &&&&&&& 100\% 
\end{NiceTabular}
\end{table}

\end{document}

You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

enter image description here

However, I would recommend a design in the spirit of booktabs.

1

With tabularray:

\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{tabularray}

\begin{document}
\begin{table}\centering
    \caption{My table with \texttt{tabularray}}\label{my-label-t}
    \begin{tblr}{
      colspec={X[l]*{7}{c}},
      hlines, vlines,
      row{1,2,Z}={font=\bfseries},
      column{2}={font=\bfseries}
      }
    \SetCell[r=2]{c}Criteria & \SetCell[r=2]{c}Expected & \SetCell[c=5]{c}Actual &&&&& \SetCell[r=2]{c}{Matching\\ Rate} \\ 
    &  & {Trial\\ 1} & {Trial\\ 2} & {Trial\\ 3} & {Trial\\ 4} & {Trial\\ 5} &\\
    The device can detect drowsiness & 2 sec & 3 sec & 2 sec & 2 sec & 2 sec & 100\% \\
    \SetCell[c=7]{r} Functionality &&&&&&& 100\% 
  \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 .