TeX - LaTeX Asked on January 14, 2021
I am trying to make the table with automatically centered, rotated multirow cells. Something like in the picture, but with cells automatically fitted to their content:
I tried to apply solutions given by @AboAmmar and @Seong, but these not ensure vertical centering within the specified number of rows. This answer is unclear, because multirow
command under makecell
package accepts non-integer value of number of rows (?). Here is given some code, but the problem is that this engages fixed value (in raisebox
argument) which is proper only for one specific cell content. The most similar question is without answer.
In fact I need some function which should be named multirowrothead
– as a combination of multirowthead
and rothead
functions of the makecell
package.
My code:
documentclass[table]{standalone}
usepackage{siunitx}
usepackage{makecell}
usepackage{xcolor}
usepackage{multirow}
usepackage{hhline}
renewcommand{theadfont}{normalsizebfseries}
renewcommand{arraystretch}{1.3}
begin{document}
begin{tabular}{
|l|
S[table-format=2.1]|
S[table-format=1.2]|
S[table-format=2.1]|
S[table-format=1.2]|
S[table-format=2.1]|
S[table-format=1.2]|
}
hline
% https://tex.stackexchange.com/questions/246889/how-to-color-column-heads-determined-width-makecell
rowcolor{gray}
multicolumn{3}{|c|}{colorbox{gray}{thead{First title in heading}}} &
multicolumn{2}{c|}{colorbox{gray}{thead{Second titlein heading}}} & &
hhline{>{arrayrulecolor{black}}|-----|>{arrayrulecolor{gray}}-%
>{arrayrulecolor{black}}|>{arrayrulecolor{gray}}->{arrayrulecolor{black}}|%
}
rowcolor{gray}
& & & & colorbox{gray}{thead{datadescription}} &
{multirowthead{-2}{Datadescription}} &
hhline{%
>{arrayrulecolor{black}}|>{arrayrulecolor{gray}}-%
>{arrayrulecolor{black}}|>{arrayrulecolor{gray}}-%
>{arrayrulecolor{black}}|>{arrayrulecolor{gray}}-%
>{arrayrulecolor{black}}|>{arrayrulecolor{gray}}-%
>{arrayrulecolor{black}}|-|-|%
>{arrayrulecolor{gray}}->{arrayrulecolor{black}}|%
}
rowcolor{gray}
colorbox{gray}{multirowthead{-2}{side-headingdescription}} &
colorbox{gray}{multirowthead{-2}{datadescription}} &
colorbox{gray}{multirowthead{-2}{datadescription}} &
colorbox{gray}{multirowthead{-2}{datadescription}} &
colorbox{gray}{thead{A}} & colorbox{gray}{thead{B}} &
colorbox{gray}{multirowthead{-3}{Data description}}
hline
Description 1 & 63.5 & 4.87 & 63.5 & 4.87 & 63.5 & 4.87
hline
Description 2 & 88.4 & 5.13 & 88.4 & 5.13 & 88.4 & 5.13
hline
end{tabular}
end{document}
You can't have the quantity b
in green on your picture smaller because the (total) height of the rows 2 and 3 is constrained by the contents of the cells of the column 5.
Here is what you can do with {NiceTabular}
of nicematrix
.
documentclass[table]{article}
usepackage{siunitx}
usepackage{makecell}
renewcommand{arraystretch}{1.3}
usepackage{nicematrix}
begin{document}
begin{NiceTabular}[ hvlines , code-before = rowcolor{gray!30}{1-3} ]
{
c
S[table-format=2.1]
S[table-format=1.2]
S[table-format=2.1]
S[table-format=1.2]
S[table-format=2.1]
S[table-format=1.2]
}%
{Block{1-3}{First title in heading}} & & &
multicolumn{2}{c}{makecell{Second titlein heading}} &
{Block{2-1}<rotate>{Datadescription}} &
{Block{3-1}<rotate>{Data description}}
{Block{2-1}<rotate>{side-headingdescription}}
& {Block{2-1}<rotate>{datadescription}}
& {Block{2-1}<rotate>{datadescription}}
& {Block{2-1}<rotate>{datadescription}}
& rotate makecell{datadescription}hspace*{0.5em}
& & & & {A} & {B}
Description 1 & 63.5 & 4.87 & 63.5 & 4.87 & 63.5 & 4.87
Description 2 & 88.4 & 5.13 & 88.4 & 5.13 & 88.4 & 5.13
end{NiceTabular}
end{document}
In {NiceTabular}
, you merge cells both vertically and horizontally with the built-in command Block
(however, the command Block
does not create space).
With the key hvlines
, you draw all the rules excepted in the blocks (which is what is expected here).
The built-in command rotate
is used to rotate contents of cells and blocks.
You can color cells, rows and columns with commands in the key code-before
(however, it's also possible to use a syntax similar to the syntax of colortbl
). Usually, the output is good in all PDF viewers at all levels of zoom.
However, you need several compilations.
Correct answer by F. Pantigny on January 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP