17

Is there a way to color text in an entire table without using environment tabular? For example, change the color of text in every cell to red.

cerebrou
  • 801

3 Answers3

20

Just use

{\color{red}\begin{tabular}{cc}
a&b\\
1&2
\end{tabular}}

and the table will be red.

David Carlisle
  • 757,742
15

Do you thing on something like this:

enter image description here

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

    \begin{document}
\begin{tabular}{>{\color{red}}c >{\color{red}}c}
    \hline
A   &   B   \\
C   &   D   \\
    \hline
\end{tabular}
    \end{document}

If you wish in red (or other selected color) entire table (with lines), than before table just put command \color{red}

Zarko
  • 296,517
2

Previous posts work for coloring individual columns or whole table contexts in latex. But while using this code for any latex template of a journal you have to write the package \usepackage[table]{xcolor} just next to the \documentclass{standalone}, otherwise, the code will not work. for e.g.

\documentclass[review]{elsarticle}
\usepackage[table]{xcolor}
\usepackage{amssymb,amsmath}
\usepackage{url}

Again for coloring individual texts of a table, you can use

\begin{tabular}{l l }

    \toprule
    1   &   \textcolor{blue}{Water}  \\
    2   &   Hippo grass  \\

    \bottomrule
\end{tabular}
Leucippus
  • 1,636
  • 1
    But the question is about not have to set the color in every cell ... With respect to xcolor package, sometimes is not needed, because it is already loaded by the document class or another package, and in this case you do not need the [table] option . Also, although sometimes the order of the packages matter, usually it must be simply in any place of preamble, no just under the \documentclass line. – Fran Nov 01 '19 at 07:39
  • How can I color a whole row with many elements? – skan Feb 25 '20 at 00:42