How to draw a line that passes through rows and columns of a table?
With only basic tools:
\documentclass{article}
\usepackage{float}
\usepackage[table, svgnames]{xcolor}
\usepackage{hhline, array}
\begin{document}
\begin{table}[H]
\centering\setlength{\extrarowheight}{1pt}
\begin{tabular}{|c|c|c|}
\hhline{|---|}
\noalign{\vskip \dimexpr1.5ex + 1pt-0.4pt\relax}
\hhline{>{\arrayrulecolor{Crimson}}--->{\arrayrulecolor{black}}|}
\noalign{\vskip\dimexpr-1.5ex- 1pt\relax}
a & b & c \\
\hhline{|---|}
d & e & f \\
\hhline{|---|}
h & i & j \\
\hhline{|---|}
\end{tabular}
\end{table}
\end{document}
One possibility is to use TikZ and tikzmark
.
\documentclass{article}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|}
\hline
\tikzmarknode{a}{a} & b & \tikzmarknode{c}{c} \\
\hline
d & e & f \\
\hline
h & i & j \\
\hline
\end{tabular}%
\begin{tikzpicture}[overlay,remember picture]
\draw[thick,red,-stealth] ([xshift=-1ex]a.west) -- ([xshift=1ex]c.east);
\end{tikzpicture}%
\end{table}
\end{document}
Note that the syntax of \tikzmarknode
is \tikzmarknode{<id>}{<content>}
, where id
is an identifier and content
is the content. So, if you want a 1
, say instead of the a
, you could use the same identifier and only change the second argument, \tikzmarknode{a}{1}
. Then there will be a 1 in the table.
\documentclass{article}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
\begin{table}[H]
\centering
\begin{tabular}{|c|c|c|}
\hline
\tikzmarknode{a}{1} & 2 & \tikzmarknode{c}{3} \\
\hline
\tikzmarknode{goat}{d} & e & f \\
\hline
\tikzmarknode{duck}{h} & i & j \\
\hline
\end{tabular}%
\begin{tikzpicture}[overlay,remember picture]
\path[left color=blue,right color=red]
([xshift=-1ex,yshift=-0.3pt]a.west) rectangle ([xshift=1ex,yshift=0.3pt]c.east);
\draw[red,shorten >=-0.2ex,shorten <=-0.2ex] (goat.north) -- (duck.south);
\end{tikzpicture}%
\end{table}
\end{document}
This example is also to illustrate that with TikZ you can go far beyond monochrome lines.