4

I want to create a table that uses both multicolumn and multirow. Currently, I used the code:

\begin{table}[!h]
\label{T:equipos}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multicolumn{7}{|c|}{\textbf{Datasets}}  \\ 
\cline{1-7}
\multicolumn{3}{|c|}{\textbf{in-house}} &  \multicolumn{4}{c|}{\textbf{NSL-KDD}} \\
\hline
\hline

DR & Accuracy & FPR & K value & DR & Accuracy & FPR\\ \hline
\multirow{ 1}{*}{99.75} & \multirow{ 1}{*}{99.72} & \multirow{ 1}{*}{0.06} & 

1 & 90.53 & 96.14 & 0.0\\ \hline
&  &  & 2 & 94.22 & 97.65 & 0.0\\ \hline
&  &  & 3 & 95.50 & 98.16 & 0.0\\ \hline
&  &  & 4 & 96.10 & 98.41 & 0.0\\ \hline
&  &  & 5 & 97.7 & 98.92 & 0.11\\ \hline
\end{tabular}
\end{center}
\end{table}

which produces the following table

enter image description here

but what I want is this:

enter image description here

how can I achieve the format of the table above i.e., table 2 above?

6
  • 1
    Why do you use a 1-row multirow?
    – TeXnician
    Aug 7, 2017 at 8:04
  • Try sketching your table here, tablesgenerator.com. Then just optimize the code for you. Edit: Also, @TeXnician is right.. 1-row multirow is a no-no. Aug 7, 2017 at 8:15
  • @TiagoCorreia But also using a table generator, if the table is nearly correct...
    – TeXnician
    Aug 7, 2017 at 8:18
  • Yes, not ideal, but it's an idea to try to "debug" any errors made by hand. Aug 7, 2017 at 8:25
  • 1
    @TiagoCorreia Thanks for that generator link. I think in future it will save me a lot of headache
    – obiigbe91
    Aug 7, 2017 at 20:22

1 Answer 1

7

To be honest: You do not need multirow for that.

multirow

\documentclass{article}
\begin{document}
\begin{table}[!htb]
\label{T:equipos}
\begin{center}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\multicolumn{7}{|c|}{\textbf{Datasets}}  \\ 
\cline{1-7}
\multicolumn{3}{|c|}{\textbf{in-house}} &  \multicolumn{4}{c|}{\textbf{NSL-KDD}} \\
\hline
\hline
DR & Accuracy & FPR & K value & DR & Accuracy & FPR\\ \hline
99.75 & 99.72 & 0.06 & 1 & 90.53 & 96.14 & 0.0\\ \cline{4-7}
&  &  & 2 & 94.22 & 97.65 & 0.0\\ \cline{4-7}
&  &  & 3 & 95.50 & 98.16 & 0.0\\ \cline{4-7}
&  &  & 4 & 96.10 & 98.41 & 0.0\\ \cline{4-7}
&  &  & 5 & 97.7 & 98.92 & 0.11\\ \hline
\end{tabular}
\end{center}
\end{table}
\end{document}

Update: You should maybe consider to (a) align your values at the decimal point and (b) use booktabs (just as suggestion):

booktabbed

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[!htb]
\label{T:equipos}
\begin{center}
\begin{tabular}{SSSlSSS}
\toprule
\multicolumn{7}{c}{\bfseries Datasets}\\
\multicolumn{3}{c}{\bfseries in-house} &  \multicolumn{4}{c}{\bfseries NSL-KDD}\\\cmidrule(lr){1-3}\cmidrule(lr){4-7}
\multicolumn{1}{l}{DR} & \multicolumn{1}{l}{Accuracy} & \multicolumn{1}{l}{FPR} & 
  K value & \multicolumn{1}{l}{DR} & \multicolumn{1}{l}{Accuracy} & \multicolumn{1}{l}{FPR}\\\midrule
99.75 & 99.72 & 0.06 & 1 & 90.53 & 96.14 & 0.0\\
&  &  & 2 & 94.22 & 97.65 & 0.0\\
&  &  & 3 & 95.50 & 98.16 & 0.0\\
&  &  & 4 & 96.10 & 98.41 & 0.0\\
&  &  & 5 & 97.7 & 98.92 & 0.11\\\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}
0

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.