fletcher.node()

Place a node in a diagram or CeTZ canvas.

Nodes are content which edge()s can snap to. Nodes can have various shapes (rect, circle), styles (fill, stroke).

fletcher.node(
  ..args,
  body: content,
  shape: auto none string,
  fill,
  stroke,
  inset: length array dictionary,
  outset: length,
  extrude: array,
  layer: number,
  name: label str,
  align: alignment,
  weight: number,
  enclose: array,
  snap: bool,
  colspan: number none,
  rowspan: number,
  in-math: bool,
  debug,
)

body

content default none

Content to draw in the node.

This content is measured to automatically determine the size of the node. The "node.body" debug option shows the body’s bounding box after inset is applied.

shape

auto or none or string default auto

The shape of the node’s body enclosing its label.

Built-in shapes are "none", "rect", "circle", "ellipse", "pill", "parallelogram", "keystone", "diamond", "triangle", "house", "chevron", "hexagon", "octagon" and "cylinder".

Some node shapes accept other styling options which can be passed as arguments to node().

See also the Node shapes section of the manual.

fill

default auto

Fill style of the node.

The fill is drawn within the outline defined by the first extrude value. For example:

#diagram(
  node-fill: yellow,
  node-stroke: 1pt,
  node((0,0), [A], extrude: (0, 3)),
  node((1,0), [B], extrude: (3, 0)),
)

This option is a node style.

stroke

default auto

Stroke style for the node outline.

This option is a node style.

inset

length or array or dictionary default auto

Padding applied to the content in a node’s body.

The "node.inset" debug option draws a box around the body content before inset is applied.

The inset can be a length like 5pt, or a CeTZ-style array or dictionary: for example, (0, 5pt) for only horizontal padding; (left: 5pt, rest: 10pt) for per-edge padding.

This option is a node style.

outset

length default auto

Separation between the node’s visible outline and the snapping target for edges.

This does not affect the node’s appearance or layout, only how closely edges connect to it.

When "node.outset" debug option is on, the node outset drawn as a green dotted line.

#diagram(
  debug: "node.outset",
  node-stroke: 1pt,
  node((0,0), [Hello]),
  edge("<->"),
  node((1,0), [World], outset: 5pt, shape: "ellipse"),
)

This option is a node style.

See also edge.outset, which controls how closely individual edges connect to nodes.

extrude

array default auto

Draw strokes around the node at the given offsets to obtain a multi-stroke effect. Offsets can be numbers specifying multiples of the stroke’s thickness or lengths.

The node’s fill is drawn within the boundary defined by the first offset in the array.

This option is a node style.

layer

number default auto

Canvas layer to draw node on.

The default layer for nodes is 0, which is above edges (on layer -1 by default; see edge.layer). Enclose nodes are drawn on layer -2 by default, under nodes and edges. Nodes with equal layer are drawn in the order they are inserted.

This option is a node style.

name

label or str default none

Name of the node for use with coordinate anchors.

This can also be passed as a positional argument (but then the name must be a label, not a string).

align

alignment default center + horizon

Align a node within its associated flexigrid cell.

This only has effect when used inside a diagram() or flexigrid().

The node’s associated cell is visible when the "node.cell" debug option is enabled.

weight

number default 1

How much the node influences the size of flexigrid rows/columns.

If 0, the node does not affect the flexigrid or other node positions. If 1, rows and columns grow to fully accommodate the node.

enclose

array default none

Positions or names of nodes to be enclosed by this node.

When set, the node’s position must be unset (or auto). The node is automatically positioned and enlarged so that it encloses the specified nodes.

#diagram(
  node-stroke: 1pt,
  node((0,0), [ABC], name: <A>),
  node((1,1), [XYZ], name: <Z>),
  node(
    enclose: (<A>, <Z>),
    text(teal)[Enclose node], stroke: teal,
    name: <group>),
  edge(<group>, (3,0.5), stroke: teal),
)

snap

bool default true

Whether this node can have edges automatically snap to it.

colspan

number or none default none

The number of columns spanned by the node’s flexigrid cell.

The column span can be positive (meaning the cell grows rightwards) or negative (leftwards), or even fractional. The cell must span at least one column, so the range of this parameter is (,1][1,).

If the column span is not none, then node’s width defaults to the full size of its enclosing cell.

#diagram(
  spacing: 5pt,
  debug: "node.cell",
  node((0,0), colspan: 3, $x y z$),
  node((0,1), rowspan: 2, $x$),
  node((1,1), $y$),
  node((2,1), $z$),
  node((2,2), colspan: -2, $y z$)
)

See also rowspan and enclose.

rowspan

number default none

Row span of the node’s flexigrid cell.

Analogous to colspan.

in-math

bool default false

Whether to return a metadata object which can be placed inside equations, instead of returning an array of functions which can be inserted into a CeTZ canvas.

If you often use fletcher in math mode, consider defining a shortcut:

#let hom = edge.with(in-math: true)
#let obj = node.with(in-math: true)

Now, hom edges and obj nodes can be inserted into equations, like so:

#diagram($x hom(|->) & obj(pi(x), stroke: #yellow)$)

See also edge.in-math.

debug

default auto

Enable debug annotations for only this node. See Node debug options.

If auto, the debug setting is inherited from the enclosing diagram() or flexigrid().