### Tags: arevertically, build, double, entries, holds, pairsa1, placed, programming, row, rowcolors, table, tex, xcolor

# table with double entries using \rowcolors from xcolor

On Programmer » Tex

6,716 words with 4 Comments; publish: Wed, 07 May 2008 02:26:00 GMT; (20062.50, « »)

I want to build a table where each row holds double entries (pairs

[a1,a2]; [b1,b2]; etc.) that are

vertically placed, like this:

| a1 | b1 | c1 |

| a2 | b2 | c2 |

|--|

| d1 | e1 | f1 |

| d2 | e2 | f2 |

|--|

| g1 | h1 | i1 |

| g2 | h2 | i2 |

--

I could split an entry on two different rows in order to obtain such a

table:

\hline

a1 & b1 & c1 \\

a2 & b2 & c2 \\

..

but this is not convenient because I want to keep handling pairs and

not just one element of a pair.

I could also use the \multirow command but this is awkward too since

all entries are multirows.

Besides, I want my tables to have gray background on every other row.

But if I use the \rowcolors command from the xcolor package I

absolutely need to have each double entry placed in one single row.

Help please.

*http://tex-program.todaysummary.com/q_tex_136799.html*

All Comments

Leave a comment...

- 4 Comments
- >>>>> jlr_0.tex-program.todaysummary.com.yahoo.com (j) wrote:
>j> I want to build a table where each row holds double entries (pairs

>j> [a1,a2]; [b1,b2]; etc.) that are

>j> vertically placed, like this:

>j> --

>j> | a1 | b1 | c1 |

>j> | a2 | b2 | c2 |

>j> |--|

>j> | d1 | e1 | f1 |

>j> | d2 | e2 | f2 |

>j> |--|

>j> | g1 | h1 | i1 |

>j> | g2 | h2 | i2 |

>j> --

>j> I could split an entry on two different rows in order to obtain such a

>j> table:

>j> \hline

>j> a1 & b1 & c1 \\

>j> a2 & b2 & c2 \\

>j> ...

>j> but this is not convenient because I want to keep handling pairs and

>j> not just one element of a pair.

>j> I could also use the \multirow command but this is awkward too since

>j> all entries are multirows.

>j> Besides, I want my tables to have gray background on every other row.

>j> But if I use the \rowcolors command from the xcolor package I

>j> absolutely need to have each double entry placed in one single row.

\newcommand\D[1]{\begin{tabular}{.tex-program.todaysummary.com.{}c.tex-program.todaysummary.com.{}

}#1\end{tabular}}

\begin{tabular}{|c|c|c|}

\hline

\D{a1\\a2} & \D{b1\\b2} & \D{c1\\c2}\\

\hline

\D{d1\\d2} & \D{e1\\e2} & \D{f1\\f2}\\

\hline

\end{tabular}

Unfortunately \rowcolor doesn't propagate properly into the inner tabulars

(the topleft cell of each double row gets black). Probably David Carlisle

knows how to repair this.

--

Piet van Oostrum <piet.tex-program.todaysummary.com.cs.uu.nl>

URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]

Private email: piet.tex-program.todaysummary.com.vanoostrum.org

#1; Wed, 07 May 2008 02:27:00 GMT

- >>>>> jlr_0.tex-program.todaysummary.com.yahoo.com (j) wrote:
- jlr_0.tex-program.todaysummary.com.yahoo.com wrote:
> I want to build a table where each row holds double entries (pairs

> [a1,a2]; [b1,b2]; etc.) that are

> vertically placed, like this:

> --

> | a1 | b1 | c1 |

> | a2 | b2 | c2 |

> |--|

> | d1 | e1 | f1 |

> | d2 | e2 | f2 |

> |--|

> | g1 | h1 | i1 |

> | g2 | h2 | i2 |

> --

> [...]

> Besides, I want my tables to have gray background on every other row.

> But if I use the \rowcolors command from the xcolor package I

