5

MWE:

\documentclass{standalone}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}

\begin{tabular}{@{}l|llll@{}} \toprule \multicolumn{1}{c|}{\multirow{2}{*}{Test}} & \multicolumn{4}{c}{A} \ \cmidrule(l){2-5} \multicolumn{1}{c|}{} & 1 & 2 & 3 & 4 \ \midrule & & & & \ & & & & \ \bottomrule \end{tabular}

\end{document}

Output:

enter image description here

Saw this, this. Somewhere, I have to use makecell or m, but not able to grasp. Any help in making the "Test" vertically align.

Dr.PB
  • 767

2 Answers2

4

Avoid verticals for a better impact and troubles with gaps

The \multirow option can be changed to decimal values for finer up-down adjustment/centering -- here changed to value of 2.4

enter image description here

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

\begin{document} \begin{table}[] \begin{tabular}{@{}lllll@{}} \toprule
\multirow{2.4}{*}{Test} & \multicolumn{4}{c}{A} \ \cmidrule(l){2-5}
& 1 & 2 & 3 & 4 \ \midrule & X & Y & Z & A \ & P & Q & R & S \ \bottomrule \end{tabular} \end{table}

\end{document}

js bibra
  • 21,280
4

Here is what you can do with {NiceTabular} of nicematrix (with the latest version: 5.4 of 2020-10-06).

\documentclass{article}
\usepackage{booktabs}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{@{}l|llll@{}} \toprule \Block{2-1}{Test} & \Block{1-4}{A} \ \cmidrule(l){2-5} & 1 & 2 & 3 & 4 \ \midrule & & & & \ & & & & \ \bottomrule \end{NiceTabular}

\end{document}

  • In {NiceTabular}, you use \Block to merge cells both vertically and horizontally.

  • The content of the block is composed at the mathemtatical center of the rectangle of the merged cells (not as with \multirow).

  • The vertical rules are not broken and thus, are compatible with booktabs (but you must be aware that the use of vertical rules is not at all in the spirit of booktabs).

  • You need several compilations (because nicematrix uses PGF/Tikz nodes).

Ouput of the above code

F. Pantigny
  • 40,250