# Using graphics primitives to draw a cross as inset in graphics

I would like to draw a cross as an inset in a Graphics environment. I tried the following:

Graphics[{Inset[Style["\[Cross]", 100], {0, 0},{Center,Center}], Circle[]},
Frame -> True]


Unfortunately, the {Center,Center} command for specifying the exact point of the cross that is drawn at the {0,0} position does not use the intercept of the two parts of the cross. Is there an easy way to produce a cross using graphics primitives rather than special characters? I have not done much with graphics yet and would really appreciate your help.

• When I evaluated your code on OS X using Mathematica V9, the cross was perfectly centered. Feb 5, 2013 at 23:16

Nice & easy:-

a = 0.2; t = 6;
Graphics[{Circle[],
Inset[Graphics[{AbsoluteThickness[t],
Line[{{-a, -a}, {a, a}}]}], {0, 0}, Center, 2 a],
Inset[Graphics[{AbsoluteThickness[t],
Line[{{-a, a}, {a, -a}}]}], {0, 0}, Center, 2 a]},
Frame -> True, ImageSize -> 250]


Using Inset ensures the resulting X stays within the 2 a bounds specified. The simpler red X shown, spills over slightly due to the thickness. The cross is also shown in green.

a = 0.2; t = 6;
Show[Graphics[{Circle[],
AbsoluteThickness[t], Red,
Line[{{-a, -a}, {a, a}}],
Line[{{-a, a}, {a, -a}}]},
Frame -> True, ImageSize -> 350],

Graphics[{Circle[],
Line[{{0, -1}, {0, 1}}],
Line[{{-1, 0}, {1, 0}}],
Line[{{a, -1}, {a, 1}}],
Line[{{-1, a}, {1, a}}],
Line[{{-a, -1}, {-a, 1}}],
Line[{{-1, -a}, {1, -a}}],
Inset[Style["\[Cross]", 100, Green], {0, 0}, {Center, Center}],
Inset[Graphics[{AbsoluteThickness[t],
Line[{{-a, -a}, {a, a}}]}], {0, 0}, Center, 2 a],
Inset[Graphics[{AbsoluteThickness[t],
Line[{{-a, a}, {a, -a}}]}], {0, 0}, Center, 2 a]},
Frame -> True, ImageSize -> 350]]


Inset X's can be made to scale. But first, using non-inset lines scales straight away:

a = 0.2; t = 6;
Graphics[{Circle[], AbsoluteThickness[t], Red,
Line[{{-a, -a}, {a, a}}], Line[{{-a, a}, {a, -a}}]},
Frame -> True, ImageSize -> 250, AspectRatio -> 0.4]


Inset lines' sizes are not affected by the enclosing graphic's AspectRatio:

a = 0.2; t = 6; r = 0.4;
Graphics[{Circle[], Inset[Graphics[{AbsoluteThickness[t],
Line[{{-a, -a}, {a, a}}]}], {0, 0}, Center, 2 a],
Inset[Graphics[{AbsoluteThickness[t],
Line[{{-a, a}, {a, -a}}]}], {0, 0}, Center, 2 a]},
Frame -> True, ImageSize -> 250, AspectRatio -> r]


Adding a factor to the insets can apply scaling:

a = 0.2; t = 6; r = 0.4;
Graphics[{Circle[], Inset[Graphics[{AbsoluteThickness[t],
Line[{{-a, -a r}, {a, a r}}]}], {0, 0}, Center, 2 a],
Inset[Graphics[{AbsoluteThickness[t],
Line[{{-a, a r}, {a, -a r}}]}], {0, 0}, Center, 2 a]},
Frame -> True, ImageSize -> 250, AspectRatio -> r]


• Using inset also makes it possible to locate the cross anywhere: a = 0.2; t = 6; Graphics[{Circle[], Inset[Graphics[{AbsoluteThickness[t], Line[{{-a, -a}, {a, a}}]}], {1, 0}, Center, 2 a], Inset[Graphics[{AbsoluteThickness[t], Line[{{-a, a}, {a, -a}}]}], {1, 0}, Center, 2 a]}, Frame -> True, ImageSize -> 250] shifts the cross to the right. Feb 5, 2013 at 15:42
• Just out of interest: why does the cross stay symmetrically if I combine it with a plot with differently scaled axes? Doesn't the a refer to the values of the x and y values where the lines of the cross end? Feb 5, 2013 at 16:00
• @Apatura - You could add aspect ratios to the insets, or scale them as shown in the addendum to my post. Feb 5, 2013 at 18:28
• Interestingly, the green cross is not offset on Mac OSX. Feb 5, 2013 at 18:30
• Thank you very much, your answer definitely helped me understanding the use of the Graphics and Inset options. Feb 5, 2013 at 22:05

\[Cross] is rendered with a font glyph. The center of the glyph is not absolute but rather in terms of typographic positioning. For example the glyph for , will be rendered lower on a line than the glyph for ^ -- this is not an error. If you wish to center a glyph you need to specify appropriate offsets for the third parameter of Inset. For example on my system (10.0.2 under Windows):

Graphics[
{Inset[Style["\[Cross]", 100], {0, 0}, {0, -0.13}], Circle[]},
Frame -> True, GridLines -> {{0}, {0}}
]