Coloring a line of a table

\documentclass{article}
\usepackage{nicematrix}
\NiceMatrixOptions{cell-space-top-limit=5pt,cell-space-bottom-limit=5pt}

\begin{document}
\begin{table}[htbp]
 \centering
    \begin{NiceTabular}{wc{1cm}|wc{4cm}|wc{4cm}|}[hvlines,code-before=\rowcolor{gray}{1}]
        & 1 & 1 \\ 
      1 & 1 & 1 \\ 
      1 & 1 & 1 \\ 
    \end{NiceTabular}
\end{table}
\end{document}

You can acheive the desired result with {NiceTabular} of nicematrix with the following avantages:

  • You won't have the top rule vanishing in the PDF viewers at some level of zoom.

  • You don't have to prefix each column of the preamble with a prefix of cellspace since you have global options cell-space-top-limit and cell-space-bottom-limit doing the job.

  • You can draw all the required rules with only one key hvlines.

Output of the above code


makegepedcellsfrom the makecell package seems to interfere with colored cells. As an alternative, you can use the cellspace package. In the following MWE, I have also replaced your x type column with wc from the array package as well as the repeated \cellcolor commands with a single \rowcolor.

enter image description here

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

\usepackage{array}

\usepackage[column=0]{cellspace}
\setlength{\cellspacetoplimit}{5pt}
\setlength{\cellspacebottomlimit}{\cellspacetoplimit}
\addparagraphcolumntypes{x}

\begin{document}

\begin{table}[htbp]
 \centering
    \begin{tabular}{|0{wc{1cm}}|0{wc{4cm}}|0{wc{4cm}}|}\hline
      \rowcolor{gray} & 1 &  1 \\ \hline
      1 & 1 & 1 \\ \hline
      1 & 1 & 1 \\ \hline
    \end{tabular}
\end{table}
\end{document}