4

I've already found solutions here that work over \rowfont{} but not automatically adjust by even and odd number of lines.

I think about a case function it would work well for the first lines and then for the next. Unfortunately I don't understand the syntax and possibilities in LaTeX. Could someone please give me a solution for the problem

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\usepackage[table]{xcolor}
\makeatletter
\g@addto@macro{\endtabular}{\rowfont{}}% Clear row font
\makeatother
\newcommand{\rowfonttype}{}% Current row font
\newcommand{\rowfont}{% Set current row font
    \gdef\rowfonttype{\color{white}}%
}
\newcolumntype{L}{>{\rowfonttype}l}

\rowcolors{1}{blue}{orange}

\begin{document}
    \begin{tabular}{LL}               
        \rowfont
        \textbf{Hello}& \textbf{World} \\
        \textcolor{Black}{Foo} & \textcolor{Black}{Bar} \\ 
        Hello & World
    \end{tabular}
\end{document}
2

I think you can achieve your needs easily with a TikZ matrix.

The options every odd row and every even row allow you to set a style for even and odd rows without complicated code.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
   \begin{tikzpicture}
   \matrix [
        matrix of nodes, 
        nodes in empty cells,
        column sep=-\pgflinewidth,% if you don't want a visible separation between columns
        column 1/.style={
            nodes={text width=3em},%put the width you prefer here
            },
        column 2/.style={
            nodes={text width=4em},%put the width you prefer here
            },
        every odd row/.style={
            nodes={fill=blue, text=white},
            },
        every even row/.style={
            nodes={fill=orange},
            },
        every node/.style={
            font=\bfseries,  
            text height=1.75ex,
            text depth=.25ex,
            align=left
            },
        ] {
        Hello & World \\
        Foo & Bar \\ 
        Hello & World\\
        };
    \end{tikzpicture}
\end{document}

enter image description here

  • TikZ allows us to do a lot of crazy things - thank you for share every odd/even row!! – manooooh Jan 27 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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