7

I have figured out how to add a cross over words with tcolorbox

\documentclass{article}\usepackage{xcolor} \usepackage[most]{tcolorbox}

\begin{document}

Of course, presenting this solution would be cheating. And, no, it won't work in all cases, due to strict limitations on the pairs 
\tcbox[tcbox raise base,
breakable,nobeforeafter, enhanced jigsaw, opacityback=0, sharp corners, parbox=false, boxrule=0pt, top=0pt,bottom=0pt,left=0pt,right=0pt, boxsep=0pt, frame hidden, parbox=false, 
  finish={\draw[thick,red] (frame.south west)--(frame.north east);\draw[thick,red] (frame.south east)--(frame.north west);}]{
  accepted
  }
  by \textbackslash{}line. Your professor surely knows that TeX doesn't draw oblique lines. With the standard package pict2e it's easier and it will work in any case.

\end{document}

enter image description here

Here I cross out word accept. However, I want the cross to stretch out a bit, say 1cm, see my illustration.

enter image description here

How can I achieve that?

2
  • Off topic: use \verb|\line| instead of \textbackslash{}line; use \TeX{} instead of TeX and use \verb|pict2e| instead of pict2e.
    – user156344
    Mar 9, 2019 at 9:25
  • @JouleV thanks, but just copied random text on texoverflow for illustration purpose.
    – Gqqnbig
    Mar 9, 2019 at 9:34

3 Answers 3

7

You can shorten your lines.

shortened

\documentclass{article}\usepackage{xcolor} \usepackage[most]{tcolorbox}

\tikzset{crossout/.style={thick,red,shorten >=-.5cm,shorten <=-.5cm}}

\begin{document}

Of course, presenting this solution would be cheating. And, no, it won't work in all cases, due to strict limitations on the pairs 
\tcbox[tcbox raise base,
breakable,nobeforeafter, enhanced jigsaw, opacityback=0, sharp corners, parbox=false, boxrule=0pt, top=0pt,bottom=0pt,left=0pt,right=0pt, boxsep=0pt, frame hidden, parbox=false, 
  finish={\draw[crossout] (frame.south west)--(frame.north east);\draw[crossout] (frame.south east)--(frame.north west);}]{
  accepted
  }
  by \textbackslash{}line. Your professor surely knows that TeX doesn't draw oblique lines. With the standard package pict2e it's easier and it will work in any case.

\end{document}
2
  • Awesome!! Can you add a bit explanation? I'm new to this package, I didn't find explanation of \tikzset in the package documentation. Can you explain that? Also what is /.?
    – Gqqnbig
    Mar 9, 2019 at 9:40
  • @Gqqnbig Which documentation are you reading? \tikzset is defined in the tikz package which you are using for the overlays (finish in this case). And a negative shorten just extends one end of the line.
    – TeXnician
    Mar 9, 2019 at 9:47
6

An alternative TikZ solution (less elegant than TeXnician's one).

With overlay you can write over something without occupy space.

I've used shift to enlarge the lines (you can use shorten also here, but I haven't used it because TeXnician already did it, hence I would like to show an alternative).

To align TikZ nodes to normal text, see here: TikZ node in normal text.

\documentclass{article}\usepackage{xcolor} \usepackage{tikz}
\newcommand{\mycrossed}[1]{%
    \tikz[remember picture, baseline=(A.base)]{
        \node[inner sep=0pt](A){#1};
        }%
    \tikz[overlay, remember picture]{
        \draw[red, very thick] ([shift={(-.5,.2)}]A.north west) -- ([shift={(.5,-.2)}]A.south east);
        \draw[red, very thick] ([shift={(-.5,-.2)}]A.south west) -- ([shift={(.5,.2)}]A.north east);
        }%
    }
\begin{document}

Of course, presenting this solution would be cheating. And, no, it won't work in all cases, due to strict limitations on the pairs 
\mycrossed{accepted}
  by \textbackslash{}line. Your professor surely knows that TeX doesn't draw oblique lines. With the standard package pict2e it's easier and it will work in any case.
\end{document}

enter image description here

1

In May 2019 (pgf version 3.1.3) tikz already has the cross out shape in its shapes.misc library.

The following code and figure is taken from Section 71.8 of the manual.

\begin{tikzpicture}
\draw [help lines] (0,0) grid (3,2);
\node [cross out,draw=red] at (1.5,1) {cross out};
\end{tikzpicture}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .