我想知道 LaTeX 中是否存在可以在單字上打十字標記的命令?
答案1
答案2
只是為了完整性:\xcancel
從cancel
包中也可以。
\documentclass{beamer}
\usepackage{cancel}
\begin{document}
\begin{frame}
\frametitle{Crossing out words}
\begin{overlayarea}{\textwidth}{\textheight}
No more \xcancel{alcohol}. No more
\textcolor{red}{\xcancel{\textcolor{black}{fast food}}}.
\end{overlayarea}
\end{frame}
\end{document}
更新:真的只是為了好玩:一個可以使用換行符(但不能使用分頁符號!)並且不會引入額外空格的版本。基於這個答案。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{tikzpagenodes}
\usepackage{ulem}
\newcommand\HighLight{\bgroup\markoverwith{\textcolor{yellow}{\rule[-.5ex]{.1pt}{2.5ex}}}\ULon}
\tikzset{StrikeOut/.style={thick,-}}
\makeatletter
\newcommand{\gettikzxy}[3]{% from https://tex.stackexchange.com/a/58590/121799
\tikz@scan@one@point\pgfutil@firstofone#1\relax
\global\edef#2{\the\pgf@x}%
\global\edef#3{\the\pgf@y}%
}
\makeatother
\newcommand{\StrikeOut}[2][2pt]{%
\tikz[remember picture,overlay, baseline=(Begin.base)]{%
\node[anchor=base,inner sep=0pt,outer sep=0pt] (Begin) {\strut};}#2%
\tikz[remember picture,overlay, baseline=(End.base)]{%
\node[anchor=base,inner sep=0pt,outer sep=0pt] (End) {\strut};}%
\begin{tikzpicture}[overlay,remember picture]
\gettikzxy{($(Begin.north)-(current page.south west)$)}{\BeginxN}{\BeginyN}
\gettikzxy{($(End.north)-(current page.south west)$)}{\EndxN}{\EndyN}%\typeout{\BeginyN\space\EndyN}
\pgfmathtruncatemacro{\mytest}{\EndyN-\BeginyN}
\ifnum\mytest=0\relax% begin and and in the same line %\typeout{begin and end in the same line}
\draw[StrikeOut] (Begin.north) -- (End.south);
\draw[StrikeOut] (Begin.south) -- (End.north);
\else% \typeout{end below begin}
\path (current page text area.north west) -- (current page text area.south west)
node(WestLine)[left]{};
\path (current page text area.north east) -- (current page text area.south east)
node(EastLine)[right]{};
\gettikzxy{($(End.north)-(current page.south west)$)}{\EndxN}{\EndyN}
\gettikzxy{($(Begin.south)-(current page.south west)$)}{\BeginxS}{\BeginyS}
\pgfmathtruncatemacro{\mytest}{\BeginyS-\EndyN+1pt}% \typeout{\mytest}
\ifnum\mytest<2\relax% \typeout{end in the next line after begin}%
\pgfmathtruncatemacro{\mytest}{\BeginxS-\EndxN}% \typeout{\mytest}
\ifnum\mytest>0\relax
\draw[StrikeOut] (Begin.north) -- (Begin.south -| EastLine);
\draw[StrikeOut] (Begin.south) -- (Begin.north -| EastLine);
\draw[StrikeOut] (End.north -| WestLine) -- (End.south);
\draw[StrikeOut] (End.south -| WestLine) -- (End.north);
\else
\draw[StrikeOut] (Begin.south) -- (Begin.north -| EastLine);
\draw[StrikeOut] (Begin.north) -- (Begin.south -| EastLine);
\draw[StrikeOut] (End.north -| WestLine) -- (End.south);
\draw[StrikeOut] (End.south -| WestLine) -- (End.north);
\fi
\else
\pgfmathsetmacro{\LineHeight}{\the\baselineskip}
\pgfmathtruncatemacro{\NumLines}{-1+(\BeginyN-\EndyN)/\LineHeight}
\typeout{\NumLines}
\foreach \X in {1,...,\NumLines}
{
\draw[StrikeOut] ($(Begin.north -| WestLine)+(0,-\X*\LineHeight pt)$) --
($(Begin.south -|EastLine)+(0,-\X*\LineHeight pt)$);
\draw[StrikeOut] ($(Begin.south -| WestLine)+(0,-\X*\LineHeight pt)$) --
($(Begin.north -|EastLine)+(0,-\X*\LineHeight pt)$);
}
\draw[StrikeOut] (Begin.north) -- (Begin.south -| EastLine);
\draw[StrikeOut] (Begin.south) -- (Begin.north -| EastLine);
\draw[StrikeOut] (End.north -| WestLine) -- (End.south);
\draw[StrikeOut] (End.south -| WestLine) -- (End.north);
\fi
\fi
\end{tikzpicture}}
\begin{document}
\begin{frame}
\frametitle{Striking out several lines}
\begin{overlayarea}{\textwidth}{\textheight}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. \StrikeOut{Sed a leo ut
erat luctus scelerisque. Suspendisse auctor mauris sit amet fringilla
hendrerit.} Maecenas eu tortor eu diam fringilla scelerisque sit amet eget enim.
Nam vitae bibendum erat, sit amet scelerisque felis. \StrikeOut{Suspendisse placerat
vitae velit pharetra lobortis et marmottae.} Donec ut erat a erat porta aliquet. Nulla eget
augue sem. Proin orci neque, eleifend id eleifend id, venenatis sit amet diam.
\StrikeOut{Mauris lacus est, cursus eget sapien at, pharetra lobortis ante. Proin
tempus ipsum tellus, ut ultricies magna congue nec. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse potenti.
In posuere dapibus urna, vitae euismod magna iaculis at.} Pellentesque pretium,
lorem ut vehicula egestas, velit dolor porta nunc, id interdum ipsum purus vel
dolor.
\end{overlayarea}
\end{frame}
\begin{frame}
\frametitle{Striking out several lines (no strike out)}
\begin{overlayarea}{\textwidth}{\textheight}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a leo ut
erat luctus scelerisque. Suspendisse auctor mauris sit amet fringilla
hendrerit. Maecenas eu tortor eu diam fringilla scelerisque sit amet eget enim.
Nam vitae bibendum erat, sit amet scelerisque felis. Suspendisse placerat
vitae velit pharetra lobortis et marmottae. Donec ut erat a erat porta aliquet. Nulla eget
augue sem. Proin orci neque, eleifend id eleifend id, venenatis sit amet diam.
Mauris lacus est, cursus eget sapien at, pharetra lobortis ante. Proin
tempus ipsum tellus, ut ultricies magna congue nec. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse potenti.
In posuere dapibus urna, vitae euismod magna iaculis at. Pellentesque pretium,
lorem ut vehicula egestas, velit dolor porta nunc, id interdum ipsum purus vel
dolor.
\end{overlayarea}
\end{frame}
\end{document}
可以透過調整來自訂線路的屬性StrikeOut
。