3

I have a table and I want a font color of 5th and 6th row be red. What I'm doing right now is changing the color of each cell in these rows, is there any command which can change font color in a row, not just in one cell?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}  
\usepackage{multirow,tabularx}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage[table]{xcolor}
\usepackage{colortbl,hhline}

\begin{document}

\begin{tabularx}{\textwidth}{ |X|X|X| }
\hline
\textbf{Наименование} & \textbf{BBB} & \textbf{ААА} \\ \hline
Теплопостачання припливних систем & 83 044,00 грн. & 67 000 грн \\ \hline
Монтаж , пусканаладка & 64 000,00 грн. & 74885849 грн \\ \hline
\rowcolor{yellow}
ИТОГО: & 1089158,71 грн. & 100000 \\ \hline
\color{red} Отклонение от минимального предложения, грн & \color{red} 0,00 грн. & \color{red} 34000 \\ \hline
\color{red} Отклонение от минимального предложения, \% & \color{red} 0\% & \color{red} 10 \%  \\ \hline
Срок выполнения работ & 3-4 недели & 2 недели \\ \hline
\end{tabularx}
\vspace{1cm}

\end{document}

enter image description here

Lucky_girl
  • 1,365

3 Answers3

2

With new table package tabularray:

case 1: with horizontal and vertical lines:

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage[russian]{babel}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{hline{1,2,Z}={solid, 0.5pt}, hline{3-Y}={dashed}, vlines, colspec={*{3}{X[l]}}, row{1} ={font=\bfseries} } Наименование & BBB & ААА \ Теплопостачання припливних систем & 83 044,00 грн. & 67 000 грн \ Монтаж , пусканаладка & 64 000,00 грн. & 74 885 849 грн \ \SetRow{yellow} ИТОГО: & 1089158,71 грн. & 100 000 \ \SetRow{fg=red} Отклонение от минимального предложения, грн & 0,00 грн. & 34000 \ \SetRow{fg=red} Отклонение от минимального предложения, % & 0 % & 10 % \ Срок выполнения работ & 3-4 недели & 2 недели \ \end{tblr}

\end{document}

enter image description here

case 2: horizontal lines at top, after column headers and at bottom, and without vertical lines. The table body is the same as before, changed are only table specifications:

\begin{tblr}{hline{1,2,Z}={solid, 0.5pt}, 
             colspec={*{3}{X[l]}},
             row{1} ={font=\bfseries}
             }
% table body, the same as before

enter image description here

Zarko
  • 296,517
1

The following builds on the technique described in An improved \rowstyle that takes the cell contents as an argument, capturing each cell using collcell:

enter image description here

Each cell .. is set using \textcolor{red}{..} depending whether/not the switch \ifrowcolour has been set to \rowcolourtrue or \rowcolourfalse. Since these switches occur inside tabular cells (and therefore groups), they have to be set \globally in order for the change to exist beyond the cell scope.

For visual appeal, I'd suggest using booktabs for you table presentation(s).

Werner
  • 603,163
1

In {NiceTabular}, you have a command \RowStyle to change the style of the end of the current row.

\documentclass{article}
\usepackage[russian]{babel}  
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabularX}{\textwidth}{XXX}[hvlines] \RowStyle{\bfseries} Наименование & BBB & ААА \ Теплопостачання припливних систем & 83 044,00 грн. & 67 000 грн \ Монтаж , пусканаладка & 64 000,00 грн. & 74885849 грн \ \RowStyle[rowcolor=yellow]{} ИТОГО: & 1089158,71 грн. & 100000 \ \RowStyle[nb-rows=2,color=red]{} Отклонение от минимального предложения, грн & 0,00 грн. & 34000 \ Отклонение от минимального предложения, % & 0 % & 10 % \ Срок выполнения работ & 3-4 недели & 2 недели \ \end{NiceTabularX}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

F. Pantigny
  • 40,250