1

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.

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

\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.

enter image description here

\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}
6
  • Alright. I usually use \rowcolor via \usepackage[table]{xcolor}
    – e_moro
    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? :)
    – e_moro
    Jun 13 '20 at 9:37
1

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}
6
  • 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?
    – e_moro
    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...
    – e_moro
    Jun 26 '20 at 16:14
  • \newcommand\foo{\noalign\bgroup\foox} \newcommand\foox[1][zzz]{something with #1\egroup} Jun 26 '20 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.