2

I have to build lots of tables similar to my MWEm only more complex and with many more columns. Manually adjusting the cmidlines and column width etc. is very annoying.

What can I do to automatically build a header like in the red box? It should be configurable with two to eight columns in the second row and draw its own configurable cmidline.

Maybe a command can look like this :

\greathead{Benutzerführung}{Erklärungen, Wizard}{r{3pt}}

enter image description here

I've tried things like a multirow in a mutlicolumn with multicolumns in the second row, but everything I tried messed up the whole table or doesn't even compile.

MWE:

\documentclass[12pt,a4paper,BCOR5mm]{scrbook}

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{ltablex}
\usepackage{rotating}
\usepackage{colortbl}
\usepackage{ragged2e} 
\usepackage{lipsum}

\newcommand\rota[1]{\rotatebox{90}{#1\ }}
\newcommand*\dimension[2]{\multicolumn{#1}{D}{\rota{#2}}}
\newcommand*\charakteristik[1]{\multicolumn{1}{C}{\rota{#1}}}

\keepXColumns

\definecolor{Gray}{gray}{0.9}

\begin{document}
This text has normal textwidth.\\
\lipsum[1]

%\begin{spacing}{0.8}
\newlength{\sepa}
\setlength{\sepa}{3pt}
%\tiny 6 \scriptsize 8 \footnotesize 10 \small 11 \normalsize 12
\newcolumntype{D}{>{\normalsize}c}
\newcolumntype{C}{>{\normalsize}c}

\newcolumntype{W}{>{\columncolor{white}}C}
\newcolumntype{G}{>{\columncolor{Gray}}C}

\begin{tabularx}{\textwidth}{@{} X* {5}{WG}@{}}
\caption{Some Title}\\
\toprule
& \dimension{2}{Benutzerführung} & \dimension{2}{Canvastypen} & \dimension{2}{Custom Canvas} & \dimension{2}{Export} & \dimension{2}{Finanzübersicht} \\

\cmidrule(r{\sepa}){2-3} \cmidrule(l{\sepa}r{\sepa}){4-5} \cmidrule(l{\sepa}r{\sepa}){6-7} \cmidrule(l{\sepa}r{\sepa}){8-9} \cmidrule(l{\sepa}){10-11}

& \charakteristik{Erklärungen} & \charakteristik{Wizard}
& \charakteristik{BMC} & \charakteristik{Weitere}
& \charakteristik{keine} & \charakteristik{austauschbar}
& \charakteristik{kein} & \charakteristik{Grafik}
& \charakteristik{keine} & \charakteristik{Erlöse-Kosten}
\\ \midrule \endhead
% Content
oneoneoneone & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 0 & 1\\
\bottomrule
\end{tabularx}
\end{document}
  • The problem is that you need the bottom rotated text to line up with the individual columns. If you merged the two columns and used a predefined size (e.g. \makebox{3em}{2\hfil 3}) then you could create a rotated header using \parbox and \rule. – John Kormylo Aug 30 '15 at 15:48
1

Here are basic building blocks. Frankly, it's a whole lot easier letting tabularx do all the work.

\documentclass[12pt,a4paper,BCOR5mm]{scrbook}

\usepackage{xcolor}% loaded by colortbl
\usepackage{graphicx}% loaded by rotating

\definecolor{Gray}{gray}{0.9}
\fboxsep=0pt

\begin{document}

How to create a box of a given width (1em) with a colored background.

\mbox{\rlap{\color{lightgray}\rule[-.2\baselineskip]{1em}{\baselineskip}}\makebox[1em]{2}}

How to line up horizontal and rotated vertical text.

\fbox{\makebox[2em]{2\hfill 3}}

\fbox{\rotatebox{90}{\parbox[c][2em][s]{1in}{\centering top line
\linebreak\vspace{-\baselineskip}\vfill bottom line}}}

\end{document}

building blocks

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.