Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I strikeout words in math mode (similar to \sout with \usepackage{ulem} in text mode)? I've tried \usepackage{cancel} and \(\cancel{1+1=2}\) but that draws a diagonal line.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

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.

share|improve this answer
    
This does not work inside math mode, e.g. if I want to strikeout a portion of a phrase in math mode. –  N.N. Jun 13 '11 at 12:20
    
@N.N.: It's easy to generalize the solution. See update. –  Leo Liu Jun 13 '11 at 12:28
    
This method does not really work well. The ulem package is necessary, and it changes \emph{} to underlining. –  Jeff Aug 29 '13 at 19:35
    
@Jeff: Use \normalem. –  Leo Liu Aug 30 '13 at 2:20
add comment

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

share|improve this answer
1  
\hbox{#2} will typeset #2 in textmode, which is fine with y (except maybe a slightly wrong width), but will break horrible with real math expressions. –  Martin Scharrer Jun 13 '11 at 12:44
    
@Martin yes you are right, I forgot $...$ –  Alain Matthes Jun 13 '11 at 12:56
    
Does this solution rely on \documentclass{scrartcl}? –  N.N. Jun 13 '11 at 17:16
    
@N.N. no I think the package `cancel is independent –  Alain Matthes Jun 13 '11 at 17:47
add comment

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

share|improve this answer
    
Indeed, but you need to restart the mathmode, don't you? E.g. `$x+\hcancel{$y$}+z$. –  Martin Scharrer Jun 13 '11 at 12:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.