Strikeout in math mode

version 2 (fine remark from Martin)

\documentclass{scrartcl}
\usepackage{xcolor,cancel}

\newcommand\hcancel[2][black]{\setbox0=\hbox{$#2$}%
\rlap{\raisebox{.45\ht0}{\textcolor{#1}{\rule{\wd0}{1pt}}}}#2} 

\begin{document}

\[
  x+\hcancel[red]{ \sum_a \mathcal{D}^a\mathcal{D}_a}=2x+ \sum_a \mathcal{D}^a\mathcal{D}_a+3 
\]

\end{document}

enter image description here


Use something like

\sout{$a^2+b^2=c^2$}

or

\[
  \hbox{\sout{$a^2+b^2$}}=c^2
\]

And you can of course define a command for convenience.


Works in math and text mode

\documentclass{article}
\usepackage{calc}
\newsavebox\CBox
\newcommand\hcancel[2][0.5pt]{%
  \ifmmode\sbox\CBox{$#2$}\else\sbox\CBox{#2}\fi%
  \makebox[0pt][l]{\usebox\CBox}%  
  \rule[0.5\ht\CBox-#1/2]{\wd\CBox}{#1}}
\begin{document}

\hcancel{Test}
\hcancel[2pt]{Test}

\end{document}

enter image description here