I would like to show a matrix with "strike-out lines" on some of its rows and columns. After some research I found a solution using Tikz matrices, which I reproduce here:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{amsmath}
\begin{document}
\[
\begin{tikzpicture}
\matrix (mat) [%
matrix of nodes,
left delimiter={(},right delimiter={)}
]
{%
2 & 6 & 0 & 4\\
3 & 5 & 5 & 0\\
1 & 0 & 2 & 4\\
5 & 2 & 1 & 0\\
};
% do the strike out thing
\draw[black] (mat-1-1.west) -- (mat-1-4.east);
\draw[black] (mat-1-3.north) -- (mat-4-3.south);
\end{tikzpicture}
\rightarrow
\begin{pmatrix}
0 & 0 & 0 & 0\\
3 & 5 & 0 & 0\\
1 & 0 & 0 & 4\\
5 & 2 & 0 & 0\\
\end{pmatrix}
\]
\end{document}
However, there are a few problems with that: first, the alignment with the second matrix is obviously wrong. Also, the two matrices are in different styles (row/column distance, font, etc).
I already have a several-hundred-long document, so switching every matrix from LateX matrix to Tikz matrix would be too time-comsuming. Is there any other way to get the strike-out effect, resulting in a matrix whose style is consistent with the rest of the matrices in the document?
Thank you!
Best Answer
Here is a method which uses no big graphics engine with many libraries and dependencies.
it uses the
pdftex
\pdfsavepos
primitive, also available inxetex
.it uses the LaTeX
picture
environment to draw the lines at shipout time, with the help of package eso-pic which transforms each page into a LaTeX picture. I observed some conflict withxetex
(shifted vertical locations) which is miraculously fixed by using packagegeometry
(I have no explication).as the
\line
command of the Leslie Lamportpicture
environment is quite limited, I used thepict2e
environment which has a more powerful\Line
. Any package enhancing thepicture
environment would do. In particular it seems I don't know how to do dashed lines withpict2e
.It is very easy to change the code to
a. replace
pict2e
with some other picture environment enhancing package,b. replace
eso-pic
with any package allowing to draw in absolute coordinates on the page.Thus this is a very low-weight solution.
Result: