1

I have the following table:

\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}

\begin{table}
\centering
\footnotesize
\begin{tabular}{lllll}
\toprule
Algorithm & Learner Memory & Production & Interpretation & Hyperparameters\\
\midrule
KNN & Samples (S) & KNN-based & KNN-based & $k$\\
\multirow{2}{*}{PE}  & Prototypes (P) & Discriminative & Nearest & $\alpha$\\
                     &                & Descriptive    &         &         \\
\multirow{2}{*}{AP}  & P + S          & Discriminative & Nearest & /       \\
                     &                & Descriptive    &         &         \\
\multirow{2}{*}{CWP} & P + Counts     & Discriminative & Nearest & $\alpha$\\
                     &                & Descriptive    &         &         \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

As you can see, I use multirow to have two entries in the third column. However, I don't like how the output looks. While the entries in the first column (Algorithm) are centered vertically, the other columns where there is only 1 entry (Learner Memory, Interpretation and Hyperparameters) are aligned at the top, because of the multirow. How can I center these entries as well?

3 Answers 3

2

Use makecell. I added some padding between rows:

\documentclass{article}
\usepackage{multirow, makecell}
\usepackage{booktabs}
\def\DisDes{\makecell{Discriminative\\ Descriptive}}

\begin{document}

\begin{table}
  \centering
  \footnotesize
  \renewcommand{\cellalign}{lc}
  \begin{tabular}{lllll}
    \toprule
    Algorithm & Learner Memory & Production & Interpretation & Hyperparameters \\
    \midrule
    KNN & Samples (S) & KNN-based & KNN-based & $k$ \\
    \addlinespace
    PE & Prototypes (P) & \DisDes & Nearest & $\alpha$ \\
    \addlinespace
    AP & P + S & \DisDes & Nearest & / \\
    \addlinespace
    CWP & P + Counts & \DisDes & Nearest & $\alpha$ \\
    \bottomrule
  \end{tabular}
\end{table}

\end{document} 

enter image description here

1
  • This looks like the clean and simple solution I am looking for. The padding also makes the distinction between rows very clear. Great!
    – JNevens
    May 17, 2017 at 8:32
1

I'll take Bernard's fine solution, but do it with stacks instead of makecell (and use fewer keystrokes).

\documentclass{article}
\usepackage{multirow,stackengine}
\usepackage{booktabs}
\def\DisDes{\addstackgap[3pt]{\Centerstack[l]{Discriminative Descriptive}}}
\begin{document}
\begin{table}
  \centering
  \footnotesize
  \begin{tabular}{lllll}
    \toprule
    Algorithm & Learner Memory & Production & Interpretation & Hyperparameters \\
    \midrule
    KNN & Samples (S) & KNN-based & KNN-based & $k$ \\
    PE & Prototypes (P) & \DisDes & Nearest & $\alpha$ \\
    AP & P + S & \DisDes & Nearest & / \\
    CWP & P + Counts & \DisDes & Nearest & $\alpha$ \\
    \bottomrule
  \end{tabular}
\end{table}
\end{document} 

enter image description here

0

If I understand you correctly, it's simpler just to markup the two-line cells as a single cell rather than try to make the rest of the table span two rows.

enter image description here

\documentclass{article}

\usepackage{booktabs}

\begin{document}

\newcommand\m[1]{%
\renewcommand\arraystretch{1}%
\begin{tabular}{@{}l@{}}#1\end{tabular}}
\begin{table}
\centering
\renewcommand\arraystretch{1.1}
\footnotesize
\begin{tabular}{lllll}
\toprule
Algorithm & Learner Memory & Production & Interpretation & Hyperparameters\\
\midrule
KNN & Samples (S) & KNN-based & KNN-based & $k$\\
PE  & Prototypes (P) & Discriminative & \m{Nearest\\Descriptive} & $\alpha$\\
AP  & P + S          & Discriminative & \m{Nearest\\Descriptive} & /       \\
CWP & P + Counts     & Discriminative & \m{Nearest\\Descriptive} & $\alpha$\\
\bottomrule
\end{tabular}
\end{table}

\end{document}

You must log in to answer this question.

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