Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In attempting to apply an alternate table row coloring (using xcolor) in a longtable, one confronts, sooner or later, problems in compiling a PDF. In xcolor's documentation it is clearly stated, under Known Issues, that \rowcolors[\hline]... does not work with longtable.

Within tex.SE, various solutions address the issue of alternate row coloring of normal tables, i.e. How to create alternating rows in a table? A nice way for auto-alternate row-coloring every table is posted at Coloring every alternate table row (see Addendum in the end of the post).

However, there is no direct question & answer referring to the combined use of xcolor's \rowcolors command & longtable. Moreover, searching the web for work-arounds, at least one solution, involves the use of longtable and colortbl.

Is there a way to use, within LyX, the \rowcolors (set of) command(s) provided by xcolor within longtable?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Adapting the solution given in the Addendum of the post Coloring every alternate table row worked just fine! It was as simple as substituting tabular with longtable.

A working example

In LyX' Preamble, watch out for the % alternate rowcolors for all long-tables part of the code:

\usepackage[table]{xcolor}

% define lightgray
\definecolor{lightgray}{gray}{0.9}

% alternate rowcolors for all tables
\let\oldtabular\tabular
\let\endoldtabular\endtabular
\renewenvironment{tabular}{\rowcolors{2}{white}{lightgray}\oldtabular}{\endoldtabular}

% alternate rowcolors for all long-tables
\let\oldlongtable\longtable
\let\endoldlongtable\endlongtable
\renewenvironment{longtable}{\rowcolors{2}{white}{lightgray}\oldlongtable} {
\endoldlongtable}

% Tables

% scale tables
\usepackage{graphicx}

% rulers for tabs
\usepackage{booktabs}

In the main body construct a longtable using LyX' own longtable capacity:

Right click within a row of a table > More... > Settings > Longtable (tab) > Activate Use long table.

Example screenshots

An alt-rowcolored longtable with (reputation-aly ranked) tex.se user-names

Avoiding (grey-)coloring of the longtable-footer, can be done by explicitly instructing \rowcolor{white} or using multiple \cellcolor{white} commands in the respective row (well, the first one of the table).

An alt-rowcolored longtable with (reputation-aly ranked) tex.se user-names, white footers

share|improve this answer
    
Also, both the \show- and \hiderowcolors commands work perfectly as showed in tex.stackexchange.com/q/61127/8272 –  Nikos Alexandris Jun 30 '12 at 11:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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