1

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}

2 Answers 2

3

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}

\begin{tabular}{>{\therowcnt\quad}LL<{\stepcounter{rowcnt}}}
  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} 

enter image description here

4
  • 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]{} Nov 15, 2015 at 20:42
  • You can obtain this result, but will have to insert a \num command in each cell.
    – Bernard
    Nov 15, 2015 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? Nov 15, 2015 at 21:11
  • Could you post a minimal (non-)working example?
    – Bernard
    Nov 15, 2015 at 21:15
1

Here's an option using the pgfplotstable package:

screenshot

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

\begin{document}

\pgfplotstabletypeset[
    every head row/.style={output empty row},
    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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .