如何在LaTeX公式中添加删除线?

42
请看下面的片段,并告诉我如何实现与主文本中相同的删除线效果。我正在使用最新Ubuntu存储库中的LaTeX版本。
\documentclass{article}
\usepackage{ulem}
\begin{document}
The sout tag works perfect in the \sout{main text area} but not inside the equations.
$$
list = [1, \sout{2}, 3, \sout{4}, 5, \sout{6}, 7, \sout{8}, 9, \sout{10}]
$$
Any clue?
\end{document}

这里是LaTeX输出


1
在Latex中不应使用$$,因为它是一个普通的Tex命令。 - Debilski
2
关于@Debilski所说的,这个问题在https://dev59.com/wHE95IYBdhLWcg3wluwg.中有一些讨论。我不认为使用$$是一种罪过,也不认为$$支持会消失,但最好避免使用它。 - Charles Stewart
4个回答

28

看起来\sout在数学环境下无法正常工作。 你可以尝试这样做,这种方法是有效的:

似乎\sout无法在数学环境中使用。 您可以尝试以下方法,它可以正常工作:

\documentclass{article}
\usepackage{ulem}
\begin{document}
The sout tag works perfect in the \sout{main text area} but not inside the equations.

$list = $[1, \sout{2}, 3, \sout{4}, 5, \sout{6}, 7, \sout{8}, 9, \sout{10}$]$

Any clue?
\end{document}

这样做非常优雅。谢谢! - Aamir
3
但是ulem宏包会将\emph{}命令改成下划线。 - Jeff
14
从Sara的回答中:“...要使用strike-out而又不让ulem重新定义\emph{}如何工作,请使用\usepackage[normalem]{ulem}。”谢谢Sara! - ɲeuroburɳ

28
如果还有人感兴趣,我刚刚发现了取消包,它允许您以几种不同的方式在数学模式下划掉文本。然而,它不是水平的,只能是对角线,但在我的情况下这样更好。

1
谢谢您提到这个。\cancelto 命令正是我所需要的。 - David L

12

如果您需要在数学模式下保留删除线(例如,保留数学字体),请尝试以下方法:

\newcommand{\msout}[1]{\text{\sout{\ensuremath{#1}}}}

然后
$\msout{\mathsf{stuckout}}$

你需要使用amsmath和ulem。

(解决方案来自这里。)


12

几乎任何非数学模式的命令都可以通过将其放在\text{}环境中来在数学模式内使用,例如:

\documentclass{article}
\usepackage{ulem}
\begin{document}
The sout tag works perfect in the \sout{main text area} but not inside the equations.

\[ list = [1, \text{\sout{2}}, 3, \text{\sout{4}}, 5, \text{\sout{6}}, 7, \text{\sout{8}}, 9, \text{\sout{10}}] \]
Any clue?
\end{document}

如果你想要使用删除线功能 但是又不希望 ulem 改变 \emph{} 的定义,那么可以使用\usepackage[normalem]{ulem}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接