[Tex/LaTex] How to set text color and font type of header row for all tables in LaTeX

colorcolortbletoolboxrowcolortables

I have a document with plenty of tables and I would like to apply the same formatting of the header row for all of them, without making manual modifications for each tabular.

I now use \AtBeginEnvironment and \rowcolors from the etoolbox package based on Bernard's solution for setting the background color in the preamble, but have not found anything similar for the font type and text color.

My current code is the following:

\documentclass{article}
\usepackage[table, svgnames]{xcolor} %\usepackage{array}
\usepackage{cellspace}
\usepackage{etoolbox}
\colorlet{headercolour}{DarkSeaGreen}
\colorlet{textcolour}{white}

\AtBeginEnvironment{tabular}{\rowcolors{1}{\ifnumless{\rownum}{2}{headercolour}{white}}{}}

\begin{document}

\begin{table}
  \centering
  \begin{tabular}{|*{4}{Sc}|}
    \hline
    \textbf{\color{white}Column1} & \textbf{\color{white}Column2} & \textbf{\color{white}Column3} & \textbf{\color{white}Column4} \\%%set formatting manually for each table
    \hline
    A & B & D & E \\
    \hline
        & & & F \\
    \hline
        & & & \\
    \hline
  \end{tabular}
\caption{Table 1}
\end{table}

\begin{table}
    \centering
    \begin{tabular}{|c|c|c|}
        \hline
        Header1 & Header2 & Header3\\
        cell1 & cell2 & cell3\\
        \hline

    \end{tabular}
\caption{Table2}
\end{table}
\end{document} 

With the first table formatted as wanted. That is the style I would like to set for each table automatically.

Any ideas how to do that?
Thanks!

Best Answer

This is something where ConTeXt really shines. Observe how the actual table content contains zero visual markup

\setupTABLE
  [row][first]
  [background=color,
   backgroundcolor=darkgreen,
   color=white,
   style=bold,
   framecolor=black]

\starttext

\startplacetable[title={Table 1}]
  \startTABLE
    \NC Column1 \NC Column2 \NC Column3 \NC Column4 \NC\NR
    \NC A       \NC B       \NC D       \NC E       \NC\NR
    \NC         \NC         \NC         \NC F       \NC\NR
  \stopTABLE
\stopplacetable

\startplacetable[title={Table 2}]
  \startTABLE
    \NC Header1 \NC Header2 \NC Header3 \NC\NR
    \NC cell1   \NC cell2   \NC cell3   \NC\NR
  \stopTABLE
\stopplacetable

\stoptext

enter image description here

Related Question