Neural Sketch
Commands

nsk@Container

Comprehensive reference for the `\nskContainer` command in Neural Sketch.

Overview

The \nskContainer macro is a powerful primitive in Neural Sketch, enabling styled grouping of diagram elements with automatic bounding box computation, background styling, padding, rotation, scaling, and precise relative positioning. Containers ensure diagram components stay visually and structurally coherent, particularly in complex diagrams or hierarchical visualizations.

nsk@Container(s) are built on top of nsk@Group

Basic Usage

A minimal container encapsulating diagram components:

\nskContainer[]{
  % Diagram components here
}

Advanced Example

An advanced use-case showcasing rotations, padding, and relative positioning:

\begin{nskFigure}
  \nskBlock[id=refBlock, text-center={Reference}]
 
  \nskContainer[
    id=myContainer,
    pos={below=1cm of refBlock},
    rotate=15,
    padding=4mm,
    border-color=nskRed,
    fill=nskRed!50,
    border-type=dashed
  ]{
    \nskBlock[id=A, text-center={A}]
    \nskBlock[last-pos={right=1cm}, text-center={B}]
  }
\end{nskFigure}

Available Keys

Identity

  • id (string, optional): Assign a unique identifier for referencing or positioning.
\nskContainer[id=group1]{...}

Styling

  • border-type (string, default=solid): Specifies border style (solid, dashed, none).
\nskContainer[border-type=dashed]{...}
  • border-color (color, default=nskLighterGray): Container border color.
\nskContainer[border-color=nskRed]{...}
  • fill (color, default=nskLightestGray): Background fill color.
\nskContainer[fill=nskOrange!20]{...}
  • padding (dimension, default=0.5cm): Padding around grouped content.
\nskContainer[padding=2mm]{...}

Transformations

  • rotate (number, default=0): Rotation angle of the container (degrees).
\nskContainer[rotate=30]{...}
  • scale (number, default=1): Uniform scaling of container content.
\nskContainer[scale=1.2]{...}
  • shift-x, shift-y (number, default=0): Horizontal and vertical displacement.
\nskContainer[shift-x=1, shift-y=-1]{...}

Positioning

  • pos (coordinate, default={}): Precise positioning relative to another node. Automatically computes internal spacing based on padding.
\nskContainer[pos={right=2cm of nodeA}]{...}

Container positioning (pos) intelligently accounts for padding, ensuring content maintains comfortable margins.

Advanced Group Options

  • group-opts (token list, optional): Pass additional group options to nsk@Group for advanced customization.
\nskContainer[group-opts={opacity=0.8}]{...}

Internal Mechanics

Internally, \nskContainer:

  • Computes bounding boxes around enclosed elements automatically.
  • Supports nested transformations (scale, rotate, translate) seamlessly.
  • Supports any-shape padding and clipping.
  • Supports multi-layering.

Practical Use Cases

Grouped Visualizations

Use containers to visually encapsulate related blocks, enhancing readability:

\nskContainer[text-north={Grouped Blocks}, padding=1cm]{
  \nskBlock[id=A, text-center={A}]
  \nskBlock[last-pos={right=}, text-center={B}]
}

Reference Table

PropTypeDefault
id?string
border-type?stringsolid
border-color?colornskLighterGray
fill?colornskLightestGray
padding?dimension0.5cm
rotate?number0
scale?number1
shift-x?number0
shift-y?number0
pos?coordinate{}
group-opts?token list{}

On this page