如何在 LaTex 中用波浪线划掉一个单词

如何在 LaTex 中用波浪线划掉一个单词

我需要在 LaTex 中用波浪线划掉一个单词。我使用了 ulem 包,但结果是带有波浪线的下划线单词。这是我目前的代码:

\documentclass{article}
\usepackage{pict2e}
\usepackage[normalem]{ulem}
\makeatletter
\newcommand{\crossout}[1]{%
  \begingroup
  \settowidth{\dimen@}{#1}%
  \setlength{\unitlength}{0.05\dimen@}%
  \settoheight{\dimen@}{#1}%
  \count@=\dimen@
  \divide\count@ by \unitlength
  \begin{picture}(0,0)
  \put(0,0){\line(20,\count@){20}}
  \put(0,\count@){\line(20,-\count@){20}}
  \end{picture}%
 #1%
  \endgroup
}
\begin{document}
The most \uwave{\hspace{1cm}}\crossout{powerful} processor in your  \crossout{computer} is probably the graphics processor 
\end{document}

答案1

使用包定义该命令ulem

\newcommand{\waveout}[1]{\raisebox{4pt}{\uwave{\phantom{#1}}}\llap{#1}}

并将其用作\waveout{word}

\documentclass{article}
\usepackage{pict2e}
\usepackage[normalem]{ulem}
\pagestyle{empty}
 \makeatletter
 \newcommand{\crossout}[1]{%
 \begingroup
 \settowidth{\dimen@}{#1}%
 \setlength{\unitlength}{0.05\dimen@}%
 \settoheight{\dimen@}{#1}%
  \count@=\dimen@
 \divide\count@ by \unitlength
  \begin{picture}(0,0)
  \put(0,0){\line(20,\count@){20}}
 \put(0,\count@){\line(20,-\count@){20}}
  \end{picture}%
 #1%
  \endgroup
}
\begin{document}
\newcommand{\waveout}[1]{\raisebox{4pt}{\uwave{\phantom{#1}}}\llap{#1}}

The most powerful processor in your  \waveout{computer} is probably the     graphics \waveout{processor}
\end{document}

在此处输入图片描述

答案2

修改后的答案根据 OP 对“原始答案”的回复。

这样会在单个单词上产生波浪形的 x 形划线。我没有使用三角函数来计算波浪线的角度,而是设置了一系列维度比较。如果需要,可以添加更多。

\documentclass{article}
\usepackage{stackengine,graphicx,xcolor,ulem}
\def\crossout#1{%
  \setbox0=\hbox{#1}%
  \ifdim\wd0<\ht\strutbox\relax\def\xangle{45}\else
  \ifdim\wd0<2\ht\strutbox\relax\def\xangle{30}\else
  \ifdim\wd0<4\ht\strutbox\relax\def\xangle{22}\else
  \ifdim\wd0<6\ht\strutbox\relax\def\xangle{11}\else
  \ifdim\wd0<10\ht\strutbox\relax\def\xangle{5}\else
  \def\xangle{3}%
  \fi\fi\fi\fi\fi
  \def\stacktype{L}\setstackgap{L}{0pt}\def\useanchorwidth{T}%
  \stackon{\stackon[0pt]{#1}{%
  \color{red}\smash{\kern-1pt\rotatebox{\xangle}{\mywave{#1}}}}}{%
  \color{red}\smash{\rotatebox[origin=right]{-\xangle}{\mywave{#1}}}\kern-1pt}}
\def\mywave#1{\raisebox{0.5pt}{\uwave{\phantom{#1}}}}
\begin{document}
The \crossout{most} \crossout{powerful} processor \crossout{in}
your \crossout{computer} is probably the graphics processor. 
Crossout \crossout{a} short word \crossout{and} a 
\crossout{hyper-ridiculously} long
\crossout{supercalifragilisticexpialadocious} word.
\end{document}

在此处输入图片描述

在此处输入图片描述

原始答案

与其他提供的答案相比,这种方法有优点也有缺点。

优点:此方法会换行,而其他方法则不会。

缺点:曲线不精确;本质上,$\sim$参数中的每个字符上都覆盖了一个比例。因此,不能保证一个曲线的末尾与下一个曲线的开头匹配。[我将曲线标为红色,以便读者更好地理解不精确的程度]

\documentclass{article}
\usepackage{stackengine,graphicx,xcolor}
\newcommand\chariterate[2][c]{\chariteratehelpA#2 \relax\relax}
\def\chariteratehelpA#1 #2\relax{%
  \chariteratehelpB#1\relax\relax%
  \ifx\relax#2\else\rlap{\charop{~}}\ \chariteratehelpA#2\relax\fi
}
\def\chariteratehelpB#1#2\relax{%
  \charop{#1}%
  \ifx\relax#2\else
    \chariteratehelpB#2\relax%
  \fi
}
\def\charop#1{\def\stacktype{L}\def\useanchorwidth{T}%
  \stackon[0pt]{#1}{\scalebox{.85}[1]{\color{red}$\sim$}}}
\let\crossout\chariterate
\begin{document}
The most \crossout{powerful} processor in your \crossout{computer} is probably the graphics processor 

\crossout{The most powerful processor in your computer is probably the graphics processor, especially extending over two lines.}
\end{document}

在此处输入图片描述

这是一个带有双波浪线的版本,正如 OP 在一条评论中提到的那样。

\documentclass{article}
\usepackage{stackengine,graphicx,xcolor}
\newcommand\chariterate[2][c]{\chariteratehelpA#2 \relax\relax}
\def\chariteratehelpA#1 #2\relax{%
  \chariteratehelpB#1\relax\relax%
  \ifx\relax#2\else\rlap{\charop{~}}\ \chariteratehelpA#2\relax\fi
}
\def\chariteratehelpB#1#2\relax{%
  \charop{#1}%
  \ifx\relax#2\else
    \chariteratehelpB#2\relax%
  \fi
}
\def\squig{\scalebox{.85}[1]{\color{red}$\sim$}}
\def\charop#1{\def\stacktype{L}\def\useanchorwidth{T}%
  \stackon[0pt]{#1}{\stackanchor[3pt]{\squig}{\squig}}}
\let\crossout\chariterate
\begin{document}
The most \crossout{powerful} processor in your \crossout{computer} is probably the graphics processor 

\crossout{The most powerful processor in your computer is probably the graphics processor, especially extending over two lines.}
\end{document}

在此处输入图片描述

答案3

使用 TikZ 的不同方法:

\documentclass[a4paper,11pt]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\newcommand{\crossout}[1]{\raisebox{-0.2mm}{%
    \tikz{\draw(0,0) node[anchor=west,inner sep=0,text depth=0.2mm](crossedWord){#1};
        \draw[decorate,decoration={snake,amplitude=1pt}](crossedWord.west) -- (crossedWord.east)
    }}}
\begin{document}
The most \crossout{powerful} processor in your \crossout{computer} is probably the graphics processor.
\end{document}

这给出了下面的结果,并且可以通过改变振幅参数来调整波的大小。 使用 TikZ 进行交叉编辑

编辑: 要绘制两个波浪,可以使用以下命令。

\documentclass[a4paper,11pt]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,calc}
\newcommand{\crossout}[1]{\raisebox{-0.2mm}{%
    \tikz{\draw(0,0) node[anchor=west,inner sep=0,text depth=0.2mm](crossedWord){#1};
        \draw[decorate,decoration={snake,amplitude=1pt}](crossedWord.west) -- (crossedWord.east);
        \draw[decorate,decoration={snake,amplitude=1pt}]($(crossedWord.west)+(0,-1.5pt)$) -- ($(crossedWord.east)+(0,-1.5pt)$);
    }}}
\begin{document}
The most \crossout{powerful} processor in your \crossout{computer} is probably the graphics processor.
\end{document}

这将导致以下输出。 使用 TikZ 进行双波

第二次编辑:在对如何划掉单词产生了一些误解之后,这里有一个 TikZ 版本,用于创建带有波浪线的“X 型”划掉。

\documentclass[a4paper,11pt]{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\newcommand{\crossout}[1]{\raisebox{-0.2mm}{%
    \tikz{\draw(0,0) node[anchor=west,inner sep=0,text depth=0.2mm](crossedWord){#1};
        \draw[decorate,decoration={snake,amplitude=1pt}](crossedWord.north west) -- (crossedWord.south east);
        \draw[decorate,decoration={snake,amplitude=1pt}](crossedWord.south west) -- (crossedWord.north east);
    }}}
\begin{document}
The most \crossout{powerful} processor in your \crossout{computer} is probably the graphics processor.
\end{document}

使用 TikZ 制作波浪形 X-crossout

相关内容