我尝试在表格中垂直和水平删除线,当水平工作时,大多数方法都有效,因为行高都是相同的,但是,使用下面概述的方法,垂直删除线总是以对角线结束
序言中的相关代码:
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawVLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2.north)$) -- ($(#3.north)$);
\end{tikzpicture}%
}%
\newcommand{\DrawLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2)+(-0.4,0.6ex)$) -- ($(#3)+(0.6,0.6ex)$);
\end{tikzpicture}%
}%
相关数组:
$
\begin{array}{|c|c|c|c|}
\hline
&Dig&\tikzmark{StartB}Weed&Cut\\
\hline
Boris&50&0&50\\
\hline
Percival&20&0&30\\
\hline
\tikzmark{StartA}Spike&0&\tikzmark{EndB}0&\tikzmark{EndA}0\\
\hline
\end{array}\\
$
\DrawLine[red, very thick,dotted]{StartA}{EndA}
\DrawVLine[red,very thick,dotted]{StartB}{EndB}
但最终却是这样的:
我想要的是让红线位于列的中心并且是直线,可以通过向 2.north 和 3.north 添加值来调整它,但是对于每个表来说这是分开的,这意味着它对我来说不够强大。
答案1
尽管这更多的是一种解决方法而不是解决方案,但您可以做这样的事情:
\documentclass{amsart}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawVLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2.north)$) -- ($(#3.north)$);
\end{tikzpicture}%
}%
\newcommand{\DrawLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2)+(-0.4,0.6ex)$) -- ($(#3)+(0.6,0.6ex)$);
\end{tikzpicture}%
}%
\begin{document}
$
\begin{array}{|c|c|c|c|}
\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{\vspace{-.3cm}\tikzmark{StartB}}&\multicolumn{1}{c}{}\\\hline
&Dig&Weed&Cut\\
\hline
Boris&50&0&50\\
\hline
Percival&20&0&30\\
\hline
\tikzmark{StartA}Spike&0&0&\tikzmark{EndA}0\\
\hline
\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{\raisebox{.6\normalbaselineskip}{\tikzmark{EndB}}}&\multicolumn{1}{c}{}\\
\end{array}\\
$
\DrawLine[red, very thick,dotted]{StartA}{EndA}
\DrawVLine[red,very thick,dotted]{StartB}{EndB}
\end{document}
产量:
当然,缺点是您有两个额外的“隐形”行。
答案2
一个非常简单的解决方案pstricks
:定义四个节点并将它们与相关参数连接起来:
\documentclass[svgnames]{amsart}
\usepackage{array}
\usepackage{pst-node}
\usepackage{auto-pst-pdf} %% to compiile with pdflatex -shell-escape (TeX Live, MacTeX)
%% or pdflatex --enable-write18 (MiKTeX)
\begin{document}
\[ \begin{postscript}
\setlength{\extrarowheight}{3pt}
\begin{array}{|c|c|c|c|}
\hline
& Dig & \Rnode{W}{Weed} & Cut\\
\hline
Boris & 50 & 0 & 50\\
\hline
Percival & 20 & 0 & 30 \\
\hline
\pnode[-4pt, 0.7ex]{A}Spike & 0 &\Rnode{O}{0} & 0\pnode[4pt, 0.7ex]{B} \\
\hline
\end{array}
%% Node connections:
\psset{linewidth=0.6pt, linecolor=Crimson, linestyle=dashed, dash=3pt 3pt}
\ncline[nodesep=-9pt]{W}{O}
\ncline{A}{B}
\end{postscript} \]
\end{document}