# Apply italic formatting to every other row

How can I make every second row in the following table in italics?

\documentclass{article}
\usepackage{array}

\begin{document}

\begin{tabular}{ll}
45.1 &22.3\\
15000.9999 & 23568.44485\\
45.1 &22.3\\
15000.9999 & 23568.44485\\
45.1 &22.3\\
15000.9999 & 23568.44485\\
45.1 &22.3\\
15000.9999 & 23568.44485\\
\end{tabular}
\end{document}


Here is a solution, with etoolbox and array: I create a rowcnt counter initialise it at the beginning of the tabular environment and reset it at the end. A \altshape command is executed at the beginning of each cell, the result of which depends on the parity of rowcnt:

\documentclass{article}
\usepackage{array}
\usepackage{xcolor, etoolbox, dcounter}
\newcounter{rowcnt}
\newcommand\altshape{\ifnumodd{\value{rowcnt}}{\color{red}}{\itshape}}
\newcolumntype{L}{ >{\altshape}l}

\AtBeginEnvironment{tabular}{\setcounter{rowcnt}{1}}
\AtEndEnvironment{tabular}{\setcounter{rowcnt}{0}}

\begin{document}

45.1 & 22.3 \\
15000.9999 & 23568.44485 \\
45.1 & 22.3 \\
15000.9999 & 23568.44485 \\
45.1 & 22.3 \\
15000.9999 & 23568.44485 \\
45.1 & 22.3 \\
15000.9999 & 23568.44485
\end{tabular}

\end{document}


• Can I surround the \itshape command with the following code in order to round the numbers to the nearest integer? I can't get it to work. \num[round-precision=0,group-separator={,},round-mode=places]{} – user2146441 Nov 15 '15 at 20:42
• You can obtain this result, but will have to insert a \num command in each cell. – Bernard Nov 15 '15 at 21:08
• Thanks. The example above isn't working when I load it into a larger document with more \usepackage commands. I'm getting a Package array Error: <{..} at wrong position. Any idea what might be causing this? – user2146441 Nov 15 '15 at 21:11
• Could you post a minimal (non-)working example? – Bernard Nov 15 '15 at 21:15

Here's an option using the pgfplotstable package:

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{article}
\usepackage{pgfplotstable}

\begin{document}

\pgfplotstabletypeset[
postproc cell content/.code={
\ifodd\pgfplotstablerow\relax
\pgfkeysalso{@cell content={\itshape#1}}%
\fi
},
]{45.1 22.3
15000.9999  23568.44485
45.1 22.3
15000.9999  23568.44485
45.1 22.3
15000.9999  23568.44485
45.1 22.3
15000.9999  23568.44485
}
\end{document}


I used Pgfplotstable and multirow as a starting point.

• I can't seem to replace the raw data with a call to \input to import some data from a csv file. . . – user2146441 Nov 15 '15 at 20:02