5

I'm having a really weird problem with a table. I have the following code for two different tables. Table 1's code is the following:

\begin{table}[H]
\centering
\begin{tabular}{*3c}\toprule
M\'aximo de horas & $R_{P_A}$ & $R_{P_E}$ \\\midrule\rowcolor[gray]{.95}
35  & 3.33    & 3.33    \\
37  & 3.33    & 3.33    \\\rowcolor[gray]{.95}
39  & 3.33    & 3.33    \\
41  & 3.33    & 3.33    \\\rowcolor[gray]{.95}
43  & 3.33    & 3.33    \\
45  & 3.33    & 3.33   \\\rowcolor[gray]{.95}
\bottomrule
\end{tabular}
\end{table}

And the result is this:

enter image description here

Meanwhile for the second table I have this is the code:

\begin{table}[H]
 \centering
 \begin{tabular}{*3c}\toprule
 M\'aximo de horas & $R_{P_A}$ & $R_{P_E}$ \\\midrule\rowcolor[gray]{.95}
35  & 2.08    & 4.580   \\
37  & 2.58    & 4.08    \\\rowcolor[gray]{.95}
39  & 3.08    & 3.58    \\
41  & 3.58    & 3.08    \\\rowcolor[gray]{.95}
43  & 4.08    & 2.58    \\
45  & 4.58    & 2.08   \\\rowcolor[gray]{.95}
\bottomrule
\end{tabular}
\end{table}

And this is the result:

enter image description here

I'm kind of new to Tex so I don't knwo if this could be caused by any of the packages I'm using, so I'm just going to list all of them right here:

\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{float}
\usepackage{caption}
\usepackage[font={color=red},figurename=Figura]{caption}
\usepackage[font={color=red},tablename=Tabla]{caption}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{enumitem}
\usepackage{listings}
\usepackage{colortbl}
\usepackage[outline]{contour}
\usepackage{bm}
\usepackage{xparse}

Thanks for your time.

  • 2
    Curious. A smaller example that demonstrates this is \documentclass{article} \usepackage[table]{xcolor} \begin{document} \begin{tabular}{c} foo \\ \rowcolor[gray]{.95} \end{tabular} \begin{tabular}{c} bar \end{tabular} \end{document}. By the way, with \usepackage[table, ... ]{xcolor}, you don't need \usepackage{colortbl}. And you don't need to load caption three times either, once is enough. – Torbjørn T. May 6 '18 at 22:09
6

It looks like the last \rowcolor directive of the first table influences the first row of the second one. But you should drop it anyway as it has no effect.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[table,dvipsnames]{xcolor}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{float}
\usepackage{caption}
\usepackage[font={color=red},figurename=Figura]{caption}
\usepackage[font={color=red},tablename=Tabla]{caption}
\usepackage{fancyhdr}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{enumitem}
\usepackage{listings}
\usepackage{colortbl}
\usepackage[outline]{contour}
\usepackage{bm}
\usepackage{xparse}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{*3c}\toprule
M\'aximo de horas & $R_{P_A}$ & $R_{P_E}$ \\\midrule\rowcolor[gray]{.95}
35  & 3.33    & 3.33    \\
37  & 3.33    & 3.33    \\\rowcolor[gray]{.95}
39  & 3.33    & 3.33    \\
41  & 3.33    & 3.33    \\\rowcolor[gray]{.95}
43  & 3.33    & 3.33    \\
45  & 3.33    & 3.33   \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[H]
 \centering
\begin{tabular}{*3c}\toprule
 M\'aximo de horas & $R_{P_A}$ & $R_{P_E}$ \\\midrule\rowcolor[gray]{.95}
35  & 2.08    & 4.580   \\
37  & 2.58    & 4.08    \\\rowcolor[gray]{.95}
39  & 3.08    & 3.58    \\
41  & 3.58    & 3.08    \\\rowcolor[gray]{.95}
43  & 4.08    & 2.58    \\
45  & 4.58    & 2.08   \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

| improve this answer | |
  • yeah I was going to, just didn't let me because of the 6 minutes timeline. – migueldva May 6 '18 at 22:35
  • @migueldva Off-topic: you are loading [utf8]{inputenc} and yet you type M\'aximo. You can go for Máximo directly (actually, if you have an up to date installation, you don't even need [utf8]{inputenc} anymore, because utf8 has become the default). If you use this "ascii accents" a lot, that could increase both the readability of your document and ease your typing. (Just make sure your editor saves your document with utf8 encoding). – gusbrs May 6 '18 at 22:55
  • Hi @gusbrs, I actually had no idea what 'utf8' was for. TexMaker loads the preamble for me automatically, but it's nice to learn something new. On the other hand, I write the accents that way because I am used to writing with an English keyboard.:) – migueldva May 6 '18 at 23:36
  • That, good Sir, was a real time-saver! Thank you! – Wolfone Aug 29 '19 at 9:53
3

mwe

Using \rowcolors (xcolor with table option) only one time in the preamble you obtain what you want with cleaner tables (and without black boxes).

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage[table]{xcolor}
\rowcolors{1}{}{gray!15}
\begin{document}

\begin{table}[h]
\begin{tabular}{*3c}\toprule
Máximo de horas & $R_{P_A}$ & $R_{P_E}$ \\\midrule
35  & 3.33    & 3.33    \\
37  & 3.33    & 3.33    \\
39  & 3.33    & 3.33    \\
41  & 3.33    & 3.33    \\
43  & 3.33    & 3.33    \\
45  & 3.33    & 3.33    \\
\bottomrule
\end{tabular}
\end{table}


\begin{table}[h]
\begin{tabular}{*3c}\toprule
 Máximo de horas & $R_{P_A}$ & $R_{P_E}$ \\\midrule%\rowcolor[gray]{.95}
35  & 2.08    & 4.580   \\
37  & 2.58    & 4.08    \\
39  & 3.08    & 3.58    \\
41  & 3.58    & 3.08    \\
43  & 4.08    & 2.58    \\
45  & 4.58    & 2.08   \\
\bottomrule
\end{tabular}
\end{table}

\end{document}
| improve this answer | |

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.