# Make first row of table all bold

I'm trying to do something that I thought would be relatively simple but seems to be quite hard. I have a table with a number of columns, and I'd like to make all of the titles appear in bold text. Obviously I can add \textbf to each of them in turn, but it strikes me that there must be a nicer way of doing this (particularly for tables with many columns).

As far as I can see there isn't a good way of doing this with plain LaTeX. Are there any packages that make this (and possibly other table-related issues) easier?

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:

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.) • I think I can explain how this works: $ is defined to "reset" the comment \currentrowstyle which is defined in \rowstyle. the rowstly command also sets the style for the column is currently is in (that's what the second #1 is for). The ^ simply puts \currentstyle in the beginning of the cell, so that if it is \relax, nothing happens, but if there are a \rowstyle command, the row gets styled. notice that a corollary of this is that if you put a \rowstly command in the middle of the row, you affect that column and the following ones. Exercise: what is the effect of {$lc^c$cc}? Nov 2, 2010 at 11:05
• @YossiFarjoun I've edited in an explanation. Feb 2, 2013 at 7:53
• I think $ isn't a particularly good choice of token, since many editors treat this as beginning a math region and the syntax highlighting is messed up. I'd used ^ and |. Oct 29, 2014 at 7:16 • @kynan I'm just using the symbols chosen by the author of the FAQ page linked to in a comment on the question: I didn't pick this particular set of symbols. Oct 29, 2014 at 7:18 • @macmadness86 The standard LaTeX tabular construct puts an \ingorespaces at the start of the cell: it's therefore expected in most peoples input. In the example in the above I don't need a % after the \rowcolor line due to the space skipping: if it was absent I'd need to worry about the line end. Nov 2, 2016 at 9:20 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  • No-one ever said LaTeX was perfect :-) I keep meaning to have a serious go at tables (for LaTeX3), but have not yet had the time just yet. Nov 2, 2010 at 20:10 • @Joseph: I'm looking forward to your table-package! Dec 6, 2010 at 22:20 • @lockstep: Don't hold your breath - I have the output routine to think about yet :-) Dec 7, 2010 at 6:34 • @JosephWright: I hope you'll call it "carpenter" (as in "table-wright") Feb 22, 2012 at 9:02 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}  • @lockstep: it's heavily bugged. See here, for example Jul 2, 2011 at 17:46 • @egreg: There're some bugs in tabu, but it is still usable. Another bug I know is that tabu cannot used together with tabularx and arydshln. (It isn't very important since tabu provides its own dash line syntax.) Jul 2, 2011 at 17:56 • @Leo: well, just don't use p columns or add manually a final \strut to each p cell. Jul 2, 2011 at 18:10 • @egreg: I agree that the bug pointed out by you is a showstopper. Jul 2, 2011 at 18:29 • Just to let you know that the original question of this answer got merged with this question now. Jul 6, 2011 at 8:31 For tables spanning several pages, simply combine array (as in Joseph Wright's answer) and longtable. \documentclass{article} \usepackage{array} \newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
\usepackage{longtable}

\begin{document}

Some text.

\vspace{42\baselineskip}

\begin{longtable}{$l^c^r} \rowstyle{\bfseries} a & a & a \\ b & b & b \\ c & c & c \\ \end{longtable} \end{document}  • I like this implementation. Do you know of a way to create a new tabular environment that automatically places the$ and ^ before the column declaration? Dec 5, 2020 at 16:33

It is easy with tabularray package to set row fonts. And you can change the environment from tblr to longtblr to get a long table.

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
width = 0.5\textwidth, colspec = {X[1]X[2]X[3]}, hlines,
row{1} = {font=\bfseries}, rowhead = 1,
}
a & b & c \\
1 & 2 & 3 \\
1 & 2 & 3 \\
1 & 2 & 3 \\
\end{tblr}
\end{document}


In {NiceTabular} of nicematrix, you have a built-in command \RowStyle to specify formatting commands to the (end of the) current row. So, it's possible to use \RowStyle{\bfseries}. However, the command \RowStyle has also a key bold which has the avantage to bold both text mode and math mode.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}
\begin{NiceTabular}{lcr}
\RowStyle[bold]{}
a & a & a \\
b & b & b \\
c & c & c \\
\end{NiceTabular}
\end{document}