[Tex/LaTex] Diagonal strikeout starting too low and ending too high

equationsstrikeouttikz-pgf

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}

\begin{equation}\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{equation}

\end{document}

This produces:

Line starts too low and ends too high

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

The line as I want it to draw

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

Best Answer

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}

\begin{equation}\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}
\end{equation}

\begin{equation}\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{equation}

\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}

\begin{equation}\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}$}
\end{equation}

\begin{equation}\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{equation}

\end{document}