# How to arrange table rows in multiline like rowspan but with same color?

I am working on LaTeX and R. My result in table are in one line (comma seprated) and i want them to be in multiline but within same row (like rowspan).

I tried to use newline but that does not seems to be working. I also used row span but color of multiline gets changed (automatic alternate coloring).

In the above figure, I am keeping first line record into multiple line which were comma seprated earlier? How can I implement it in LaTeX. Any working example will help me a lot.

-
Please post some minimal and complete document showing how the table is built at the moment. – Gonzalo Medina Jun 19 '12 at 1:38

There are a number of possible solutions:

1. You can use \rownum to change the color alternancy for particular rows.
2. You can use \multicolumn with an appropriate p{<length>} specification.

The following code shows the same table three times; the leftmost one exhibits the default color alternancy; the middle one uses the \rownum approach, and the rightmost one shows the \multicolumn approach:

\documentclass{article}
\usepackage[table]{xcolor}

\begin{document}

\rowcolors*{1}{blue!60}{blue!20}
\noindent\begin{tabular}{ll}
col1 & col2 \\
text & text \\
text & text \\
text & text \\
\rowcolors*{1}{blue!60}{blue!20}
\begin{tabular}{ll}
col1 & col2 \\
\global\rownum=1
text & text \\
text & text \\
text & text \\
\rowcolors*{1}{blue!60}{blue!20}
\begin{tabular}{ll}
col1 & col2 \\
\multicolumn{1}{p{1cm}}{text text} & \multicolumn{1}{p{1cm}}{text text} \\
text & text \\
\end{tabular}

\end{document}


Having into account the comment, you can use a \parbox of the desired width inside \multicolumn, and define a command to simplify the writting:

\documentclass{article}
\usepackage[table]{xcolor}

\newcommand\boxcolumn[2]{%
\multicolumn{1}{p{#1}}{\parbox[t]{#1}{#2}}}

\begin{document}

\rowcolors*{1}{blue!60}{blue!20}
\noindent\begin{tabular}{ll}
col1 & col2 \\
\boxcolumn{2cm}{text \\ text} & \boxcolumn{3cm}{text \\ text} \\[2.5ex]
text & text \\
\end{tabular}

\end{document}


-
if i increase the width of column in cm they appeat to be in same line.\documentclass{article} \usepackage[table]{xcolor} \begin{document} \rowcolors*{1}{blue!60}{blue!20} \begin{tabular}{ll} col1 & col2 \\multicolumn{1}{p{5cm}}{text text} & \multicolumn{1}{p{5cm}}{text text} \text & text \\end{tabular} \end{document} I want to keep still in next line weather width is more or less. – manish Jun 19 '12 at 6:49
@manish you can use the \rownum approach instead. I added a new option in my edited answer, using a \parbox of the desired width. – Gonzalo Medina Jun 19 '12 at 17:31