0

see part i: text is overwritten when using multirow

now I want to align the header of the columns ("Abs." and "Rel."):

\begin{tabular}{rrr}
\rowcolor{COLORROW} \rot{textA} & \multicolumn{2}{c}{%
  \begin{tabular}[b]{@{}cc@{}}
     \rowcolor{COLORROW} \multicolumn{2}{c}{\footnotesize text2} \\
     \rowcolor{COLORROW} \footnotesize Abs. & \footnotesize Rel.
     %\rowcolor{COLORROW} \multicolumn{1}{r}{\footnotesize Abs.} & \footnotesize Rel.
  \end{tabular}}
\\

\footnotesize{ 1} & \footnotesize{  5} & \footnotesize{ 1.00\%} \\
\footnotesize{ 2} & \footnotesize{ 10} & \footnotesize{10.03\%} \\
\footnotesize{ 3} & \footnotesize{  2} & \footnotesize{ 5.00\%} \\
\footnotesize{ 4} & \footnotesize{100} & \footnotesize{ 3.50\%} \\

\end{tabular}

but the alignment doesnt work, also tried a multicolumn-formatting (see %\rowcolor ...)

enter image description here

  • btw: sorry mico for using \footnotesize{...} again ;) – Robert Apr 11 '17 at 19:01
  • 1
    You have a tabular inside a multicolumn. The columns of this tabular have nothing in common with the columns of the main tabular. BTW, for best results, put \footnotesize INSIDE braces. – John Kormylo Apr 11 '17 at 19:12
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Martin Schröder Apr 11 '17 at 19:22
  • colorrow, documentclass etc. is defined in part i, see first line – Robert Apr 11 '17 at 19:30
  • 1
    @Robert - Please post standalone, i.e., fully compilable code chunks. Asking people to navigate back and forth between web pages just to figure out background information is a sure-fire way to annoy and discourage them. – Mico Apr 11 '17 at 19:31
2

I suggest this layout, using the S column type from siunitx, if this is what you want (not sure):

\documentclass{article} 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{rotating}
\newcommand\rot[1]{\rotatebox{90}{\footnotesize#1}} %
\usepackage[svgnames, table]{xcolor}
\colorlet{COLORROW}{Gainsboro!70}
\usepackage{siunitx, booktabs}

    \begin{document}

{\footnotesize%
\begin{tabular}{rS[table-format=2.0]S[table-format=2.2]}
\rowcolor{COLORROW}
     & \multicolumn{2}{c}{text2\rule{0pt}{4ex}} \\
     \rowcolor{COLORROW} \rot{\rlap{textA}} & {Abs.} &{Rel.\,(\%)} \\
\addlinespace[1ex]
1 & 5 & 1.00 \\
2 & 10 & 10.03 \\
3 & 2 & 5.00 \\
4 & 100 & 3.50 \\
\end{tabular}}%

\end{document}

enter image description here

| improve this answer | |
  • @bernhard, tnx - interesting answer, maybe i can adapt "table-format" to make it right aligned (see first figure above) – Robert Apr 11 '17 at 20:03
  • 1
    With the S column type, numbers are aligned by their decimal dot (or comma). The non-numeric cells (such as the column head) have to be between brackets and are centred. I was not too sure of what you want, so I did it the standard way. Did you actually want the column heads right aligned? – Bernard Apr 11 '17 at 20:14
2

Here is a slight variation on Bernard's solution. I use struts to reserve enough space for the rotated text.

\documentclass{scrbook}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{multirow}
\usepackage{colortbl}
\usepackage[english]{babel}
\usepackage{biblatex}
\usepackage{pdfpages}
\definecolor{COLORROW}{HTML}{BEBEBE}

\usepackage{rotating}
\newcommand\rot[1]{\rotatebox{90}{\footnotesize#1}}

\begin{document}

\bgroup
\sbox0{\rot{textA}}% measure size
\def\mystrut{\rule{0pt}{0.5\ht0}\rule[-0.5\dp0]{0pt}{0pt}}% note: local to group
\footnotesize
\begin{tabular}{rrr}
\rowcolor{COLORROW} \mystrut & \multicolumn{2}{c}{text2} \\
\rowcolor{COLORROW} \mystrut \smash{\usebox0} & \multicolumn{1}{c}{Abs.} & \multicolumn{1}{c}{Rel.} \\
1 & 5 & 1.00\% \\
2 & 10 & 10.03\% \\
3 & 2 & 5.00\% \\
4 & 100 & 3.50\%
\end{tabular}
\egroup

\end{document}

demo

| improve this answer | |

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.