# How to cross a row in matrix with a line?

Is there an "easy" way to cross the row in a matrix with a line? I am trying to demonstrate to my students how to type in LaTeX their homework assignment on Boolean function. The below table is used during the construction of normal conjunctive and disjunctive form of a Boolean function. This is a "hand" made example.

• I understand the question, but could you clarify the motivation? It seems to have become garbled... Jan 29, 2012 at 5:50
• @Mark In order to construct normal form for Boolean function you cross the rows with output zero and then use rows with output 1 to construct the function. For example in first row which is not crossed you have 0 under p, 0 under q and 1 under r so the form for that row is \lnot p \wedge \lnot q \wedge r. Then you want to \vee that expression with expressions for two other raws which have output 1. I just want to use TeX to cross o output raws in the same fashion I did it by hand. Jan 29, 2012 at 6:14
• I think you misunderstood me. I understand the question, but the text is actually garbled. The second sentence is the problem. Jan 29, 2012 at 7:46
• @Mark I wonder what was in my head when I typed that nonsense. Thank you so much for pointing the mistake!!! You should have immediately edited question yourself. Jan 29, 2012 at 15:11
• It's possible to do the full monty here and implement the entire matrix in TikZ, thus giving full access to all the entries as nodes. See tex.stackexchange.com/q/26866/86 for details. Jan 29, 2012 at 17:26

You can use tikz for this. Probably not the finest answer possible, but works for me:

\documentclass{article}
\usepackage{tikz}
\newcommand{\pmark}[1]{\begin{tikzpicture}[overlay,remember picture]\node(#1)at (-1em,.7ex){};\end{tikzpicture}}
\newcommand{\smark}[1]{\begin{tikzpicture}[overlay,remember picture]\draw(#1)--(0,.7ex);\end{tikzpicture}}
\begin{document}
$$\begin{array}{cccc|c} a&b&bc&d&f\\\hline 0\pmark{a}&0&1&1&1\smark{a}\\ 0&0&0&1&0\\ 0&0&1&1&1\\ \end{array}$$
$f=\overline{a}\wedge\overline{b}\wedge c\wedge+\dots$
\end{document}

• Yeap, it sure does! Actually you did even better. Your code provides means of controlling the length and the position of the line so that one can cross arbitrary number of entries in the line. I am guessing it could be even modified for crossing columns (I have no idea why that would be useful). Jan 29, 2012 at 15:07

With nicematrix, you can write a command \Cross to use in each row you want to cross. You will be able to use that command in the environments of nicematrix ({NiceTabular}, {pNiceMatrix}, etc.) which are similar to the classical environments (of the packages array and amsmath).

\documentclass{article}
\usepackage{nicematrix}
\usepackage{tikz}

\ExplSyntaxOn
\NewDocumentCommand { \Cross } { }
{
\tl_gput_right:Nx \g_nicematrix_code_after_tl
{ \__pantigny_cross:n { \int_use:c { c@iRow } } }
}
\cs_new_protected:Nn \__pantigny_cross:n
{
\tikz
\draw [red, shorten~> = -3pt, shorten~< = -3pt]
( #1-1-medium .west ) -- ( #1- \int_use:c { c@jCol } - medium .east ) ;
}
\ExplSyntaxOff

\begin{document}

\begin{NiceTabular}{cccc}[create-medium-nodes]
$p$ & $q$ & $r$ & $f$ \\
\hline
0 & 0 & 0 & 0 \Cross \\
0 & 0 & 1 & 1 \\
0 & 1 & 0 & 1 \\
0 & 1 & 1 & 0 \Cross \\
1 & 0 & 0 & 0 \\
1 & 1 & 0 & 0 \\
1 & 1 & 1 & 1
\end{NiceTabular}

\end{document}


The use of the medium nodes ensures horizontal lines.

We have to compile several times (because nicematrix uses PGF/Tikz nodes).