如何在数组中的一行(条目上方)画一条水平线?
答案1
下面的宏\overtabline
在前一个表格行的中间放置一行,假设该行不大于\@arstrut
(\strut
对于也包含设置的表格\arraystretch
)。
\documentclass{article}
\renewcommand*{\arraystretch}{1.5}
\makeatletter
\newcommand*{\overtabline}{%
\noalign{%
% normal "baselineskip" in tabular is height + depth of \@arstrutbox
\vskip-.5\dimexpr\ht\@arstrutbox+\dp\@arstrutbox\relax
% default line thickness is 0.4pt
\vskip-.2pt\relax
\hrule
\vskip-.2pt\relax
\vskip+.5\dimexpr\ht\@arstrutbox+\dp\@arstrutbox\relax
}%
}
\begin{document}
\centering
\begin{tabular}{ll}
abc&def\\
\overtabline
ghi&jkl\\
\overtabline
\end{tabular}
\[
\begin{array}{ll}
abc&def\\
\overtabline
ghi&jkl\\
\overtabline
\end{array}
\]
\end{document}
答案2
也可以使用以下方法完成\tikzmark
:
笔记:
这确实需要两次运行。第一次确定位置,第二次进行绘图。
来自
\tikzmark
在正文旁边添加大括号。
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawLine}[3][]{%
\begin{tikzpicture}[overlay,remember picture]
\draw [#1] ($(#2)+(0,0.6ex)$) -- ($(#3)+(0,0.6ex)$);
\end{tikzpicture}%
}%
\begin{document}
\[
\begin{array}{c c c}
a & b & c \\
\tikzmark{StartA}1 & 2 & 3\tikzmark{EndA} \\
\tikzmark{StartB}f & g & h\tikzmark{EndB}
\end{array}
\]
\DrawLine[red, thick]{StartA}{EndA}
\DrawLine[blue, thick, dotted]{StartB}{EndB}
\end{document}