Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

My use case is drawing a ticked box in line with normal text like this: "Hello ☒ World." (unicode example, your mileage may vary). One solution I managed to come up with is the following rather verbose expression.

Hello \tikz{
      \node[draw,rectangle,minimum size=1.5ex] {};
      \node[draw,cross out,minimum size=1.5ex] {};
} World.

Is there a more elegant way to describe this picture, for example by having the two shapes superimposed on one node?

Alternatively, is there any cross out path operation akin to rectangle, allowing something like the following?

\tikz \draw rectangle (1.5ex,1.5ex) cross out (0,0);

(N.B. This issue is mostly of aesthetic and academic nature, since the first example does indeed work as expected.)

Clarification: This is single-use so creating a new command is not what I'm after (thanks Peter).

share|improve this question
add comment

4 Answers

up vote 6 down vote accepted

enter image description here

Some explanations about the question and my answer : A node has only one shape, so to modify a shape associated to a node, you can define a new shape with \pgfdeclareshape and it's possible for example to combine two defined shapes and another solution is to modify the shape used. In the next code I added two lines to the rectangle. It's possible to do that with the path picture option. With this option, it's possible to use some anchors of the bounding box but others solutions are possible.

\documentclass{article}
\usepackage{tikz}

   \tikzset{squarecross/.style={draw,path picture={% 
      \draw[black]
       (path picture bounding box.north west) -- (path picture bounding box.south east) 
       (path picture bounding box.south west) -- (path picture bounding box.north east);
      }}}   

\begin{document}
Hello  \tikz \node[squarecross] (mynode) {}; World.
\end{document} 
share|improve this answer
    
A bit more verbose than what I was hoping for. Also, it appears that I only have PGF/TikZ 2.00 where /tikz/path picture does not exist. Shame. Still, good to know that technique. –  Fritz Mar 8 '12 at 17:23
    
Verbose no ! the style is not really in your code, you use only \tikz \node[squarecross] {};. There are others methods but you need in each way to define something in a style. 2.00 !! it's not serious ! :) Do you have a good reason to not update ? you need to update because there are a lot of interesting improvements. –  Alain Matthes Mar 8 '12 at 17:57
    
Not upgrading? Well, mostly due to laziness and not liking Ubuntu 11.10. Of course you're right about the \tikzset not being in the text. It's verbose however, if you think in terms of Code Golf. ;-) –  Fritz Mar 8 '12 at 18:42
    
Having thought about my question a bit more, I noticed that having two shapes on one node causes problems like conflicting anchors. So the only viable solution to have "two shapes on one node" is thus painting them yourself, as you have done. If you add that to your answer, I feel I can accept it. –  Fritz Mar 21 '12 at 14:22
    
@Fritz Sorry but I have some difficulties to understand your comment because my english is not enough efficace to understand subtleties. But here you can't get conflicting anchors because you have only one node (mynode). The cross does not modify the anchors. The cross completes the rectangle. The pgfmanual says : "the path picture is cleared at the beginning of each path". Can you explain differently the problem ? –  Alain Matthes Mar 21 '12 at 16:18
show 3 more comments

Not sure if this is any better, but you could just draw this shape:

enter image description here

\documentclass{article}
\usepackage{tikz}

\newcommand{\CrossOut}{%
    \tikz [x=1.5ex,y=1.5ex] 
        \draw (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle
         (0,0) -- (1,1)
         (0,1) -- (1,0)
        ;
}%

\begin{document}
Hello \CrossOut World.
\end{document}
share|improve this answer
    
Sorry, I neglected to mention that the scenario is single-use, so creating a new command is not what I was after. Still, thanks for pointing this out, for the sake of completeness. –  Fritz Mar 8 '12 at 17:01
add comment

Non-Tikz solution, using a \XBox symbol from the wasysym package, which I think is more elegant.

\documentclass{article}
\usepackage{wasysym}
\begin{document}
\CheckedBox  \Square  \Huge \XBox
\end{document}

The advantage of a non-Tikz solution is that the symbol can scale as per the font-size and is much simpler.

enter image description here

share|improve this answer
    
As far as I know the TikZ picture also scales with the font size when using ex or em lengths because these units are based on font metrics. Still, good to know that there are other ways. –  Fritz Mar 21 '12 at 14:59
    
@Fritz Sure I didn't mean that a TikZ solution will not scale. –  Yiannis Lazarides Mar 21 '12 at 15:01
    
@Fritz Why I wouldn't favour the TikZ solution is you loading a huge library for what is basically a font issue. Doesn't seem elegant and you did ask ... for unicode or other:) –  Yiannis Lazarides Mar 21 '12 at 15:03
    
That's a good point. For people who don't already use TikZ in their document this is probably the best solution. –  Fritz Mar 21 '12 at 16:10
add comment

For the sake of completeness, here's how I did it in the end. After some more thought, the following (based on Peter's answer) was the shortest solution for my single-use ticked box that I could think of.

Hello \tikz[x=1.1ex,y=1.1ex] \draw rectangle (1,1) -- (0,0) (1,0) -- (0,1); World.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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