4

First: I've split up my question(s) from Cleaning up code and here is one of the bullets, with the code somewhat reduced.

Consider

\DocumentMetadata{} \documentclass[ a4paper, 12pt ]{article} \usepackage[ hmargin = 2.3cm, vmargin = 3cm ]{geometry} \usepackage{multirow,array} \def\mlr{1} \newcommand*\saenk[1]{\raisebox{\fpeval{-5/9*\mlr}ex}{#1}} \begin{document} \begin{center} \begin{tabular}{ |p{5cm}| >{\centering\arraybackslash}p{5cm}| >{\centering\arraybackslash}p{5cm}| } \hline \multicolumn{1}{|c|}{\multirow{2}{*}{\raisebox{\fpeval{-1.5*\mlr}ex}{Du kender \dots}}} & \multicolumn{2}{ c|}{\saenk{Du kan beregne \dots}} \\[\mlr ex] \cline{2-3} & \saenk{sider} & \saenk{vinkler} \\[\mlr ex] \hline A & B & C \\ \hline \end{tabular} \end{center} \end{document} 

Question

How do I color the cell background of the header of the table, i.e., the cells with the text Du kender \dots, Du kan beregne \dots, sider and vinkler? That is (probably), how can I use colortbl with this code?

5
  • 2
    This question can be simplified further, now for example I could not run the code because I don't have texgyrepagella installed and I had to change the fonts, however the font is probably not relevant for the question so all the fontspec things can be removed to make it easier to reproduce. The same goes for all math, PSTricks drawings, etc. Commented Sep 30, 2024 at 13:19
  • 2
    Furthermore it was not fully clear to me what you mean with "color the header of the table", if you mean text color or cell background color. Assuming cell background color I tried the colortbl package, which is the standard way of coloring table cells/rows/columns - you have most likely also encountered this package when doing research for your question. However, when just loading the package (and not using any of its commands yet) I got a Misplaced \omit error. So I guess the question essentially is "how can I use colortbl with this code?" Maybe you can edit to reflect this. Commented Sep 30, 2024 at 13:24
  • @Marijn Thanks for the heads-up; I've edited my question. Commented Sep 30, 2024 at 14:16
  • 1
    Can you accept to use tabularray? Commented Sep 30, 2024 at 15:21
  • @Stephen Easily. :-) However, I would like to be able to achieve all three bullets in the referenced question at the top of the question. Commented Sep 30, 2024 at 15:45

2 Answers 2

6

With tabularray:

\documentclass[a4paper,12pt]{article} \usepackage[ hmargin = 2.3cm, vmargin = 3cm,showframe ]{geometry} \usepackage{xcolor} \usepackage{tabularray} \begin{document} \noindent \begin{tblr}{colspec={|Q[5cm]|Q[c,5cm]|Q[c,5cm]|}, rowspec={|Q[cyan6]|Q[cyan6]|Q|}} \SetCell[r=2]{c} Du kender \dots & \SetCell[c=2]{c} Du kan beregne \dots & \\ & sider & vinkler \\ A & B & C \\ \end{tblr} \end{document} 

enter image description here

0
2

With {NiceTabular} of nicematrix.

\documentclass[a4paper,12pt]{article} \usepackage[ hmargin = 2.3cm, vmargin = 3cm,showframe ]{geometry} \usepackage{xcolor,ninecolors} \usepackage{nicematrix} \begin{document} \noindent \renewcommand{\arraystretch}{1.2}% \begin{NiceTabular}{w{l}{5cm}w{c}{5cm}w{c}{5cm}}[hvlines] \CodeBefore \rowcolor{cyan6}{1,2} \Body \Block[c]{2-1}{Du kender \dots} & \Block{1-2}{Du kan beregne \dots} \\ & sider & vinkler \\ A & B & C \\ \end{NiceTabular} \end{document} 

Output of the above code

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.