32

If I do

\draw (1,1) circle (1pt)

tikz draw a little circle with diameter 1pt at (1,1).

How can I define a path cross such that

\draw (1,1) cross (1pt)

draws a little cross with diameter 1pt (adjustable in size just like the circle)?

student
  • 29,003
  • 2
    if a node is OK, you can take a look ad http://tex.stackexchange.com/a/15162/1952 or http://tex.stackexchange.com/a/47281/1952. There is also a cross out node in shapes.misc library (look at last example in http://tex.stackexchange.com/a/54856/1952). – Ignasi Jul 12 '13 at 14:49
  • 1
    @Ignasi you should turn your comment into an answer ;-) – Gonzalo Medina Jul 14 '13 at 01:28

3 Answers3

55

cross command equivalent to circle doesn't exist in TiKZ but you can use a cross out node from shapes.misc library. This kind of node adds a cross over node's text, but it's easy to adapt it to do what you want.

\tikzset{cross/.style={cross out, draw, 
         minimum size=2*(#1-\pgflinewidth), 
         inner sep=0pt, outer sep=0pt}}

Because circle (1pt) draws a circle with radius=1pt, its total size will be 2pt, then cross node's size is defined with minimum size=2*(#1-\pgflinewidth) and inner and outer separations fixed to 0pt.

If cross angle is not what you want, you can change it with rotate option. Next you have some examples. I've also placed circles over them just to show that circle and crosses have equal size.

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.misc}

\tikzset{cross/.style={cross out, draw=black, minimum size=2*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt},
%default radius will be 1pt. 
cross/.default={1pt}}

\begin{document}
\begin{tikzpicture}[]

\draw (0,0) circle (1pt);

\draw (.5,0) node[cross,rotate=10] {};
\draw (.5,0) circle (1pt);

\draw (0,.5) circle (1pt);
\draw (0,.5) node[cross,red] {};

\draw (.5,.5) node[cross,rotate=30] {};

\draw (0.25,.25) circle (2pt);
\draw (0.25,.25) node[cross=2pt,rotate=45,green]{};
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588
  • Additional note: If somebody wanted a thicker cross, you could change that with the line width option. – mivkov Mar 04 '22 at 12:39
  • Could you provide an example? My cross just disappears after specifying the line width – Huhngut Dec 31 '23 at 12:59
  • @Huhngut Make sure the cross size is larger than the line width or else it won't be visible. In practice, the cross size should probably be at least double the line width to resemble an actual cross. – tdy Feb 05 '24 at 16:27
  • e.g., \draw (0.5, 0.25) node[cross=4pt, line width=2pt] {}; – tdy Feb 05 '24 at 16:28
2

Alternative solution using pic:

\documentclass[]{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\tikzset{
    cross/.pic = {
    \draw[rotate = 45] (-#1,0) -- (#1,0);
    \draw[rotate = 45] (0,-#1) -- (0, #1);
    }
}

\begin{document}



\begin{tikzpicture}

    \draw (0,0) circle (1pt);

    \path (.5,0) pic[rotate = 10] {cross=1pt};
    \draw (.5,0) circle (1pt);

    \draw (0,.5) circle (1pt);
    \path (0,.5) pic[red] {cross=1pt};

    \draw (.5,.5) pic[rotate = 30] {cross=1pt};

    \draw (0.25,.25) circle (2pt);
    \draw (0.25,.25) pic[rotate=45,green] {cross=2pt};
\end{tikzpicture}

\end{document}

enter image description here

Angelos
  • 291
  • Notice that this solution always requires specification of the cross size. Is there anyone who knows how to modify this solution to add a default size? – Angelos Oct 15 '19 at 08:58
  • You can use \tikzset{pics/cross/.style args={#1}{code={...}}, pics/cross/.default=0.1} for a cross with default size 0.1cm. Substitute the ... by the definition. – DerWeh Oct 21 '21 at 13:12
1

You can write an "x" at the respective position:

\draw (1,1) node {x};

You can then adjust the size using font sizes like this:

\draw (1,1) node {\Huge x};

The center of the 'x' actually is placed exactly at the given coordinates.