Neural Sketch

Measure

Precisely measure distances and align blocks effortlessly with Neural Sketch.

Precision is powerfulbut it shouldn’t be painful.

\nskMeasure gives you a declarative way to measure distances between points and immediately reuse the result, making alignment and sizing in your diagrams consistent and effortless.

Overview

The \nskMeasure command provides a powerful yet intuitive mechanism to accurately measure distances and align diagram components within your Neural Sketch diagrams. Whether you need blocks of precisely matching sizes, exact spacing between elements, or consistent alignment, this command simplifies your workflow.

Basic Usage

To measure distances between two points or anchor coordinates, use the \nskMeasure macro as follows:

\nskMeasure[
  axis=horizontal, % Axis along which to measure (horizontal or vertical)
  from={a.south west}, % Starting anchor
  to={b.south east}, % Ending anchor
]

Once you've performed the measurement, you can immediately reuse the resulting length via the built-in macro \nskDistance.

Example: Matching Block Widths

Here's how you can measure the width between two blocks and then set a new block to precisely match that measured width:

% Measure distance horizontally from block 'a' to block 'b'
\nskMeasure[
  axis=horizontal,
  from=a.west, to=b.east,
]
 
% Create a new block 'c' with exactly the measured width
\nskBlock[
  id=c, text-center=$A+B$,
  width=\nskDistance,
]

This ensures c matches precisely the combined width of a and b, providing visual consistency and exact alignment across your diagram elements.

Measurement unlocks reuse. Instead of guessing sizes or manually syncing blocks, you can anchor your layout to relationships that already exist in your drawing.

Multiple measurement

You can store a measurement into a custom-named macro using the into= parameter:

\nskMeasure[
  from=a.west, to=b.east,
  into=<macro-name>
]

You can now reference the measurement using \<macro-name> wherever you need that value.

This is particularly useful when comparing or combining multiple distances:

examples-doc/measure-i.tex
\nskBlock[id=a, text-center=A, fill=nskGreen]
\nskBlock[id=b, text-center=B, last-pos={right=4cm}, fill=nskRed]
 
\nskMeasure[from=a.west, to=b.east, into=oab] % outer %
\nskMeasure[from=a.east, to=b.west, into=iab] % inner %
 
\nskWrapUnder[a]
\nskBlock[id=c, text-center=C, width=\oab, fill=nskSecondaryAccent]
 
\nskConnect[id=abc, from=a, to=b, arrow-tip=|<->|]
\nskConnect[id=aboc, from=a.north west, to=b.north east, arrow-tip=|-|, shift-y=5mm]
\nskMarkPath[at=.5]{abc}{\node[above]{\iab};}
\nskMarkPath[at=.5]{aboc}{\node[above]{\oab};}

Available Options

OptionTypeDescriptionDefault
axisEnum (horizontal, vertical)Axis along which the measurement is taken.horizontal
fromAnchorStarting anchor coordinate for measurement.required
toAnchorEnding anchor coordinate for measurement.required
intoMacro nameCustom macro name to store the result.\nskDistance

Practical Use Cases

  • Consistent Spacing: Maintain equal spacing between elements across your figures.
  • Dynamic Sizing: Create adaptive blocks or containers that adjust sizes based on other elements.
  • Perfect Alignment: Ensure elements line up precisely, essential for professional-quality diagrams.
  • Path-based repetition: Combine with \nskMarkPath to step through measured space.
  • Multi-scale diagrams: Compare, annotate, or overlay relative distances.

Tip

Use clear names and label your measurements with annotations if they represent a meaningful constraint. Treat spacing like a design material.

Composability

Any value measured with \nskMeasure — whether \nskDistance or a custom macro — is just a dimension. Use it for width, padding, spacing, path control, or anything else.

Reference

PropTypeDefault
axis?choicehorizontal
from?token list{}
to?token list{}
into?string\nskDistance

On this page