Since \sout does not work in math mode, what can I use instead? I don't want the diagonal strikeout like with cancelf
Asked
Active
Viewed 4,278 times
4
-
@Mico as I mentioned I want a HORIZONTAL slash NOT a diagonal one I want \sout but for math mode – Hao S Apr 12 '20 at 01:13
-
One should be able to adapt the answers at Diagonal strikeout starting too low and ending too high to get a horizontal line as it allows you to control how high you start and end. – Peter Grill Apr 12 '20 at 05:30
2 Answers
3
The package cancel was made exactly for this purpose.
The manual says that there are four different commands:
\cancel\bcancel\xcancel\cancelto{<value>}{<expression>}
The first three work in math and text mode, but \cancelto is only for math mode.
And this is what they do
MWE
\documentclass{article}
\usepackage{cancel}
\begin{document}
\(\cancel{f(x)} = \bcancel{4} + \xcancel{5} - \cancelto{45}{60}\)
\end{document}
Andreas Schneider
- 2,755
1
This answer is heavily based on egreg's comment and he deserves all the credit.
\documentclass{article}
\makeatletter
\newcommand{\linethrough}{\mathpalette\@thickbar}
\newcommand{\@thickbar}[2]{{#1\mkern0mu\vbox{
\sbox\z@{$#1#2\mkern-1.5mu$}%
\dimen@=\dimexpr\ht\tw@-\ht\z@+2\p@\relax % The +2 represents the vertical shift of the line.
\hrule\@height0.5\p@ % The 0.5 represent the thickness on the line.
\vskip\dimen@
\box\z@}}
}
\makeatother
\newcommand{\mathstrike}[1]{\ensuremath{\linethrough{#1}}}
\begin{document}
\mathstrike{f(x) = x^2},\qquad \mathstrike{c_0}, \qquad \mathstrike{f(x) = x^2 + c_0}
\end{document}
M. Al Jumaily
- 4,035
- 2
- 11
- 26
-
Very nice answer! Just one question: how can we make the line to be in front of the striked out text (I made the line red, and it appears behind the text)? – M. Winter Feb 23 '21 at 16:03
-
1@M.Winter you can redefine the
\@thickbaras follows:\newcommand{\@thickbar}[2]{% \textcolor{red}{ {\mkern0mu\vbox{ \sbox\z@{$#1\textcolor{black}{#2}\mkern-1.5mu$}% \dimen@=\dimexpr\ht\tw@-\ht\z@+2\p@\relax % The +2 represents the vertical shift of the line. \hrule\@height0.5\p@ % The 0.5 represent the thickness on the line. \vskip\dimen@ \box\z@}}#1} }and make sure to add
– M. Al Jumaily Feb 23 '21 at 19:19\usepackage{xcolor} -
Unfortunately this does not work for me. The line is still behind the text. – M. Winter Feb 24 '21 at 11:34
-
@M.Winter, it would have been easier to create a new question so I can give a complete answer than just a comment but here is another alternative:pastebin – M. Al Jumaily Feb 24 '21 at 15:30

