1

I am writing a report using latex on overleaf. After a paragraph I want to add a table:

\begin{table}[]
    \centering
    \caption{Two Object Detection Types}
    \begin{tabular}{ll}
        \hline
        % \rowcolor[HTML]{C0C0C0}
        % \multicolumn{2}{c}{\cellcolor[HTML]{C0C0C0}\textbf{Types of Object Detection Detectors}} \\ \hline
        % \rowcolor[HTML]{EFEFEF} 
        \multicolumn{1}{|c|}{\cellcolor[HTML]{EFEFEF}{\ul \textbf{One Stage Detectors}}} & \multicolumn{1}{c|}{\cellcolor[HTML]{EFEFEF}{\ul \textbf{Two Stage Detectors}}} \\ \hline
        \multicolumn{1}{|c|}{Single Shot Detector} & \multicolumn{1}{|c|}{RCNN family} \\ \hline
        \multicolumn{1}{|c|}{YOLO v1-v4} & \multicolumn{1}{|c|}{CenterNet} \\ \hline
        \multicolumn{1}{|c|}{Scaled YOLO v4} & \multicolumn{1}{|c|}{EfficientDet} \\ \hline
    \end{tabular}
\end{table}

I have used this website to generate the code.

But I have a paragraph before this table and there are whitespaces in between as shown in the figure below. I would like to know how do I remove them whitespace. enter image description here

Not only that but I am also getting the error: Undefined Control Sequence for the second and third multicolumn lines in the above code. Can someone explain to me why this is and how it can be resolved?

Thanks.

Edit 1:

enter image description here

6
  • In order to help you you should show an emc. Please read carefully this page: tex.meta.stackexchange.com/q/228/231952. The "Undefined Control Sequence" error will disappear if you you load all the necessary packages: multicol, soul, xcolor, colortbl
    – Ivan
    Mar 25, 2021 at 17:19
  • Additionally \begin{table}[] should probably be \begin{table}[htbp] just in case. BTW: from where do to have that using \ul here is a good idea?
    – daleif
    Mar 25, 2021 at 17:26
  • emc? Also I have included the packages as mentioned on the website from which I converted the excel table to latex: % \usepackage[table,xcdraw]{xcolor} % If you use beamer only pass "xcolor=table" option, i.e. \documentclass[xcolor=table]{beamer} % \usepackage[normalem]{ulem} % \useunder{\uline}{\ul}{}
    – duddal
    Mar 25, 2021 at 17:32
  • I have solved it. I forgot to add [H] after \begin{table}. Apologies. Can I post this as an answer?
    – duddal
    Mar 25, 2021 at 17:33
  • you would get much simpler code if you simply hand wrote the table, that site comes up quite offten always with massively over-complicated code with redundant \multicolumn everywhere Mar 25, 2021 at 21:06

1 Answer 1

1

There is nothing very wrong with the table except the command \ul that must be defined or be provided by a package, that must be loaded.

For underline the first bold faced row (an overkill) you might use the package soul and its command \ul. The correct use for a bold underline is \textbf{\ul{One Stage Detectors}}.

You don't need all the complicated \multicolumn{1}{|c|}{.. for such a simple table. They are artifacts from the table generator.

What is needed is to add vertical space in the first row to accommodate the underline. Done with mutirow, making the first row two rows high.

And do not use [H]. Use [h!] instead.

Next time please provide the complete MWE with its preamble.

w

\documentclass[12pt,a4paper]{report}

\usepackage{kantlipsum} % dummy text    
\usepackage[table]{xcolor}  
\usepackage{soul} % underlines
\usepackage{multirow}   % multiple rows

\begin{document}
    
1.  \kant[1]

    \begin{table}[h!]
        \sffamily
        \centering
        \caption{Two Object Detection Types}    
        \smallskip  
        \begin{tabular}{|c|c|}
        \hline  
        \cellcolor{gray!10}  &\cellcolor{gray!10}\\
        \multirow{-2}{*}{\cellcolor{gray!10}\textbf{\ul{One Stage Detectors}}}& 
        \multirow{-2}{*}{\cellcolor{gray!10}\textbf{\ul{Two Stage Detectors}}}\\
        \hline
        Single Shot Detector    & mRCNN family  \\ \hline
        YOLO v1-v4              & CenterNet     \\ \hline
        Scaled YOLO v4          & EfficientDet  \\ \hline
        \end{tabular}
    \end{table}

2.  \kant[2]    
    
\end{document}
2
  • Okay, I understand now thank you. But the Column headings "One stage Detectors" and "Two Stage Detectors" are not centered as can be seen in Edit 1 of the question. And I have included all the necessary packages in the preamble.
    – duddal
    Mar 25, 2021 at 17:52
  • @duddal Please see the updated answer. Mar 25, 2021 at 19:04

You must log in to answer this question.

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