2

I have made the following table:

\begin{center}
    \begin{tabular}{| c | c | c |}
    \hline
    \cellcolor{blue!25}$M_{\delta}$ & \cellcolor{blue!25}$t_{go}^{s}$ [sec] & \cellcolor{blue!25}\text{Miss Distance [m]} \\ \hline
     -100 & 0.5274 &  1.40153 \\ \hline
     -150 & 0.4664 &  1.03992 \\ \hline
     -200 & 0.4360 &  0.85460 \\ \hline
     -250 & 0.4216 &  0.74391 \\ \hline
     -300 & 0.4172 &  0.67290 \\ \hline
     -350 & 0.4179 &  0.62575 \\ \hline
     -400 & 0.4190 &  0.59338 \\ \hline
     -450 & 0.4183 &  0.56994 \\ \hline
     -500 & 0.4161 &  0.55187 \\ \hline
  \end{tabular}
\end{center}

However, when I run the code the table looks as following: enter image description here

I noticed that when I compile the borders sometimes appear and sometimes not.

Is there a way that I can make sure all the borders appear?

Thank you

2
  • 2
    This might be a viewer issue. Do the lines show up if you magnify the output in your viewer? Related: Colored tabular - line not showing
    – leandriis
    Jun 30, 2018 at 13:53
  • 3
    Anyway, since all cells of the first row have the same colour, you should use the shorter syntax: \rowcolor{blue!25} $M_{\delta}$ &$t_{go}^{s}$ [sec] & \text{Miss Distance [m]}
    – Bernard
    Jun 30, 2018 at 13:59

2 Answers 2

2

this is "extended" comment. consider Bernard comment, adding some small changes in column type and array stretching, your table looks like:

enter image description here

above image is generated by

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{array} 

\begin{document}
\begin{center}
\renewcommand\arraystretch{1.5}             % <---
    \begin{tabular}{| >{$}c<{$} | c | c |}  % <---
    \hline
    \rowcolor{blue!25}
    M_{\delta}    & $t_{go}^{s}$ [sec] & Miss Distance [m]    \\ \hline
     -100 & 0.5274  &  1.40153 \\ \hline
     -150 & 0.4664  &  1.03992 \\ \hline
     -200 & 0.4360  &  0.85460 \\ \hline
     -250 & 0.4216  &  0.74391 \\ \hline
     -300 & 0.4172  &  0.67290 \\ \hline
     -350 & 0.4179  &  0.62575 \\ \hline
     -400 & 0.4190  &  0.59338 \\ \hline
     -450 & 0.4183  &  0.56994 \\ \hline
     -500 & 0.4161  &  0.55187 \\ \hline
  \end{tabular}
\end{center}
\end{document}
1
  • @Ben, any news?
    – Zarko
    Jul 30, 2018 at 18:05
0

The package nicematrix has tools designed to address that kind of problem. In the following code, I have loaded nicematrix (and unloaded colortbl) and replaced the environment {tabular} with the environment {NiceTabular} with the key color-inside (alias colortbl-like) which means that there will be color instructions within the tabular.

You have directly the expected output. The rules won't seem to vanish, whatever PDF viewer you use.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{center}
  \begin{NiceTabular}{| >{$}c<{$} | c | c |}[color-inside] 
    \hline
    \rowcolor{blue!25}
    M_{\delta}    & $t_{go}^{s}$ [sec] & Miss Distance [m]    \\ \hline
     -100 & 0.5274  &  1.40153 \\ \hline
     -150 & 0.4664  &  1.03992 \\ \hline
     -200 & 0.4360  &  0.85460 \\ \hline
     -250 & 0.4216  &  0.74391 \\ \hline
     -300 & 0.4172  &  0.67290 \\ \hline
     -350 & 0.4179  &  0.62575 \\ \hline
     -400 & 0.4190  &  0.59338 \\ \hline
     -450 & 0.4183  &  0.56994 \\ \hline
     -500 & 0.4161  &  0.55187 \\ \hline
  \end{NiceTabular}
\end{center}

\end{document}

You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood).

Output of the above code

Moreover, {NiceTabular} has a key hvlines to draw all the rules in the tabular. Hence, you have the same output with the following code:

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{center}
  \begin{NiceTabular}{>{$}c<{$} c c }[color-inside,hvlines]     
    \rowcolor{blue!25}
    M_{\delta}    & $t_{go}^{s}$ [sec] & Miss Distance [m]    \\ 
     -100 & 0.5274  &  1.40153 \\ 
     -150 & 0.4664  &  1.03992 \\ 
     -200 & 0.4360  &  0.85460 \\ 
     -250 & 0.4216  &  0.74391 \\ 
     -300 & 0.4172  &  0.67290 \\ 
     -350 & 0.4179  &  0.62575 \\ 
     -400 & 0.4190  &  0.59338 \\ 
     -450 & 0.4183  &  0.56994 \\ 
     -500 & 0.4161  &  0.55187 \\ 
  \end{NiceTabular}
\end{center}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .