表格中的垂直删除线太长

表格中的垂直删除线太长

所以我昨天刚开始使用 LateX,遇到了一个问题。我正在制作一个表格,其中一个数字被圈出,整行被划掉。我在网上找到了不同的代码,并尝试将它们应用到表格中。以下是代码:

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath,amssymb,amsthm, amsfonts}
\usepackage{tikz-inet}
\usepackage{graphicx}
\usetikzlibrary{matrix}
\usepackage{tikz}

画圆命令:

\usetikzlibrary{fit,shapes.geometric}

\newcounter{nodemarkers}
\newcommand\circletext[1]{%
    \tikz[overlay,remember picture] 
        \node (marker-\arabic{nodemarkers}-a) at (0,1.5ex) {};%
    #1%
    \tikz[overlay,remember picture]
        \node (marker-\arabic{nodemarkers}-b) at (0,0){};%
    \tikz[overlay,remember picture,inner sep=2pt]
        \node[draw,ellipse,fit=(marker-\arabic{nodemarkers}-a.center) 
        (marker-\arabic{nodemarkers}-b.center)] {};%
    \stepcounter{nodemarkers}%
}

在表中绘制线条的命令:

\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline] 
\node [anchor=base] (#1) {$#2$};}

\newcommand{\DrawVLine}[3][]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[shorten <=0.3ex, #1] (#2.north) -- (#3.south);
  \end{tikzpicture}
}

\newcommand{\DrawHLine}[3][]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[shorten <=0.2em, #1] (#2.west) -- (#3.east);
  \end{tikzpicture}
}

桌子:

\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.3}
  \begin{tabular}{c|cccc}
   \multicolumn {1}{c|}{} & 60 & 110 & 80 & 110 \\ \hline

    80 & \tikzmark{topA}{3}   & \tikzmark{topB}{10}   & 
    \tikzmark{topC}{20} & \tikzmark{topD}{ \circletext{0} }  \\  

    20 & 2 & 1 & 3 &        \tikzmark{rightB}{0}     \\ 
    50 & 2,5 & 3,5 & 4 &    \tikzmark{rightC}{0}    \\ 
    210 & 4 & 5 & 9 &       \tikzmark{rightD}{0}        \\ 
    \DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}
  \end{tabular}
  \end{center}
\end{document}

表格如下所示

正如您所见,垂直线太长了。

谁能告诉我代码哪里出错了?

如果我尝试删除

\DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}

它看上去不错。

答案1

有了这个,你得到正确的线条

\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.3}
  \begin{tabular}{c|cccc}
   \multicolumn {1}{c|}{} & 60 & 110 & 80 & 110 \\ \hline

    80 & \tikzmark{topA}{3}   & \tikzmark{topB}{10}   &
    \tikzmark{topC}{20} & \tikzmark{topD}{ \circletext{0} }  \\

    20 & 2 & 1 & 3 &        \tikzmark{rightB}{0}     \\
    50 & 2,5 & 3,5 & 4 &    \tikzmark{rightC}{0}    \\
    210 & 4 & 5 & 9 &       \tikzmark{rightD}{0}          %% remove \\ here
  \end{tabular}
  \DrawVLine[blue, thick, opacity=0.8]{topD}{rightD}      %% move this after \end{tabular}
  \end{center}
\end{document}

在此处输入图片描述

\\最后一行的 引入了额外的行,并且在环境\DrawVLine之外有其自然的位置tabular

相关内容