Neural Sketch
Commands

nsk@Onlayer

Precise layer-based drawing control for Neural Sketch diagrams.

Overview

The macros \nskOnlayer, \nskOnbg, and \nskOnfg provide intuitive yet powerful mechanisms for precise layer management within Neural Sketch diagrams. Leveraging TikZ's built-in layering system, these macros enable fine-grained control over the drawing order and placement of diagram elements, essential for creating clear, structured, and visually appealing diagrams.

Usage

\nskOnlayer

This general macro explicitly places provided content onto a specified TikZ layer:

\nskOnlayer{<layer-name>}{
  % content here
}
  • <layer-name>: The name of a valid, predefined TikZ layer.
  • Content: Any valid Neural Sketch or TikZ code intended for explicit layering.

Predefined Layer Shortcuts

For common use cases, Neural Sketch provides two convenient shortcuts:

  • Background Layer (background): Use \nskOnbg
  • Foreground Layer (foreground): Use \nskOnfg

Background Layer (\nskOnbg)

Quickly positions content explicitly on the background layer:

\nskOnbg{
  % content drawn on background layer
}

Foreground Layer (\nskOnfg)

Positions content explicitly on the foreground layer, ideal for annotations or elements requiring visual prominence:

\nskOnfg{
  % content drawn on foreground layer
}

Examples

Basic Layering

Placing annotations clearly on the foreground:

\begin{nskFigure}
  \nskBlock[id=A, text-center={Block A}]
 
  \nskOnfg{
    \node[below right=0.2cm of A.south east] {Foreground annotation};
  }
\end{nskFigure}

Background Decoration

Adding subtle backgrounds behind primary diagram elements:

\begin{nskFigure}
  \nskBlock[id=mainBlock, fill=nskBlue!20, text-center={Main Block}]
 
  \nskOnbg{
    \nskBlock[
      fill=nskRed!20,
      x=0, y=0,
      width=4cm, height=4cm,
      text-north={Secondary Block},
    ]
  }
\end{nskFigure}

Layer Definitions and Management

By default, Neural Sketch leverages the TikZ predefined layers:

  • background
  • main (default layer)
  • foreground

The default layer order is background -> main -> foreground. Content placed explicitly with \nskOnlayer, \nskOnbg, or \nskOnfg respects this hierarchy.

Custom Layers

If additional layer granularity is required, you may define custom layers in your document preamble:

\pgfdeclarelayer{customlayer}
\pgfsetlayers{background, main, customlayer, foreground}

Use the newly defined layer explicitly:

\nskOnlayer{customlayer}{
  % elements explicitly drawn on 'customlayer'
}

Practical Use Cases

  • Annotations and Labels: Clearly position annotations, ensuring readability and clarity without visual interference.
  • Decorative Elements: Control decorative backgrounds or highlights to emphasize structural or semantic groupings.
  • Complex Diagrams: Precisely orchestrate drawing sequences to visually distinguish overlapping or nested diagram components.

Tips & Best Practices

  • Consistency: Regularly use layers to maintain visual clarity, especially in intricate diagrams.
  • Performance: While explicit layering is efficient, avoid unnecessary complexity that might impact compilation.

Ensure the layers you reference are explicitly defined or included by default to avoid LaTeX compilation errors.

Reference Table

PropTypeDefault
layer-namestring{}
contentLaTeX code{}

On this page