4

I am wondering if there exists any command in LaTeX with which one can put a cross mark on a word?

  • 3
    What do you mean by cross mark on*? Please, give an image as example. – Sigur Feb 16 '18 at 20:21
11

With the help of TikZ (and shapes library), it is possible to make some nice cross out effects.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\crossme}[2][]{%


\tikz[baseline=(X.base)]{\node [outer sep=0pt,cross out,draw=#1,line width=2pt] (X) {#2};}%
}


\begin{document}
A nice \crossme[blue]{crossed} word.
\end{document}

enter image description here

| improve this answer | |
  • @CarLaTeX: I know, it was written in a hurry ;-) – user31729 Feb 16 '18 at 20:28
  • It works Thanks :) One small problem. For me A nice remains in the first line and the rest go to the next line!!!! I am working in Beamer – Majid Feb 16 '18 at 20:35
  • @Majid: Why is that a problem? – Werner Feb 16 '18 at 20:47
  • @Werner Because imagine it breaks a line in a unnecessary place! – Majid Feb 17 '18 at 13:49
11

Just for completeness: \xcancel from the cancel package also works.

\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}

enter image description here

UPDATE: Really just for fun: a version that works with line breaks (but not page breaks!) and does not introduce additional spaces. Based on this answer.

\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}

enter image description here

The properties of the line can be customized by adjusting StrikeOut.

| improve this answer | |
  • “and does introduce additional spaces” ...does or does not? – Andrea Lazzarotto Feb 17 '18 at 14:47
  • 1
    does not. Thanks a lot for catching this! – user121799 Feb 17 '18 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.