用删除线隐藏文本?

用删除线隐藏文本?

我想隐藏已删除的文本。我认为这不会hide产生效果,因为hide它会用相同大小的空框替换。

我认为类似这样的用无\renewcommand\st替换每个实例的方法\st{ }\会很好用,但我不知道如何做到这一点(我也没有找到另一篇完全做到这一点的帖子)。

最小工作示例:

\documentclass[12pt]{article}
\usepackage{soul}
\begin{document}

This text should remain visible 
\st{but the strikethrough text should just disappear} 
so that thus just flows from the word visible before the strikethrough.

\end{document}

答案1

一个解决方案是使用\unskip像建议的那样@StevenB.Segletes。但我更喜欢使用\@bsphack\@esphack,因为这样\unskip会吞掉前面的空格\st,即使后面没有空格(下面说明了这一点)。

此外,我会使用\ifhmode它作为\unskip解决方案,因为您通常不想删除任何垂直空间,并且\@bpshack\@esphack解决方案不需要它,因为两者\@bsphack都可以自行\@esphack测试\ifhmode

我会用什么:

\documentclass[]{article}

\usepackage{soul}

\makeatletter
\renewcommand\st[1]{\@bsphack\@esphack}%
\makeatother

\begin{document}
This text should remain visible.
\st{but the strikethrough text should just disappear} 
So that thus just flows from the word visible before the strikethrough.
\end{document}

比较两种解决方案的示例:

\documentclass[]{article}

\usepackage{soul}

\begin{document}
This text should remain visible.
\st{but the strikethrough text should just disappear} 
So that thus just flows from the word visible before the strikethrough.

\renewcommand\st[1]{\ifhmode\unskip\fi}%
This text should remain visible.
\st{but the strikethrough text should just disappear} 
So that thus just flows from the word visible before the strikethrough.

\noindent
\makebox[\linewidth][s]
  {%
    This text should remain visible.
    \st{but the strikethrough text should just disappear}%
    So that thus%
  }

\makeatletter
\renewcommand\st[1]{\@bsphack\@esphack}%
\makeatother
\noindent
\makebox[\linewidth][s]
  {%
    This text should remain visible.
    \st{but the strikethrough text should just disappear}%
    So that thus%
  }

This text should remain visible.
\st{but the strikethrough text should just disappear} 
So that thus just flows from the word visible before the strikethrough.
\end{document}

在此处输入图片描述

相关内容