Make first row of table all bold

Taking apan's comment and turning it into an example:

\documentclass{article}
\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces
}

\begin{document}
\begin{tabular}{$l^c^r}
\rowstyle{\bfseries}
a & a & a \\
b & b & b \\
c & c & c \\
\end{tabular}
\end{document}

This gives:

enter image description here

You might, of course, choose different markers for the column types.


To explain what is going on, the first 'column' is of type $ (could be any symbol not required in the preamble). This simply sets \currentrowstyle to do nothing, which means that in each row this command will be a no-op unless something else happens. The first real column (here l) will contain the command to make it bold (if required), but that is not true for the other columns. They therefore are preceded by ^, which is another fake column type used to apply \currentrowstyle.

In a normal row, \currentrowstyle therefore starts off as \relax and never changes, so the ^ do nothing and the row is unchanged. However, if the first column sets \rowstyle, this is saved as \currentrowstyle (for the later columns) and applied (for this column). The ^ then insert this at the start of each column in the row, so everything is bold.

(All of the operations are global as table cells form groups.)


This is one of the cases where I find the ConTeXt interface to be much better than LaTeX. To make the first row of a table bold, you just need

\setupTABLE[row][1][style=bold]

and not change anything in the table body. So, there is a clear separation of style and presentation. Minimal example:

\setupTABLE[row][1][style=bold]

\starttext
\startTABLE
  \NC A \NC B \NC C \NC \NR
  \NC A \NC B \NC C \NC \NR
  \NC A \NC B \NC C \NC \NR
\stopTABLE
\stoptext

For multi-page tables, besides lockstep's solution (from UK-FAQ), you can also use \rowfont command in longtabu environment from tabu package.

\documentclass{article}
\usepackage{longtable}
\usepackage{tabu}

\begin{document}

Some text.

\vspace{42\baselineskip}

\begin{longtabu}{lcr}
\rowfont{\bfseries}
a & a & a \\
b & b & b \\
c & c & c \\
\end{longtabu}

\end{document}