Strike out – Strikethrough text and formula in LaTeX
LaTeX doesn’t provide a built-in strikethrough text option. However, with a few clever techniques and packages, you can easily add strikethrough text to your LaTeX documents. Like, cancel
and ulem
package.
In this tutorial, we will explore various methods and styles to achieve strikethrough text and formulas in LaTeX.
Strikethrough in LaTeX with cancel package
cancel
package is the most recommended package for strikethrough text and formulas in LaTeX. Because it works well with text and also inside the equation
environment.
This package provides you with different styles of Strikeouts. The following table will help you.
Command | Output |
---|---|
\cancel{text} | ![]() |
\bcancel{text} | ![]() |
\xcancel{text} | ![]() |
\cancelto{4}{2+2} | ![]() |
\documentclass{article} \usepackage{cancel} \begin{document} Strike out expression with \verb|\cancel| in inline math mode: $\cancel{\alpha +2\pi}$ Strike out this \cancel{text} in text mode with \verb|cancel|. Strike out expression with \verb|\cancel| in inline math mode: $\bcancel{\alpha +2\pi}$ Strike out this \bcancel{text} in text mode with \verb|bcancel|. Strike out this \xcancel{this} with \verb|\xcancel|. Strike out inside \verb|equation| with \verb|\cancel|: \begin{equation} \cancel{a_1 + a_2 = a_3} \end{equation} Strike out inside \verb|equation| with \verb|\bcancel|: \begin{equation} \bcancel{a_1 + a_2 = a_3} \end{equation} Strike out inside \verb|equation| with \verb|\xcancel|: \begin{equation} \xcancel{a_1 + a_2 = a_3} \end{equation} Strike out inside \verb|equation| with \verb|\cancelto|: \begin{equation} \frac{\cancelto{8}{16}}{\cancel{2}} = 8 \end{equation} \end{document}
Output:
Strikethrough in LaTeX with ulem package
Basically, the ulem
package is mostly used to add underline to text. However, this package provides \sout{<text>}
and \xout{<text>}
command to strike out text.
But these command doesn’t work inside the equation
environment and LaTeX math mode, in this case, you have to use the cancel
package.
Also, you can use the amsmath
package and \text
command to strike out text in math mode but inside the equation
not possible. Take a look.
\documentclass{article} \usepackage{amsmath} \usepackage{ulem} \begin{document} Strike out expression with \verb|\sout| in inline math mode: $\sout{\alpha +2\pi}$ Not worked in math mode! Strike out expression with \verb|\sout| and \verb|\text| in inline math mode: \text{\sout{$\alpha +2\pi$}} Worked!! Strike out this \sout{text} in text mode with \verb|\sout|. Worked in text mode! Strike out this \xout{this} with \verb|\xout|. Strike out inside \verb|equation| with \verb|\sout|: \begin{equation} \sout{a_1 + a_2 = a_3} \end{equation} Not worked! \end{document}
Output:
Colored strikeout in LaTeX with soul package
The soul package also provides \st{<text>}
command to strike out text in LaTeX. The advantage of this package is you can set the color of the line and get a colored strikeout.
In order to set the color you have to use \setstcolor{<color-name>}
command then use the \st
command.
\documentclass{article} \usepackage{xcolor} % For color \usepackage{soul} \begin{document} Strike out this \st{this} with \verb|\st|. \setstcolor{red} % set color Strike out this \st{this} with \verb|\st| in red color. \setstcolor{green} % set color Strike out this \st{this} with \verb|\st| in green color. \end{document}
Output:
Leave a Reply