0

I managed to insert a row with custom font series and font color.

\documentclass{article}
\usepackage{tabu}
\usepackage{xcolor}
\begin{document}
  \begin{tabu}{ l | l l l l }
  \rowfont{\leavevmode\color{red}\bfseries}
    A   & 1 & 2 & 3 & 4 \\ 
    \hline 
    1   & A & B & C & D \\ 
    2   & A & B & C & D \\ 
    3   & A & B & C & D \\ 
    4   & A & B & C & D \\ 
  \end{tabu}
\end{document}

enter image description here

How can I additionally change the background colour of the row e.g. to black? I experimented with \rowcolor but it returns an error. Perhaps this can be achieved with tabulx?

Stücke
  • 305
  • 1
    do not use the tabu package. It is broken and unmaintained (see the readme here https://github.com/tabu-issues-for-future-maintainer/tabu). Use colortbl, tabularray or nicematrix. – Ulrike Fischer Jun 07 '23 at 07:51
  • Thank you for your comment! Perhaps my question can be answered using tabularx? – Stücke Jun 07 '23 at 08:12
  • If you want to extensively use colors in your tables, you should probably have a look at the nicematrix or tabularray packages. If you only need a few cells colord, colortbl might already be enough. You might want to look at the other solutions provided here https://tex.stackexchange.com/q/26360/47927 (where your code example probably also originates from). – Jasper Habicht Jun 07 '23 at 08:20

2 Answers2

1

You can try tabularray.

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\begin{document}
\begin{tblr}
{
colspec  = {*{5}{Q[c,m]}},
hline{2} = {},
vline{2} = {},
row{1}   = {cmd=\bfseries,bg=black,fg=red},
}
A & 1 & 2 & 3 & 4 \\
1 & A & B & C & D \\
2 & A & B & C & D \\
3 & A & B & C & D \\
4 & A & B & C & D \\
\end{tblr}
\end{document}

enter image description here

Clara
  • 6,012
1

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{c|cccc} \RowStyle[rowcolor=black,color=red,bold]{} A & 1 & 2 & 3 & 4 \ 1 & A & B & C & D \ 2 & A & B & C & D \ 3 & A & B & C & D \ 4 & A & B & C & D \ \end{NiceTabular}

\end{document}

Output of the above code

F. Pantigny
  • 40,250