Como preencher uma caixa tabular com um nó tikz e centralizar o texto?

Como preencher uma caixa tabular com um nó tikz e centralizar o texto?

Como preencher uma caixa tabular com um nó tikz e centralizar h/v o texto?

Não quero usar o pacote colortbl neste caso.

insira a descrição da imagem aqui

\documentclass[a4paper]{article}

\usepackage{array,tabularx,tikz,ragged2e,siunitx}
\begin{document}

{\renewcommand\tabularxcolumn[1]{m{#1}}
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{%
    |X|*{3}{>{\Centering}m{2cm}|}}\hline
Entourer la ou les bonne(s) reponse(s)
&\tikz[baseline,overlay]
    \node[fill=blue!15,minimum height=20pt,minimum width=2cm+2\tabcolsep] (A) {a};
&b&p\\\hline
\end{tabularx}}

\end{document}

Responder1

Não tenho certeza se entendi sua pergunta, mas se você deseja alinhar a verticalmente com b e c, considere

\documentclass[a4paper]{article}

\usepackage{array,tabularx,tikz,ragged2e,siunitx}
\begin{document}

{\renewcommand\tabularxcolumn[1]{m{#1}}
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{%
    |X|*{3}{>{\Centering}m{2cm}|}}\hline
Entourer la ou les bonne(s) reponse(s)
&\tikz[baseline=(A.base),overlay]
    \node[fill=blue!15,minimum height=20pt,minimum width=2cm+2\tabcolsep] (A) {a};
&b&p\\\hline
\end{tabularx}}

\end{document}

insira a descrição da imagem aqui

ATUALIZAR: OK, vejo que @Zarko já te deu o que você queria. Por diversão, segui um pouco sua abordagem original e foi aí que cheguei:

\documentclass[a4paper]{article}

\usepackage{array,tabularx,tikz,ragged2e,siunitx}
\usetikzlibrary{calc}
\newcommand{\TikzStrut}[1]{\tikz[overlay,remember picture]{\node(#1){\strut};}}
\makeatletter
\newcommand{\RowHeight}{% see e.g. https://tex.stackexchange.com/a/84536/121799
\def\tmp{\dimexpr\arraystretch\ht\strutbox+\arraystretch\ht\strutbox+\arraystretch\dp\@arstrutbox}\relax
\xdef\myrowheight{\the\tmp}\relax
}
\makeatother
\begin{document}

{\renewcommand\tabularxcolumn[1]{m{#1}}
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{%
    |X|*{3}{>{\Centering}m{2cm}|}}\hline
Entourer la ou les bonne(s) reponse(s)\RowHeight
&\tikz[baseline=(A.base),overlay,remember picture]{
    \node[fill=blue!15,minimum height=\myrowheight,minimum width=2cm+2\tabcolsep] (A) 
    {a};}
&b&p\\\hline
\end{tabularx}}

\end{document}

insira a descrição da imagem aqui

Ele calcula a altura da linha corretamente (eu acho), mas somente depois de usar o fato de que há uma linha com duas linhas. E também o alinhamento vertical não é perfeito. Estou apenas postando isso para que possa ser concluído, se necessário, mais tarde.

Responder2

eu suspeito que você está procurando por isso:

insira a descrição da imagem aqui

para isso você não precisa de mágica com tikz:

\documentclass[a4paper]{article}
\usepackage{array,tabularx}%reorganized loading of package
\renewcommand\tabularxcolumn[1]{m{#1}} % added
\usepackage{ragged2e}
%\usepackage{tikz}      % is not used in mwe
%\usepackage{siunitx}   % is not used in mwe
%
\usepackage[table]{xcolor}% new package, for coloring table

\begin{document}
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{|X|*{3}{>{\Centering}m{2cm}|}}
    \hline
Entourer la ou les bonne(s) reponse(s)
    & \cellcolor{blue!15}{a} & b & p    \\
    \hline
\end{tabularx}
\end{document}

adendo (editado): da discussão nos comentários abaixo *e do seu acompanhamento pergunta*concluo que você realmente gosta de tersolução semelhante ao primeiro exemplo da minha resposta, conforme forneço nessa pergunta (acompanhamento):

insira a descrição da imagem aqui

*que permite alterações adicionais no formato do nó, conforme mencionado no comentário abaixo e mais detalhado em sua pergunta de acompanhamento:

\documentclass[12pt]{article}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\usepackage{ragged2e}
\usepackage{tikz}

\newcommand{\DC}[1]{%
\begin{tikzpicture}[baseline=(current bounding box.base)]
    \node[minimum width=\dimexpr2cm+2\tabcolsep,
          minimum height=12mm, text depth=0.25ex,
          inner ysep=2mm, outer sep=0pt,
          append after command={
             \pgfextra{\let\LN\tikzlastnode
          \path[fill=blue!15]
            (\LN.south west) -| (\LN.north east) -| cycle;
                      }     },
          font=\bfseries] {#1};
\end{tikzpicture}}

\begin{document}
    \begingroup
\renewcommand{\arraystretch}{1.3}
\begin{tabularx}{\linewidth}{%
    |>{\raggedright}X | *{3}{@{}>{\Centering}m{\dimexpr2cm+2\tabcolsep}@{}|}
                            }
    \hline
Entourer la ou les bonne(s) reponse(s)
    & \DC{a}   &    b   &   c    \\
    \hline
\end{tabularx}
    \endgroup
\end{document}

informação relacionada