2

I have a huge table I am editing with LyX

I tried to use rowcolors to have alternate row colors but it does not work

This looks like to depend on the use of \tabularnewline instead of \\

The header column contain multiple lines text (formatted as p) so I guess that \tabularnewline must be used

How can I obtain alternate row colors with minimum effort?

Sample

    %% LyX 2.1.4 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[table]{xcolor} 
\usepackage[a4paper]{geometry}
\geometry{verbose,lmargin=1cm,rmargin=1cm,headheight=1cm,headsep=1cm}
\setlength{\parindent}{0bp}
\definecolor{lightgray}{gray}{0.9}
%\usepackage{color}
\usepackage{array}
\usepackage{setspace}
\usepackage{esint}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\renewcommand{\arraystretch}{0.9}%
\setlength{\tabcolsep}{.07667em}


\makeatother

\usepackage{babel}
\begin{document}



\begin{spacing}{0.7}
\noindent \begin{flushleft}
\rowcolors{0}{lightgray}{white}
\begin{tabular*}{2cm}{@{\extracolsep{\fill}}>{\raggedright}m{28mm}|>{\centering}m{14mm}|>{\centering}m{16mm}|>{\centering}m{1.6cm}|>{\centering}m{1.8cm}|>{\centering}m{2cm}|>{\centering}m{1.8cm}|>{\centering}m{1.8cm}|}
\cline{2-8} 
 & {\footnotesize{}1} & {\footnotesize{}2} & {\footnotesize{}3} & {\footnotesize{}4} & {\footnotesize{}5} & {\footnotesize{}6} & {\footnotesize{}7}\tabularnewline
\cline{2-8} 
{\footnotesize{}Aaaaaaaaa aaaaaa aaaa } & {\footnotesize{}n/y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y}\tabularnewline
\cline{2-8} 
{\footnotesize{}Bbbbbb bbbbb bbbbb} & {\footnotesize{}n/y} & {\footnotesize{}n/y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y}\tabularnewline
\cline{2-8} 
\end{tabular*}
\par\end{flushleft}
\end{spacing}

\end{document}

pdflatex output

The following works:

    %% LyX 2.1.4 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[table]{xcolor} 
\usepackage[a4paper]{geometry}
\geometry{verbose,lmargin=1cm,rmargin=1cm,headheight=1cm,headsep=1cm}
\setlength{\parindent}{0bp}
\definecolor{lightgray}{gray}{0.9}
%\usepackage{color}
\usepackage{array}
\usepackage{setspace}
\usepackage{esint}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\renewcommand{\arraystretch}{0.9}%
\setlength{\tabcolsep}{.07667em}


\makeatother

\usepackage{babel}
\begin{document}



\begin{spacing}{0.7}
\noindent \begin{flushleft}
\rowcolors{0}{lightgray}{white}
\begin{tabular}{@{\extracolsep{\fill}}>{\raggedright}m{28mm}|>{\centering}m{14mm}|>{\centering}m{16mm}|>{\centering}m{1.6cm}|>{\centering}m{1.8cm}|>{\centering}m{2cm}|>{\centering}m{1.8cm}|>{\centering}m{1.8cm}|}
\hline
 & {\footnotesize{}1} & {\footnotesize{}2} & {\footnotesize{}3} & {\footnotesize{}4} & {\footnotesize{}5} & {\footnotesize{}6} & {\footnotesize{}7}\tabularnewline
\hline
{\footnotesize{}Aaaaaaaaa aaaaaa aaaa } & {\footnotesize{}n/y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y}\tabularnewline
\hline
{\footnotesize{}Bbbbbb bbbbb bbbbb} & {\footnotesize{}n/y} & {\footnotesize{}n/y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y} & {\footnotesize{}y}\tabularnewline
\hline
\end{tabular}
\par\end{flushleft}
\end{spacing}

\end{document}

closed as off-topic by Moriambar, TeXnician, Stefan Pinnow, Zarko, CarLaTeX Jun 9 '17 at 12:24

  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \tabularnewline is just defined by \let\tabularnewline\\ so it should work the same way as \\ If you have an example where it doesn't make a small example document that shows the problem and add it to your question. – David Carlisle Nov 23 '15 at 11:51
  • apparently the issue is with cline. but hline was not working with tabular* – Dimitri Ognibene Nov 23 '15 at 12:10
  • as documented in the colortbl package documentation, \cline is not compatible with cell colouring. – David Carlisle Nov 23 '15 at 13:00
  • thanks, I needed \cline because lyx was using \begin{tabular*}{2cm} that messed up \hline – Dimitri Ognibene Nov 23 '15 at 13:37
  • 4
    I'm voting to close this question as off-topic because it appears to be resolved in comments (issues with \cline and colortbl) – Moriambar Jun 9 '17 at 11:22

Browse other questions tagged or ask your own question.