删除文本而不影响文本框大小

删除文本而不影响文本框大小

我想用一条简单的线划掉文本。不幸的是,在我找到的解决方案中,文本与下一行之间的距离总是较大(见示例)。

怎样才能删除文本而不增加到下一行的距离?

\documentclass[12pt]{beamer}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[normalem]{ulem}
\newcommand\tst{% thick strike through  %% from http://tex.stackexchange.com/questions/134088/mis-alignment-of-columns-in-tabular-environment-when-using-ulem-and-beamer
  \bgroup%
  \markoverwith{\textcolor{red}{\rule[.8ex]{1pt}{0.8pt}}}%
  \ULon%
}

\begin{document}

\begin{frame}
\begin{align*}
P = \{ & \tst{S\rightarrow X_{1,4,2}}\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1},\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1}\}
\end{align*}
\end{frame}

\end{document}

答案1

我曾经soul做过删除线,但必须定义一个displayst命令来在显示数学模式下做删除线。(soul命令只适用于数学,如\st{$abc$}。。。)我也使用了解决方案为什么投影机里的灵魂着色不可见使颜色起作用。用于\setul{⟨underline depth⟩}{⟨underline thickness⟩}更改下划线/删除线的粗细soul。–

\documentclass[12pt]{beamer}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{color,soul}
\makeatletter
\newcommand\SoulColor{%
  \let\set@color\beamerorig@set@color
  \let\reset@color\beamerorig@reset@color}
\makeatother
\setstcolor{red}
%\setul{}{1pt} Use this to change weight of underline/strikethrough

\newcommand{\displayst}[1]{\textrm{\SoulColor\st{$\displaystyle#1$}}}

\begin{document}

\begin{frame}
\begin{align*}
P = \{ & \displayst{S\rightarrow X_{1,4,2}}\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1},\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1}\}
\end{align*}
\end{frame}

\end{document}

结果:

在此处输入图片描述

编辑

我想要让这个工作顺利进行,soul需要修复一些问题。我最初发布的解决方案是在文本后面而不是文本顶部删除,但这在不同颜色的删除线出现在字母后面,而不是字母上面

\documentclass[12pt]{beamer}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xparse,xcolor,soul}

%% First define strikethrough command that strikes on top of letters, not behind them 
\makeatletter
\NewDocumentCommand{\sttwo}{O{red}O{black}+m}
    {%
        \begingroup
        \setulcolor{#1}%
        \setul{-.5ex}{1pt}% <---- sets the undline/strikeout weight to 1pt
        \def\SOUL@uleverysyllable{%
            \rlap{%
                \color{#2}\the\SOUL@syllable
                \SOUL@setkern\SOUL@charkern}%
            \SOUL@ulunderline{%
                \phantom{\the\SOUL@syllable}}%
        }%
        \ul{#3}%
        \endgroup
    }
\makeatother

% Now make soul colors work with beamer
\makeatletter
\newcommand\SoulColor{%
  \let\set@color\beamerorig@set@color
  \let\reset@color\beamerorig@reset@color}
\makeatother

%Now make a version of strikethrough that works with display math
\newcommand{\displayst}[1]{\textrm{\SoulColor\sttwo{$\displaystyle#1$}}}


\begin{document}

\begin{frame}
\begin{align*}
P = \{ & \displayst{S\rightarrow X_{1,4,2}}\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1},\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1}\}
\end{align*}
\end{frame}

\end{document}

结果:

在此处输入图片描述

答案2

不带ulemsoul

\documentclass[12pt]{beamer}
\usepackage{amsmath,amssymb,amsthm}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\makeatletter
\newcommand{\tst}[1]{%
  \ifmeasuring@
    % we're in the measuring stage, just use the argument
    #1
  \else
    % we're typesetting, add the strikeout rule
    \sbox0{$\displaystyle#1$}
    \rlap{\color{red}%
          \vrule height \dimexpr.5ex+0.4pt\relax
                 depth -\dimexpr.5ex-0.4pt\relax
                 width \wd0 }
    \box0
  \fi
}
\makeatother

\begin{document}

\begin{frame}
\begin{align*}
P = \{ & \tst{S\rightarrow X_{1,4,2}}\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1},\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1}\}
\end{align*}
\begin{align*}
P = \{ & S\rightarrow X_{1,4,2}\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1},\\
       & X_{1,4,1}\rightarrow X_{1,1,1}X_{2,3,1}\}
\end{align*}
\end{frame}

\end{document}

在此处输入图片描述

相关内容