在表格中添加左右对角箭头

在表格中添加左右对角箭头

我有这张表:

\begin{center}
\renewcommand{\arraystretch}{1.5} % aumenta espaço entre linhas
\renewcommand{\tabcolsep}{18 pt}  % aumenta espaço entre colunas
\begin{tabular}{ c | c c | c }
\hline
& \multicolumn{2}{c|}{Y}\\
%\cline{2 - 4} % linha horizontal entre as colunas
% 2 e 4
X & 0 & 1 & Total \\
\hline
0 & $P_{00}$  & $P_{01}$ & $P_{0.}$ \\
1 & $P_{10}$ & $P_{11}$ & $P_{1.}$ \\
\hline
Total & $P_{.0}$ & $P_{.1}$ & 1 \\
\hline
\end{tabular}
\end{center}

在此处输入图片描述

我想像示例图一样在对角线上画左箭头和右箭头(对角线上的左箭头和右箭头从 P_00 到 P_11 和从 P_10 到 P_01)

谢谢

答案1

使用tikzmark包库tikz

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\tikzset{is/.style = {inner xsep=3pt}}

\begin{document}
    \[
    \renewcommand\arraystretch{1.5}
    \setlength\arraycolsep{18pt}
\begin{array}{ c | c c | c }
\hline
& \multicolumn{2}{c|}{Y}\\
X   & 0                             & 1                             & \mathrm{Total}    \\
\hline
0   & \tikzmarknode[is]{a}{P_{00}}  & \tikzmarknode[is]{b}{P_{01}}  & P_{0.} \\
1   & \tikzmarknode[is]{c}{P_{10}}  & \tikzmarknode[is]{d}{P_{11}}  & P_{1.} \\
\hline
\mathrm{Total}
    & P_{.0}                    & P_{.1}                      & 1 \\
\hline
\end{array}
    \]
\begin{tikzpicture}[overlay,remember picture]
  \draw[<->]   (a) -- (d);
  \draw[<->]   (c) -- (b);
\end{tikzpicture}
 
\end{document}

经过至少两次编译你将获得:

在此处输入图片描述

为了缩短表格主体中的代码,我使用array而不是tabularray并将其插入数学环境中。

相关内容