> absolutely need to have each double entry placed in one single row.

What about this?

\documentclass{article}

\usepackage{amsmath}

\usepackage{array}

\usepackage{colortbl}

% LaTeX style

% normal

%\newcommand*\V[2]{\ensuremath{\genfrac{

}{}{0pt}{}{\strut#1}{\strut#2}}}

% force display style

\newcommand*\V[2]{\ensuremath{\genfrac{}

{}{0pt}{0}{\strut#1}{\strut#2}}}

% TeX style

% normal

%\def\V(#1,#2){\ensuremath{\genfrac{}{}{

0pt}{}{\strut#1}{\strut#2}}}

% force display style

%\def\V(#1,#2){\ensuremath{\genfrac{}{}{

0pt}{0}{\strut#1}{\strut#2}}}

\begin{document}

% LaTeX style

\begin{tabular}{|c|c|c|}

\hline

\V{a_1}{a_2} & \V{b_1}{b_2} & \V{c_1}{c_2} \\\hline

\rowcolor[gray]{0.85}

\V{d_1}{d_2} & \V{e_1}{e_2} & \V{f_1}{f_2} \\\hline

\V{g_1}{g_2} & \V{h_1}{h_2} & \V{i_1}{i_2} \\\hline

\rowcolor[gray]{0.85}

an & other & line \\\hline

\end{tabular}

% TeX style

%\begin{tabular}{|c|c|c|}

% \hline

% \V(a_1,a_2) & \V(b_1,b_2) & \V(c_1,c_2) \\\hline

% \rowcolor[gray]{0.85}

% \V(d_1,d_2) & \V(e_1,e_2) & \V(f_1,f_2) \\\hline

% \V(g_1,g_2) & \V(h_1,h_2) & \V(i_1,i_2) \\\hline

% \rowcolor[gray]{0.85}

% an & other & line \\\hline

%\end{tabular}

\end{document}

#2; Wed, 07 May 2008 02:28:00 GMT

- jlr_0.tex-program.todaysummary.com.yahoo.com wrote:
- >>>>> On Wed, 04 Jan 2006, at 12:54:39 , Piet van Oostrum wrote:
PvO> \newcommand\D[1]{\begin{tabular}{.tex-program.todaysummary.com.{}c.tex-program.todaysummary.com.{}

}#1\end{tabular}}

PvO> \begin{tabular}{|c|c|c|}

PvO> \hline

PvO> \D{a1\\a2} & \D{b1\\b2} & \D{c1\\c2}\\

PvO> \hline

PvO> \D{d1\\d2} & \D{e1\\e2} & \D{f1\\f2}\\

PvO> \hline

PvO> \end{tabular}

That's exactly the solution I tried first. And I think this is the

most elegant

one. Except for the fact that it does not work with \rowcolor

(colortbl) nor

with \rowcolors (xcolor).

PvO> Unfortunately \rowcolor doesn't propagate properly into the

inner

PvO> tabulars (the topleft cell of each double row gets black).

Probably David

PvO> Carlisle knows how to repair this.

I think I'll drop David Carlisle a note.

Thanks for your help.

--=20

ren=E9

#3; Wed, 07 May 2008 02:29:00 GMT

- >>>>> On Wed, 04 Jan 2006, at 12:54:39 , Piet van Oostrum wrote:
- Jean-C=F4me Charpentier wrote:
> What about this?

> \documentclass{article}

> \usepackage{amsmath}

> \usepackage{array}

> \usepackage{colortbl}

> \newcommand*\V[2]{\ensuremath{\genfrac{}

{}{0pt}{0}{\strut#1}{\strut#2}}}

Thanks for this suggestion. This works but doesn't quite meet my

needs though as my table entries cannot be used in math mode.

The best idea would still remain the inclusion of tabulars I guess.

ren=E9

#4; Wed, 07 May 2008 02:30:00 GMT

- Jean-C=F4me Charpentier wrote: