0

I would like to color the text containing in the table row but with different colors in each row. How can I do this? Below, I show my minimum code.

\documentclass[12pt, article]{memoir}
% Packages
\usepackage[T1]{fontenc}
\usepackage[brazilian]{babel}
\usepackage{geometry}
     \geometry{a4paper, hdivide = {30mm, 160mm, 20mm}, vdivide = {30mm, 247mm, 20mm}}
\usepackage{xltabular}
\usepackage{multirow}
\usepackage{bigstrut}
\usepackage{booktabs}
\usepackage{graphicx}
     \graphicspath{{../imagens/}}
\usepackage[table]{xcolor}

% First row in table one \def\mil{\rotatebox{90}{Millions}} \def\hth{\rotatebox{90}{Hundred thousands}} \def\tth{\rotatebox{90}{Ten thousands}} \def\tho{\rotatebox{90}{Thousands}} \def\hun{\rotatebox{90}{Hundreds}} \def\one{\rotatebox{90}{Ones}} \def\pnt{\rotatebox{90}{and}} \def\ten{\rotatebox{90}{Tenths}} \def\hus{\rotatebox{90}{Hundredths}} \def\ths{\rotatebox{90}{Thousandths}} \def\tts{\rotatebox{90}{Ten thousandths}} \def\hts{\rotatebox{90}{Hundred thousandths}} \def\mls{\rotatebox{90}{Millionths}} \def\tms{\rotatebox{90}{Ten millionths}} \def\hms{\rotatebox{90}{Hundred millionths}}

\begin{document} \begin{xltabular}{\linewidth}{ccccccccccccccccccccc} \toprule \mil & \hth & \tth & \tho & \hun & \one & \pnt & \ten & \hus & \ths & \tts & \hts & \mls & \tms & \hms &&&&& \ \midrule\rowcolor{blue} & & & & 3 & 6 & . & 5 & 7 & & & & & & & & & & & \ \midrule%\rowstyle{\color{green}} \multicolumn{15}{c}{thirty-six and fifty-seven hundredths.}\ \midrule & & & & & 4 & . & 6 & 0 & 3 & & & & & & & & & & \ \midrule \multicolumn{15}{c}{four and six hundred three thousandths}\ \midrule & & & 1 & 2 & 4 & . & 1 & 2 & 3 & & & & & & & & & & \ \midrule \multicolumn{16}{c}{One hundred twenty four and one hundred twenty three thousandths}\ \midrule & & & & 1 & 2 & . & 0 & 0 & 3 & 2 & 1 & 4 & & & & & & & \ \midrule \multicolumn{15}{c}{Twelve three thousand two hundred fourteen millionths.}\ \midrule & & & & & 0 & . & 3 & 2 & 6 & 3 & & & & & & & & & \ \midrule \multicolumn{15}{c}{text}\ \bottomrule\ \end{xltabular}

  \end{document}

lucenalex
  • 317
  • 1
    Please be aware that using xltabular without any X type column will not necessarily result in the expecred output. If your table is narrower than the available width, this will lead to horizontal lines continuing to the left margin and an output that looks like the last column was overly wide. You might want to adjust that. – leandriis Apr 17 '21 at 07:45
  • 1
    Do you really need xltabular for this particular table? As it currently is, it should fit onto a single page quite easily. Will you add more rows later? Also, you declare a total of 21 columns, but actually only seem to use 15 of them. Is that intentional? – leandriis Apr 17 '21 at 07:52
  • 1
    https://tex.stackexchange.com/a/119773/134144 could also work for your table. – leandriis Apr 17 '21 at 07:57
  • @leandris, I desire to used xltabular by pattern. I am controlling the width with a \linewidth, but eventually, in case I want, I can use the X to control the width. – lucenalex Apr 17 '21 at 08:47
  • @leandris, my table grows over time because I will insert other numbers as I wanted to show more and more examples and, therefore, it can increase in size and can then exceed the limits of the page. For that reason, I prefer to use xltabular with my default environment. – lucenalex Apr 17 '21 at 08:54
  • @leandris, I truly appreciate your concern, but your questions are not the focus of my question. The focus of my question is changing the colors of text from row to row, as I can't do this with \rowcolors. \rowcolors change the background color of the table, an effect that is not what I am looking for. – lucenalex Apr 17 '21 at 08:59
  • 1
    Thanks for adding the clarifications regarding the use of xltabular. Please take a closer look at the answer I liked to earlier, especially at the screenshot of the otuput. Doesn't this image show colored text as opposed to a colored background, so exactly what you seem to be interested in? Also, neither this particular answer, to which I linked to earlier, nor any of my previous comments mention the command \rowcolors. – leandriis Apr 17 '21 at 09:05
  • I had already seen this example, but I would like to know if there is a way to achieve the effect I want without having to create an extra macro. Is there a package that has a macro that does this? Increasing my preamble too much is not something I would like to do. – lucenalex Apr 17 '21 at 09:15
  • leandris, in fact, you didn't mention the \rowcolors command, but @Hassen Nigatu, in your answer, suggests using it. As I mentioned in the comments to that response, this is not the effect I would like to achieve. Hence, why I mention it now here in the comments of the question. – lucenalex Apr 17 '21 at 09:20

1 Answers1

1

Try this

\usepackage[table]{xcolor}

% Table code { \rowcolors{2}{green!25}{green!75} \begin{tabular}{ccc} \hline \rowcolor{gray}Header & Header & Header \ 1 & 2 & 3 \ 4 & \cellcolor{gray}5 & 6 \ 7 & 8 & 9 \ \hline \end{tabular} }

Jae H
  • 81
  • Sorry @Hassen Nigatu, thanks for the attempt, but that is not what I want. I desire to color only the text contained in the table rows, but that, for each row, the text has a different color from the previous row. For example, I would like that the text in the first row was in blue, that the text in the second row was red, the text in the third row was green, and so on. Besides, I also wish that this is done in the xltabularx environment. – lucenalex Apr 17 '21 at 04:29
  • 1
    Try this \begin{table}[] \begin{tabular}{lllll} \hline `\multicolumn{1}{|l|}{{\color[HTML]{FE0000} gree}} & \multicolumn{1}{l|}{{\color[HTML]{3166FF} red}} & \multicolumn{1}{l|}{\cellcolor[HTML]{6665CD}} & \multicolumn{1}{l|}{\cellcolor[HTML]{6665CD}} & \multicolumn{1}{l|}{\cellcolor[HTML]{6665CD}} \ \hline \rowcolor[HTML]{FFCC67} {\color[HTML]{FE0000} gree} & & & &

    \end{tabular} \end{table}`

    – Jae H Apr 17 '21 at 16:11