# How to make a command take effect on all elements in a row of a table?

I am thinking about something similar to \rowfont of tabu package or \rowcolor of xcolor, but to work in the tabular standard environment.

I have no idea if it is a reasonable wish, like in the case of columns, or not. I think at the moment nothing similar has been implemented.

• What is the command that you would like to affect a single row? Jun 12 '20 at 20:44
• Any declaration, like the preamble syntaxs >{<declarations>} accepts. For example: \large, \bfseries, \color{color}, \centering, and so on. Jun 12 '20 at 21:16

\rowfont and \rowcolor (which comes from colortbl not xcolor) use the same mechanism which is shown here, you can hide some of the syntax but that is just syntactic sugar.

\documentclass{article}

\usepackage{array}

\begin{document}

\let\zz\relax
\begin{tabular}{>{\zz}c | >{\zz}l |  >{\zz}c}
aaa & bbb & ccc\\
\noalign{\global\let\zz\bfseries}
aaa & bbb & ccc\\
\noalign{\global\let\zz\relax}
aaa & bbb & ccc\\
\noalign{\global\let\zz\Large}
aaa & bbb & ccc\\
\noalign{\global\let\zz\relax}
aaa & bbb & ccc\\
\end{tabular}
\end{document}

• Alright. I usually use \rowcolor via \usepackage[table]{xcolor} Jun 12 '20 at 21:27
• @e_moro doesn't really matter, but since I wrote \rowcolor and didn't write xcolor I thought I'd mention it:-) Jun 12 '20 at 21:29
• My answer exactly, except I call it \rowhook. Jun 12 '20 at 22:11
• @DonaldArseneau but if I call it \zz then 30 years later people will recognise it's me not some other package:-) Jun 12 '20 at 22:16
• Should I use \zzrowhook to avoid future legal problems? :) Jun 13 '20 at 9:37

Just a little makeup on the David's answer. I attempt to keep the classical array-like syntax. However, I can't avoid using a new columntype. A second limitation is \rowstyle only manage one macro as input. Any suggestion?

\documentclass{article}

\let\zz\relax
\newcommand\rowstyle[1]{\noalign{\global\let\zz #1}}
\def\mytabnewline{\global\let\zz\relax\tabularnewline}
\newcolumntype{z}{>{\zz\let\\\mytabnewline}c}

\begin{document}

\begin{tabular}{zzz}
aaa & bbb & ccc\\
\rowstyle{\bfseries}
aaa & bbb & ccc\\
\rowstyle{\Large}
aaa & bbb & ccc \\
\end{tabular}

\end{document}

• you can use \newcommand\rowstyle[1]{\noalign{\gdef\zz{#1}}} to allow more than one token, for inserting the > a new column type is certainly easiest, you could look how colortbl injects its command (\CT@row@color ) into the table preamble but doing the same is tricky as you have to hack the same place and may need to do it differently depending if colortbl is not loaded or is loaded before or after your code Jun 13 '20 at 10:46
• @DavidCarlisle, a 'Misplaced \noalign' error is thrown if you use \newcommand with an optional argument. This seems to be a limitation of the trick, isn't it? Jun 26 '20 at 15:12
• Not sure why you call it a trick but yes anyway the standard latex optional argument test isn't expandable, you could move the \noalign to before the test, or simpler, use xparse package declareexpandabledocumentcommand, which is expandable. Jun 26 '20 at 15:15
• @DavidCarlisle, sorry. I meant to say the idea, the technique. On the other hand, I don't understand where I should move \noalign... outside of \newcommand? It has no sense for me... Jun 26 '20 at 16:14