Centering a plus sign at a particular coordinate

I’m trying to show a plus sign centered in a circle and can’t seem to do it… am I missing something obvious?

#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge, shapes

#diagram(
  node((0,0), align(horizon)[$+$], shape:shapes.circle, stroke: 1pt+black, width: 4mm, height:4mm),
)

image

Make it a block equation, then it will be optically aligned instead of aligned with the text baseline. :grinning: So like this:

node((0,0), $ + $, stroke: 1pt+black, radius: 2mm)
1 Like

Just in case you are trying to draw the xor symbol, it is pre-defined by typst and you can include it with any of the following (depending on the font, it’ll look different in/outside of math mode)

$xor$, #sym.xor, $plus.o$, #sym.plus.o

No, this is not the XOR symbol. It’s an adder, for a block diagram.

1 Like

That works! Could you elaborate? I don’t quite understand what’s different here.

Also, why does it fail to center here?

#diagram(
  edge-stroke: 0.3mm,
  mark-scale: 80%,
  spacing: 7.5mm,

  node([], enclose: ((1,0), (1,4)), shape:shapes.trapezium.with(dir:right, angle:30deg), stroke:1pt+black, width: 1cm, name:<muxout>),
  node((2,2), $ + $, stroke: 1pt+black, radius: 2mm, name:<sum>),
  edge(<muxout>, <sum>, "-|>")
)

or here:

#diagram(
  node([], enclose: ((1.2,3), (1.2,4)), shape:shapes.trapezium.with(dir:right, angle:30deg), stroke:1pt+black, width: 1cm, name:<muxout>),
  node((2,3.5), $+$, shape:shapes.circle, stroke: 1pt+black, radius: 2mm, name:<plusout>),
)

oh, it’s the $+$ vs $ + $

8/

In this case, the $ + $ isn’t perfectly centered because the node is forced to have a smaller radius than the size of the body plus the node’s inset, so it gets cramped and bugs out.

Instead, you make reduce the inset (aka padding) of the node and let the radius auto-fit to the content:

#diagram(
  edge-stroke: 0.3mm,
  mark-scale: 80%,
  spacing: 7.5mm,
  node-stroke: 1pt + black,

  node([], enclose: ((1,0), (1,4)), shape: shapes.trapezium.with(dir:right, angle:30deg), width: 1cm, name: <muxout>),
  node((2,2), $ + $, name: <sum>, inset: 0mm),
  edge(<muxout>, <sum>, "-|>")
)

1 Like

neat neat neat neat… every day I can use typst + fletcher instead of tikz is a good day :-)

1 Like