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.

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).

enter image description here

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).

enter image description here

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.

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

1 Answer 1

up vote 6 down vote accepted

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 \\
\end{tabular}\qquad
\rowcolors*{1}{blue!60}{blue!20}
\begin{tabular}{ll}
col1 & col2 \\
\global\rownum=1
text & text \\
text & text \\
text & text \\
\end{tabular}\qquad
\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}

enter image description here

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}

enter image description here

share|improve this answer
    
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

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.