I am writing an article in LaTeX 2e. Part of the article describes the Sieve of Eratosthenes, and I want to show examples of how multiples of a prime are removed from the sieve by showing them in a strikethrough font. How do I create a strikethrough font in LaTeX 2e?
[Tex/LaTex] Strikethrough text
strikeouttext-decorations
Related Solutions
Here is a solution using the SOUL
package. Linebreaks etc. are respected although spacing may change very slightly if prior experience holds true. I tried with ulem
but likely because of my unfamiliarity of the package, I couldn't get a solution that would work for more than a single word. I'm not sure if the SOUL
package is any less compatible than ulem
when it comes to conflicts etc.
I believe that both packages first draw the line, and the place the text which is why the line is in the background. There may be other ways around that problem, but my "soul"ution was to typeset zero-width text (using \rlap
), and then strikeout a phantom version of the text on top of it. The command takes two optional arguments: the first sets the color of the strike (default red) and the second sets the color of the text.
\documentclass{article}
\usepackage{xparse}
\usepackage{soul}
\usepackage{xcolor}
\makeatletter
\NewDocumentCommand{\sotwo}{O{red}O{black}+m}
{%
\begingroup
\setulcolor{#1}%
\setul{-.5ex}{.4pt}%
\def\SOUL@uleverysyllable{%
\rlap{%
\color{#2}\the\SOUL@syllable
\SOUL@setkern\SOUL@charkern}%
\SOUL@ulunderline{%
\phantom{\the\SOUL@syllable}}%
}%
\ul{#3}%
\endgroup
}
\makeatother
\begin{document}
Hello \sotwo{Welt} World!
\sotwo[green]{Here is a long sentence that will span across a number of lines to force a linebreak}
\sotwo[green][blue]{Here is a long sentence that will span across a number of lines to force a linebreak}
Here is a long sentence that will span across a number of lines to force a linebreak
\end{document}
Here's a way of defining a \hideit
using Beamer's extended \newcommand
:
\documentclass[handout]{beamer}
\setbeamercolor{math text}{fg=blue}
\newcommand\hideit[1]{%
\only<0| handout:1>{\mbox{}}%
\invisible<0| handout:1>{#1}}
\begin{document}
\begin{frame}
\frametitle{Two bugs:}
{\color{red}Error with itemize}
\begin{itemize}
\item The line below should have a `bullet' (only the
text should be hidden)
\item \hideit{Some text to be hidden}
\item This is visible again.
\end{itemize}
\bigskip
{\color{red}Error with beamer's pause command:}
\textbf{Example 1:}\quad Differentiate \ $f(x)=x^2\sin x$
\bigskip
\underline{\itshape Solution:}
\hideit{Let $u=x^2$ and $v=\sin x$. (this line should be hidden)
\pause Then $u'=2x$ and $v'=\cos x$.
Using the product rule we get
$$f' = 2x\sin x + x^2\cos x.$$
}
\end{frame}
%%%%%%%%%%%
\begin{frame}
\frametitle{Two more bugs:}
{\color{red}Error with `inline' hiding:}
Here is some \hideit{hidden} text on one line.
\bigskip
{\color{red}Error with eqnarray* in beamer:}
\textbf{Example 1:}\quad Differentiate \ $f(x)= \frac{\sin x}{e^x}$.
\medskip
\underline{Solution:} Let $u=\sin x$ and $v=e^x$.
Then $u'=\cos x$ and $v'=e^x$. Therefore
\hideit{\begin{eqnarray*}
f'(x) &=& \frac{e^x\cos x-(\sin x)e^x}{(e^x)^2} \\
&=& \frac{e^x(\cos x-\sin x)}{(e^x)^2} \\
&=& \frac{\cos x-\sin x}{e^x}.
\end{eqnarray*}
}
And that's how you do it! (This should be black text)
\end{frame}
\end{document}
And for the presentation:
Best Answer
I'm not quite sure what you mean with creating a strikethrough font. However, for striking through text horizontally see:
https://stackoverflow.com/questions/2663944/how-to-strike-out-inside-latex-equations
So with the
ulem
package this is:With the
soul
package this is:The
ulem
package seems more up to date so I would use that.