nsk@Group
Comprehensive reference for the `\nskGroup` command in Neural Sketch.
Overview
The \nskGroup
macro provides a powerful and intuitive way to logically group diagram components within Neural Sketch, facilitating advanced transformations such as rotation, scaling, and precise relative positioning. By wrapping elements in a cohesive group, users can effortlessly control collective styling and spatial arrangement, ensuring visual coherence in complex diagrams.
Basic Usage
The minimal syntax for grouping elements is:
Advanced Example
Below is a practical example demonstrating multiple grouped blocks with transformations:
Available Options
Positioning
pos
(coordinate
, default={}
): Specifies the group position relative to another element.
last-pos
(coordinate
, default={}
): Sets the position relative to the previous block or group, simplifying chained positioning.
Use explicit positioning with pos
or last-pos
for precise alignment and layout consistency.
Transformations
rotate
(number
, default=0
): Rotates the entire group around its center.
scale
(number
, default=1
): Scales the group uniformly.
shift-x
,shift-y
(number
, default=0
): Shifts the group horizontally or vertically.
Anchoring and Alignment
pos-align
(string
, default={}
): Explicitly defines the anchor alignment, overriding automatic detection.
Boundaries
bounds-name
(string
, default=__nsk_container_bounds
): Internally defines a local bounding box name for advanced referencing or later transformations.
Internal Mechanics
Internally, \nskGroup
:
- Generates a local bounding box, allowing precise relative positioning.
- Supports comprehensive alignment logic, automatically adjusting anchor positions based on provided directions.
- Allows forward compatibility with TikZ options by passing unrecognized keys directly to TikZ scopes.
- Automatically manages phantom reference nodes to ensure seamless positioning without visual artifacts.
Positioning Logic
Smart Anchor Detection
Neural Sketch analyzes your positioning directives and automatically determines suitable anchors:
- Example:
This automatically aligns the group's anchor appropriately (south-west by default in the above example) to facilitate precise positioning.
Last-Position Convenience
Quickly place groups relative to the preceding diagram element:
Ensure preceding elements are explicitly named or previously created to avoid compilation warnings.
Practical Use Cases
\nskGroup
proves invaluable in scenarios such as:
- Composite elements: Bundling multiple blocks to form a logical sub-diagram.
- Rotated annotations: Grouping annotations or labels to rotate collectively, maintaining relative placements.
- Scalable components: Reusable diagram sections that adjust uniformly across different figures.
Advanced Tips
Combine transformations for sophisticated layout effects:
Error Handling and Troubleshooting
- Ensure coordinates and references are correctly defined.
- Explicitly define block identifiers to avoid confusion in chained positioning.
- Avoid overly complex nested transformations without clear intermediate steps.
The internal phantom reference node (__nsk_phantom_refnode
) is hidden, ensuring groups align smoothly without visual clutter.
Reference Table
Prop | Type | Default |
---|---|---|
bounds-name? | string | __nsk_container_bounds |
pos? | coordinate | {} |
last-pos? | coordinate | {} |
pos-align? | string | {} |
shift-x? | number | 0 |
shift-y? | number | 0 |
rotate? | number | 0 |
scale? | number | 1 |
Integrating \nskGroup
into your workflow enhances flexibility and expressive power, empowering users to create sophisticated, publication-ready diagrams with ease and precision.