# Diagonal strikeout starting too low and ending too high

I want to strikeout an equation with diagonal line but I've not managed to get the diagonal line to draw as I want. The closest I've gotten is via the first example in Frédéric's answer of \cancel draws under thing being canceled:

\documentclass{minimal}

\usepackage{tikz}

\newcommand{\hcancel}[1]{%
\tikz[baseline=(tocancel.base)]{
\node[inner sep=0pt,outer sep=0pt] (tocancel) {#1};
\draw[red] (tocancel.south west) -- (tocancel.north east);
}%
}%

\begin{document}

$$\label{eq:2} \hcancel{h_1 \land h_2 \land h_3 \land h_4 \land h_5 \land h_6 \land h_7 \land h_8 \land h_9 \land h_{10}}$$

\end{document}


This produces:

But the line starts too low and ends too high. The following is what I want:

I'd be happy for an option to make the line start slightly earlier and end slightly later too.

-

You can modify Frédéric's code so that \hcancel receives four more mandatory arguments controlling the vertical and horizontal shifting for the starting and ending points:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\hcancel}[5]{%
\tikz[baseline=(tocancel.base)]{
\node[inner sep=0pt,outer sep=0pt] (tocancel) {#1};
\draw[red] ($(tocancel.south west)+(#2,#3)$) -- ($(tocancel.north east)+(#4,#5)$);
}%
}%

\begin{document}

$$\label{eq:1} \hcancel{h_1 \land h_2 \land h_3 \land h_4 \land h_5 \land h_6 \land h_7 \land h_8 \land h_9 \land h_{10}}{0pt}{0pt}{0pt}{0pt}$$

$$\label{eq:2} \hcancel{h_1 \land h_2 \land h_3 \land h_4 \land h_5 \land h_6 \land h_7 \land h_8 \land h_9 \land h_{10}}{-3pt}{3pt}{3pt}{-2pt}$$

\end{document}


The new syntax:

\hcancel{<text>}{<start. point horiz. shifting>}{<start. point vertical shifting>}{<end. point horiz. shifting>}{<end. point vertical shifting>}


EDIT: using the xparse package, the definition of the new command is much more flexible; using something like

\usepackage{xparse}
\DeclareDocumentCommand{\hcancel}{mO{0pt}O{0pt}O{0pt}O{0pt}}{%
\tikz[baseline=(tocancel.base)]{
\node[inner sep=0pt,outer sep=0pt] (tocancel) {#1};
\draw[red] ($(tocancel.south west)+(#2,#3)$) -- ($(tocancel.north east)+(#4,#5)$);
}%
}%


allows the use of \hcancel{<text>} for the standard behaviour of the command as defined by Frédéric and to use the four (now optional) arguments to control the horizontal/vertical shifting:

\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc}

\DeclareDocumentCommand{\hcancel}{mO{0pt}O{0pt}O{0pt}O{0pt}}{%
\tikz[baseline=(tocancel.base)]{
\node[inner sep=0pt,outer sep=0pt] (tocancel) {#1};
\draw[red] ($(tocancel.south west)+(#2,#3)$) -- ($(tocancel.north east)+(#4,#5)$);
}%
}%

\begin{document}

$$\label{eq:1} \hcancel{h_1 \land h_2 \land h_3 \land h_4 \land h_5 \land h_6 \land h_7 \land h_8 \land h_9 \land h_{10}}$$

$$\label{eq:2} \hcancel{h_1 \land h_2 \land h_3 \land h_4 \land h_5 \land h_6 \land h_7 \land h_8 \land h_9 \land h_{10}}[-3pt][3pt][3pt][-2pt]$$

\end{document}

-

You can create nodes at the beginning and the end of the line, and shift them vertically:

\tikzstyle{nosep}=[inner sep=0pt, outer sep=0pt]
\newcommand{\hcancel}[1]{%
\tikz[baseline=(tocancel.base)]{
\node[nosep] (tocancel) {#1};
\node[nosep, yshift=.5ex]  (from) at (tocancel.south west) {};
\node[nosep, yshift=-.5ex] (to)   at (tocancel.north east) {};
\draw[red] (from) -- (to);
}%
}%


You can find the best shifts by trial and error. I chose .5ex and -.5ex arbitrarily.

-
@N.N. And to make the line slightly longer, add xshift=-1ex to the from node (+1ex for the to node). – Alan Munn Jun 13 '11 at 21:05

Another possibility is to create a style.

\documentclass[]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[cancel/.style={path picture={ \draw[#1]
($(path picture bounding box.south west)+(-3pt,6pt)$) -- ($(path picture bounding box.north east)+(3pt,-6pt)$);
}}]
\node   [inner sep=3pt,cancel=red] {$2x+3=y$};
\end{tikzpicture}

\end{document}


-
It's possible to place the code in a macro with arguments. – Alain Matthes Jun 13 '11 at 21:53
When I try to compile this I get: ! Package pgfkeys Error: I do not know the key '/tikz/path picture' and I am going to ignore it. Perhaps you misspelled it. – N.N. Jun 14 '11 at 7:33
@N.N. I use pgf 2.1. and perhaps 'path picture' is defined since the 2.1 but I don't know :( I use this option in several examples and in some answers without problem. – Alain Matthes Jun 14 '11 at 8:03
OK, you're probably right. I've got pgf 2.0 from TeX Live 2009 on my system. – N.N. Jun 14 '11 at 8:07

I use PSTricks in this answer. Please adjust the parameters until they suit your preference best. The parameters given in the code below are self-explanatory.

\documentclass{minimal}

\psset{linecolor=red}
\def\myeq{\psDefBoxNodes{A}{h_1 \land h_2 \land h_3 \land h_4 \land h_5 \land h_6 \land h_7 \land h_8 \land h_9 \land h_{10}}}
\begin{document}

\centering

$$\myeq \ncline[nodesep=3pt,offsetA=-1pt,offsetB=3pt]{A:bl}{A:tr}$$
\\[5mm]

Controlling the length:
$$\myeq \ncline[nodesep=10pt,offsetA=-1pt,offsetB=3pt]{A:bl}{A:tr}$$
\\[5mm]

Controlling the left node:
$$\myeq \ncline[nodesep=3pt,offsetA=-1pt,offsetB=-10pt]{A:bl}{A:tr}$$
\\[5mm]

Controlling the right node:
$$\myeq \ncline[nodesep=3pt,offsetA=10pt,offsetB=3pt]{A:bl}{A:tr}$$

\end{document}

-