2

I am making table using both nicematrix and makecell packages, because these packages applied together allow to obtain multirow heading cells containing rotated text (as pointed here; if I am not wrong, makecell package alone enables making cells with rotated text, enables merging vertically adjacent cells, but not both for a single cell). I need to highlight table-heading content by setting not only gray background, but also bold font. I have two problems/questions:

  1. The content of \Block is shifted upward from the cell center - letter Ś touches top bounding line of the cell (see picture below); and letter m in the cell with rotated text almost touches the corresponding bounding line of the cell. How to center \Block content automatically?
  2. Does the \Block command enable for application bold footnotesize font for a group of cells, like \renewcommand{\theadfont}{\footnotesize\bfseries} in makecell package?

Code:

\documentclass[table]{standalone}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{nicematrix}
\renewcommand{\arraystretch}{1.3}

\begin{document}
\begin{NiceTabular}[hvlines,code-before=\rowcolor{gray!30}{1-3}]{%
    S[table-format=2.1]
    S[table-format=1.2]
    S[table-format=2.1]
}
\multicolumn{2}{c}{\makecell{Średnia wartość\\czegoś tam}} & 
{\Block{2-1}{\rotate \makecell{Obrócony opis\\kolumny B}}} \\
{\Block{2-1}{\rotate \makecell{straszne dane}}}
& \rotate \makecell{inne dane\\z długim opisem} \\
& {A} & {B} \\
63.5 & 4.87 & 63.5\\
88.4 & 5.13 & 88.4\\
\end{NiceTabular}
\end{document} 

enter image description here

2 Answers 2

3

Your problems are not linked to the command \Block (provided by nicematrix) since the command \Block is not used in both cells with problems (however, using \Block in those cells won't solve the problems since the command \Block does not create space).

In fact, your problems would arise in a standard {tabular} of LaTeX (provided you use explicitely \rotatebox instead of the syntactic variant \rotate provided by nicematrix).


For the first cell (whose content is Średnia wartość czegoś tam), I suggest to use the command \gape provided by makecell since you have used the command \makecell.

That gives : \gape[t]{\makecell{Średnia wartość\\czegoś tam}}.


\documentclass{article}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{nicematrix}
\renewcommand{\arraystretch}{1.3}

\begin{document}

\begin{NiceTabular}[hvlines,code-before=\rowcolor{gray!30}{1-3}]{%
    S[table-format=2.1]
    S[table-format=1.2]
    S[table-format=2.1]
}
\multicolumn{2}{c}{\gape[t]{\makecell{Średnia wartość\\czegoś tam}}} & 
{\Block{2-1}<\rotate>{Obrócony opis\\kolumny B}} \\
{\Block{2-1}<\rotate>{straszne dane}}
&{\Block{}<\rotate>{inne dane\\z długim opisem\;}}\\
& {A} & {B} \\
63.5 & 4.87 & 63.5\\
88.4 & 5.13 & 88.4\\
\end{NiceTabular}
\end{document} 

Output of the above code

3
  • Thank you for explanations. I have one more problem: I tried to put \bfseries into angle brackets after \Block command (I would like to make bold the whole content of the table heading, which is already marked by gray background). But without success. Is the \Block argument in angle brackets dedicated only for mathematical mode? How to set font globally for the whole heading, including cells made with \multicolumn as well as \Block commands?
    – forrest
    Commented Oct 1, 2020 at 5:20
  • As of now, the bracket argument is dedicated for arrays in math mode. Indeed, in {NiceTabular}, there is no need to such argument: you may simply put your command \bfseries in the main argument of \Block: \Block{2-2}{\bfseries My text}. In arrays in math mode, it's not possible to put a command such as \Large in math mode and that's why I've created the options in angular brackets. Commented Oct 1, 2020 at 5:28
  • OK. I don't know, why I didn't find that solution for bold font (before I asked the question): {\Block{2-1}{\bfseries\rotate \makecell{Obrócony opis\\kolumny B}}}. It works.
    – forrest
    Commented Oct 1, 2020 at 8:21
2

For the blocks, the text is already at the center. If you want to shift further, use \hspace to achieve the desired output. For the spacing, you can try adjusting the cell width else reduce the size of the text, so that the text will not touch the cell border. This can be achieved by using \small or \scriptsize. Just use it before the text.

\documentclass[table]{standalone}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{nicematrix}


\begin{document}
\centering
\begin{NiceTabular}[hvlines,code-before=\rowcolor{gray!30}{1-3}]{%
S[table-format=2.1]
S[table-format=1.2]
S[table-format=2.1]
}
\multicolumn{2}{c}{\makecell{\scriptsize{Średnia wartość}\\\scriptsize{czegoś tam}}} & 

{\Block{2-1}{\hspace{-.4cm}\rotate \makecell{Obrócony opis\\kolumny B}}} \\
{\Block{2-1}{\centering\rotate \makecell{straszne dane}}}
& \rotate \makecell{inne dane\\z długim opisem} \\
& {A} & {B} \\
63.5 & 4.87 & 63.5\\
88.4 & 5.13 & 88.4\\
\end{NiceTabular}
\end{document} 

Edited answer after comment:

\documentclass[table]{standalone}
\usepackage{siunitx}
\usepackage{makecell}
\usepackage{nicematrix}


\begin{document}
\centering
\begin{NiceTabular}[hvlines,code-before=\rowcolor{gray!30}{1-3}]{%
S[table-format=2.1]
S[table-format=1.2]
S[table-format=2.1]
}
\multicolumn{2}{c}{\makecell{\scriptsize{\textbf{Średnia wartość}}\\\scriptsize{\textbf{czegoś tam}}}} & 

{\Block{2-1}{\hspace{-.4cm}\rotate \makecell{\small \textbf{Obrócony opis}\\\small\textbf{kolumny B}}}} \\
{\Block{2-1}{\centering\rotate \makecell{\small \textbf{straszne dane}}}}
& \rotate \makecell{\scriptsize \textbf{inne dane}\\\scriptsize \textbf{z długim opisem}} \\
& {A} & {B} \\
63.5 & 4.87 & 63.5\\
88.4 & 5.13 & 88.4\\
\end{NiceTabular}
\end{document} 
2
  • If the rotated text is aligned to the cell center, why the the height of the cell is not sufficient for symmetrical margins? I don't understand why letter "z" is above the horizontal line and word "opisem" almost touches the horizontal line above it. It is not centered. Do you know how to set bold font for the text in all heading cells (filled with gray)?
    – forrest
    Commented Sep 30, 2020 at 12:32
  • See my recent edit.
    – M S
    Commented Sep 30, 2020 at 17:01

You must log in to answer this question.

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