Diagonal strikeout starting too low and ending too high
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}
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.
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}