表形式のボックスを tikz ノードで埋めて、テキストを中央揃えにするにはどうすればよいでしょうか?

表形式のボックスを tikz ノードで埋めて、テキストを中央揃えにするにはどうすればよいでしょうか?

表形式のボックスを tikz ノードで埋めて、テキストを中央揃えにするにはどうすればよいでしょうか?

この場合、colortbl パッケージは使用したくありません。

ここに画像の説明を入力してください

\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}

答え1

質問の意味がよく分かりませんが、aをbとcと垂直に揃えたい場合は、

\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}

ここに画像の説明を入力してください

アップデート: わかりました。@Zarko がすでにあなたが求めていたものを提供してくれたようです。楽しみのために、あなたのオリジナルのアプローチを少しだけ踏襲してみたところ、次のようになりました:

\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}

ここに画像の説明を入力してください

行の高さは正しく計算されます (そう思います) が、2 行の行があるという事実を利用した後のみです。また、垂直方向の配置も完璧ではありません。後で必要になった場合に完了できるように、これを投稿しています。

答え2

あなたが探しているのはこれだと思います:

ここに画像の説明を入力してください

これには魔法は必要ありません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}

補遺(編集済み): 以下のコメントでの議論から*そしてあなたのフォローアップから 質問* 私は結論として、あなたは実際に持っているのが好きなのですその(フォローアップの)質問で私が提供した回答の最初の例に似た解決策:

ここに画像の説明を入力してください

*これにより、以下のコメントで述べたようにノードの形状をさらに変更し、フォローアップの質問でさらに詳しく説明できるようになります。

\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}

関連情報