26

I'd like to "cancel" (draw a line through) a column of a matrix (using \begin{pmatrix}..\end{pmatrix}). How can I do this?

2

4 Answers 4

12

The usual TikZ answer using \tikzmark to mark the top and bottom points where you want the line to be drawn:

enter image description here

Notes:

  • This does require two runs. First one to determine the locations, and the second to do the drawing.

References:

Code:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}

\newcommand{\tikzmark}[2]{\tikz[overlay,remember picture,baseline] \node [anchor=base] (#1) {$#2$};}

\newcommand{\DrawLine}[3][]{%
  \begin{tikzpicture}[overlay,remember picture]
    \draw[#1] (#2.north) -- (#3.south);
  \end{tikzpicture}
}

\begin{document}
\[
\begin{pmatrix}
  \tikzmark{topA}{a} & \tikzmark{topB}b & {0} \\
  a & b & 0 \\
  a & b & 0 \\
  \tikzmark{bottomA}{c} & \tikzmark{bottomB}d & {1}
\end{pmatrix}
\]
\DrawLine[red, thick, opacity=0.5]{topA}{bottomA}
\end{document}
20
\documentclass{article} 
\usepackage{amsmath}
\begin{document}

\[\begin{pmatrix}
  a & b & c  \\
  d & e & f\makebox(-6,0){\rule[1ex]{0.4pt}{3\normalbaselineskip}}\\
  g & h & i
\end{pmatrix}\]

\end{document}

enter image description here

And a line only through f and i:

d & e & f\makebox(-6,0){\rule[-7ex]{0.4pt}{2\normalbaselineskip}}\\

enter image description here

3
  • can you show me how draw an horizontal line to cancel the first row? Merry christmas! Dec 25, 2017 at 11:42
  • for example \rlap{\rule[0.6ex]{1.3cm}{0.4pt}}a & b & c \\
    – user2478
    Dec 25, 2017 at 20:40
  • Very good @Herbert! Dec 25, 2017 at 21:06
9
\documentclass[a4paper]{article}
\usepackage{amsmath}
\begin{document}
\[
\settodepth{\dimen0}{$\begin{array}[t]{l}1\\2\\3\\4\end{array}$}
\addtolength{\dimen0}{2ex}
\begin{pmatrix}
  a & b & 0 \\
  a & b & 0 \\
  a & b & 0 \\
  \smash{\makebox[0pt][l]{\kern2pt\rule[-.8ex]{0.4pt}{\dimen0}}}
  c & d & 1
\end{pmatrix}
\]
\end{document}

enter image description here

More can be added if you define better your needs

2

Here is a rudimentary way to do this with a regular array:

enter image description here

\documentclass{article} 
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\[\begin{pmatrix}
  a & b & c \\
  d & e & f \\
  g & h & i
\end{pmatrix}\]

\[\left(\begin{array}{@{}cc@{\hspace{2\tabcolsep}}|@{\hspace{-.5\tabcolsep}}c@{}}
  a & b & c \\
  d & e & f \\
  g & h & i
\end{array}\right)\]
\end{document}

This works well for single-entry columns. If you have wider columns, more modification of the lengths are required.

You must log in to answer this question.

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