3

How to draw a horizonal line across a row (over the entries) in an array?

1

2 Answers 2

4

The following macro \overtabline puts a line in the middle of the previous table row assuming the row is not larger than \@arstrut (\strut for tables that also include the setting of \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}

Result

3

This can also be done using \tikzmark:

enter image description here

Note:

Code:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .