1

enter image description here

I am trying to make the above table using the code given below.

\begin{table}[ht]
\centering
\caption{Result of transfer learning}
\label{tab2}
\begin{tabular}{|p{3cm}|p{3cm}|p{3cm}|p{3cm}|}

\hline
Model Name & Band/Model & Accuracy & Accuracy after voting \\
\hline
\multirow{3}{4em}{C1 vs C2} & alpha & 58.45\% \\ 
& beta & 60.01\% \\ 
& theta & 54.32\% \\

\hline

\multirow{3}{4em}{C1 vs C3} & alpha & 65.96\% \\ 
& beta & 67.02\% \\ 
& theta & 63.30\% \\ 

\hline

\multirow{3}{4em}{C3 vs C2} & alpha & 55.45\% \\ 
& beta & 64.28\% \\ 
& theta & 57.01\% \\ 

\hline


\hline
\end{tabular}
\end{table}

But as you can see, it is not coming as I expected. There are basically two issues that I am facing.

1 - How do I add values to the right-most column ( Accuracy after voting column)? I have to only add one value in this column per row unlike three values in the columns before it which is why I am having problems.

2 - How do I close the bracket on the right end?

1
  • 1
    Welcome to TeX.SE. – Mico Jun 11 at 5:18
2

1 - How do I add values to the right-most column ( Accuracy after voting column)? I have to only add one value in this column per row unlike three values in the columns before it which is why I am having problems.

2 - How do I close the bracket on the right end?

For Q1, just use a \multirow directive in the final column -- akin to what you're doing in the first column. For Q2, just add extra & particles in the rows for which you don't already have a \multirow directive in column 4.

There are two additional issues. First, with fixed column widths there's no guarantee that the four-column table will fit inside the width of the text block. Thus, I'd like to suggest replace the tabular with a tabularx column. Second, since the table has quite a few \multirow{3}{*}{...} directives, I'd also recommend creating a shortcut macro, say,

 \newcommand\MR[1]{\multirow{3}{*}{#1}}

to simplify inputing the correspongding material.

The result of implementing these recommendations is shown in table 1 below.

Do note that the "look" of table 1 isn't exactly open and inviting. If a table isn't open and inviting, your readers are simly less likely to engage with the table's contents. I would therefore also like to recommend that you (a) get rid of all vertical rules and most horizontal rules and (b) use some of the line-drawing macros of the booktabs package -- specifically: \toprule, \midrule, \bottomrule, and \addlinespace. The result of implementing these additional recommendations is shown in Table 2 below.

enter image description here

\documentclass{report} % or some other suitable document class
\usepackage{tabularx,ragged2e,multirow}
\newcolumntype{L}{>{\RaggedRight}X}
\newcolumntype{C}{>{\Centering}X}
\newcommand\MR[1]{\multirow{3}{*}{#1}} % handy shortcut macro
\usepackage[skip=0.333\baselineskip]{caption} % optional
\usepackage{booktabs}

\begin{document}
\setcounter{chapter}{5} % just for this example

\begin{table}[ht]
\caption{Result of transfer learning, Take 1} \label{tab1}
\begin{tabularx}{\textwidth}{|*{4}{L|}}
\hline
Model Name & Band\slash Model & Accuracy & Accuracy after voting \\
\hline
\MR{C1 vs C2} & alpha & 58.45\% & \MR{something} \\
   & beta  & 60.01\% & \\ 
   & theta & 54.32\% & \\
\hline
\MR{C1 vs C3} & alpha & 65.96\% & \MR{something} \\
   & beta  & 67.02\% & \\ 
   & theta & 63.30\% & \\ 
\hline
\MR{C3 vs C2} & alpha & 55.45\% & \MR{something} \\ 
   & beta  & 64.28\% & \\ 
   & theta & 57.01\% & \\ 
\hline
\end{tabularx}
\end{table}

\begin{table}[ht]
\caption{Result of transfer learning, Take 2} \label{tab2}
\begin{tabularx}{\textwidth}{@{} LCCC @{}}
\toprule
Model Name & Band\slash Model & Accuracy & Accuracy after voting \\
\midrule
\MR{C1 vs C2} & alpha & 58.45\% & \MR{something} \\
   & beta  & 60.01\% \\ 
   & theta & 54.32\% \\
\addlinespace
\MR{C1 vs C3} & alpha & 65.96\% & \MR{something} \\
   & beta  & 67.02\% \\ 
   & theta & 63.30\% \\ 
\addlinespace
\MR{C3 vs C2} & alpha & 55.45\% & \MR{something} \\ 
   & beta  & 64.28\% \\ 
   & theta & 57.01\% \\ 
\bottomrule
\end{tabularx}
\end{table}

\end{document}
1
  • as is already mentioned, you always need to put all ampersants to table body that you will get last vertical line in table
  • for column with numbers I would use S column type defined in the siunitx package and makecell package for column header
  • it is not clear, what is in the last column. A number, a text, just check mark? I consider the last possibility
\documentclass{article}
\usepackage{dingbat}
\usepackage{makecell, multirow}
\usepackage{siunitx}

\begin{document}
    \begin{table}[ht]
\centering
\caption{Result of transfer learning}
\label{tab2}
\setcellgapes{2pt}
\makegapedcells
\begin{tabular}{|l|l|S[table-format=2.2,
                       table-space-text-post=\,\%]|c|}
    \Xhline{1pt}
\makecell{Model\\ Name} 
    &   \makecell{Band/\\ Model}
        &   {\makecell{Accuracy}} 
            &   \makecell{Accuracy\\ after voting} \\
    \Xhline{0.7pt}
\multirow{3.4}*{C1 vs C2} 
    & alpha & 58.45\,\% & \multirow{3.4}{*}{\checkmark}   \\
    & beta  & 60.01\,\% &                         \\
    & theta & 54.32\,\% &                         \\
    \hline
\multirow{3.4}{*}{C1 vs C3} 
    & alpha & 65.96\,\% & \multirow{3.4}{*}{\checkmark}   \\
    & beta  & 67.02\,\% &                         \\
    & theta & 63.30\,\% &                         \\
    \hline
\multirow{3.4}{*}{C3 vs C2}
    & alpha & 55.45\,\% & \multirow{3.4}{*}{\checkmark}   \\
    & beta  & 64.28\,\% &                         \\
    & theta & 57.01\,\% &                         \\
    \Xhline{1pt}
\end{tabular}
    \end{table}
\end{document}

enter image description here

2
  • I would go with \multirow{3}{...}{...}, not \multirow{3.4}{...}{...}. – Mico Jun 11 at 6:25
  • @Mico, because I use \makegapedcells which introduce additional vertical space in cells, the cell content in \multirow{3.4}{...}{...} is better vertical centered. The same result is obtained by use of \multirow{3}*[-2pt]{C1 vs C2}, however I rather estimate this 2pt shift by decimal numbers of spanning text lines. – Zarko Jun 11 at 6:33
0
\documentclass[10pt,a4paper]{article}

\usepackage{multirow, makecell}

\begin{document}
    \begin{table}[ht]
        \centering
        \caption{Result of transfer learning}
        \label{tab2}
        \begin{tabular}{|p{3cm}|p{3cm}|p{3cm}|p{3cm}|}
            \hline
            Model Name & Band/Model & Accuracy & Accuracy after voting \\
            \hline
            \makecell{C1 vs C2} & \makecell{alpha\\beta\\theta} & \makecell{58.45\% \\60.01\%\\54.32\%}&z\\ 
            \hline
        \end{tabular}
    \end{table}
    
\end{document}

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.