Underleaf Logo
Underleaf
PricingAboutBlog
Log InGet started

Learn TikZ

Getting Started

  • What is TikZ?
  • TikZ for Beginners
  • Basic Setup

Nodes and Labels in TikZ

Master adding text, labels, and styled nodes to your TikZ diagrams.

Basic Nodes

Nodes are the primary way to add text to TikZ drawings:

\begin{tikzpicture} % Simple text node \node at (0,0) {Hello World}; % Node with border \node[draw] at (3,0) {Boxed Text}; % Colored and filled node \node[draw=blue, fill=blue!20] at (6,0) {Blue Box}; % Node with name for referencing \node (mynode) at (0,-1.5) {Named Node}; \end{tikzpicture}

Node Shapes

Use different shapes for nodes (requires shapes.geometric library):

\usetikzlibrary{shapes.geometric} \begin{tikzpicture} % Rectangle (default) \node[draw, rectangle] at (0,0) {Rectangle}; % Circle \node[draw, circle] at (3,0) {Circle}; % Ellipse \node[draw, ellipse] at (6,0) {Ellipse}; % Diamond \node[draw, diamond] at (0,-1.5) {Decision}; % Rounded rectangle \node[draw, rounded corners] at (3,-1.5) {Rounded}; % Regular polygon \node[draw, regular polygon, regular polygon sides=6] at (6,-1.5) {Hex}; \end{tikzpicture}

Node Size Options

\begin{tikzpicture} % Minimum dimensions \node[draw, minimum width=3cm, minimum height=1cm] at (0,0) {Fixed Size}; % Inner separation (padding) \node[draw, inner sep=10pt] at (5,0) {More Padding}; % Outer separation (margin for connections) \node[draw, outer sep=5pt] at (0,-2) {Outer Sep}; % Text dimensions \node[draw, text width=3cm, align=center] at (5,-2) {This text wraps to multiple lines}; \end{tikzpicture}

Node Positioning

Position nodes relative to other elements:

\begin{tikzpicture} \draw (0,0) -- (4,0); % Position relative to point \node[above] at (2,0) {Above}; \node[below] at (2,0) {Below}; \node[left] at (0,0) {Left}; \node[right] at (4,0) {Right}; % Combined positions \node[above right] at (4,0) {Above Right}; \node[below left] at (0,0) {Below Left}; % With distance \node[above=5pt] at (2,0) {5pt Above}; \end{tikzpicture}

Positioning Library

The positioning library enables powerful relative positioning:

\usetikzlibrary{positioning} \begin{tikzpicture}[node distance=2cm] % First node \node[draw] (a) {Node A}; % Relative to first node \node[draw, right=of a] (b) {Node B}; \node[draw, below=of a] (c) {Node C}; \node[draw, below right=of a] (d) {Node D}; % Custom distance \node[draw, right=3cm of b] (e) {Node E}; % Combined with offset \node[draw, below=1cm and 2cm of a] (f) {Node F}; \end{tikzpicture}

Node Anchors

Each node has anchor points for precise positioning and connections:

AnchorDescription
centerCenter of the node
northTop center
southBottom center
eastRight center
westLeft center
north eastTop right corner
north westTop left corner
south eastBottom right corner
south westBottom left corner
\begin{tikzpicture} \node[draw, minimum width=2cm, minimum height=1cm] (box) {Box}; % Connect to specific anchors \draw[->] (box.east) -- ++(1,0); \draw[->] (box.north) -- ++(0,0.5); \draw[->] (box.south west) -- ++(-0.5,-0.5); % Position at anchor \node[anchor=north west] at (3,0) {Anchored at NW}; \end{tikzpicture}

Labels on Paths

Add labels along lines and paths:

\begin{tikzpicture} % Label at end using node \draw (0,0) -- (3,0) node[right] {End Label}; % Label in the middle \draw (0,-1) -- (3,-1) node[midway, above] {Middle}; % Label at specific position \draw (0,-2) -- (3,-2) node[pos=0.3, above] {30%}; % Multiple labels \draw (0,-3) -- node[above] {A} node[below] {B} (3,-3); % Label on curved path \draw (0,-4) to[bend left] node[above] {Curved} (3,-4); \end{tikzpicture}

Node Styling

\begin{tikzpicture} % Font styling \node[font=\large\bfseries] at (0,0) {Large Bold}; \node[font=\itshape] at (3,0) {Italic}; \node[font=\ttfamily] at (6,0) {Monospace}; % Text color \node[text=red] at (0,-1) {Red Text}; \node[draw, text=blue, fill=yellow!20] at (3,-1) {Styled}; % Rotation \node[rotate=45] at (6,-1) {Rotated}; % Opacity \node[draw, opacity=0.5] at (0,-2) {Transparent}; % Combined \node[draw, thick, fill=green!20, font=\bfseries, text=green!50!black] at (4,-2) {Combined Style}; \end{tikzpicture}

Multi-line Text

\begin{tikzpicture} % Using \\ for line breaks \node[draw, align=center] at (0,0) {Line One\\Line Two\\Line Three}; % Text width with automatic wrapping \node[draw, text width=3cm, align=left] at (4,0) { This is a longer text that will automatically wrap to multiple lines. }; % Different alignments \node[draw, text width=3cm, align=right] at (8,0) {Right aligned text that wraps}; \end{tikzpicture}

Custom Node Styles

\tikzset{ process/.style={ draw, rectangle, rounded corners, minimum width=2.5cm, minimum height=1cm, fill=blue!20, font=\sffamily }, decision/.style={ draw, diamond, aspect=2, fill=yellow!30, inner sep=2pt }, startstop/.style={ draw, rectangle, rounded corners=10pt, fill=green!20, minimum width=2cm } } \begin{tikzpicture} \node[startstop] (start) {Start}; \node[process, below=of start] (proc) {Process Data}; \node[decision, below=of proc] (dec) {Valid?}; \end{tikzpicture}

Next Steps

Continue learning TikZ:

  • Text Positioning - Advanced label placement
  • Flowcharts - Apply nodes to diagrams
  • Block Diagrams - System architecture diagrams

Nodes and Labels in TikZ

Master adding text, labels, and styled nodes to your TikZ diagrams.

Basic Nodes

Nodes are the primary way to add text to TikZ drawings:

\begin{tikzpicture} % Simple text node \node at (0,0) {Hello World}; % Node with border \node[draw] at (3,0) {Boxed Text}; % Colored and filled node \node[draw=blue, fill=blue!20] at (6,0) {Blue Box}; % Node with name for referencing \node (mynode) at (0,-1.5) {Named Node}; \end{tikzpicture}

Node Shapes

Use different shapes for nodes (requires shapes.geometric library):

\usetikzlibrary{shapes.geometric} \begin{tikzpicture} % Rectangle (default) \node[draw, rectangle] at (0,0) {Rectangle}; % Circle \node[draw, circle] at (3,0) {Circle}; % Ellipse \node[draw, ellipse] at (6,0) {Ellipse}; % Diamond \node[draw, diamond] at (0,-1.5) {Decision}; % Rounded rectangle \node[draw, rounded corners] at (3,-1.5) {Rounded}; % Regular polygon \node[draw, regular polygon, regular polygon sides=6] at (6,-1.5) {Hex}; \end{tikzpicture}

Node Size Options

\begin{tikzpicture} % Minimum dimensions \node[draw, minimum width=3cm, minimum height=1cm] at (0,0) {Fixed Size}; % Inner separation (padding) \node[draw, inner sep=10pt] at (5,0) {More Padding}; % Outer separation (margin for connections) \node[draw, outer sep=5pt] at (0,-2) {Outer Sep}; % Text dimensions \node[draw, text width=3cm, align=center] at (5,-2) {This text wraps to multiple lines}; \end{tikzpicture}

Node Positioning

Position nodes relative to other elements:

\begin{tikzpicture} \draw (0,0) -- (4,0); % Position relative to point \node[above] at (2,0) {Above}; \node[below] at (2,0) {Below}; \node[left] at (0,0) {Left}; \node[right] at (4,0) {Right}; % Combined positions \node[above right] at (4,0) {Above Right}; \node[below left] at (0,0) {Below Left}; % With distance \node[above=5pt] at (2,0) {5pt Above}; \end{tikzpicture}

Positioning Library

The positioning library enables powerful relative positioning:

\usetikzlibrary{positioning} \begin{tikzpicture}[node distance=2cm] % First node \node[draw] (a) {Node A}; % Relative to first node \node[draw, right=of a] (b) {Node B}; \node[draw, below=of a] (c) {Node C}; \node[draw, below right=of a] (d) {Node D}; % Custom distance \node[draw, right=3cm of b] (e) {Node E}; % Combined with offset \node[draw, below=1cm and 2cm of a] (f) {Node F}; \end{tikzpicture}

Node Anchors

Each node has anchor points for precise positioning and connections:

AnchorDescription
centerCenter of the node
northTop center
southBottom center
eastRight center
westLeft center
north eastTop right corner
north westTop left corner
south eastBottom right corner
south westBottom left corner
\begin{tikzpicture} \node[draw, minimum width=2cm, minimum height=1cm] (box) {Box}; % Connect to specific anchors \draw[->] (box.east) -- ++(1,0); \draw[->] (box.north) -- ++(0,0.5); \draw[->] (box.south west) -- ++(-0.5,-0.5); % Position at anchor \node[anchor=north west] at (3,0) {Anchored at NW}; \end{tikzpicture}

Labels on Paths

Add labels along lines and paths:

\begin{tikzpicture} % Label at end using node \draw (0,0) -- (3,0) node[right] {End Label}; % Label in the middle \draw (0,-1) -- (3,-1) node[midway, above] {Middle}; % Label at specific position \draw (0,-2) -- (3,-2) node[pos=0.3, above] {30%}; % Multiple labels \draw (0,-3) -- node[above] {A} node[below] {B} (3,-3); % Label on curved path \draw (0,-4) to[bend left] node[above] {Curved} (3,-4); \end{tikzpicture}

Node Styling

\begin{tikzpicture} % Font styling \node[font=\large\bfseries] at (0,0) {Large Bold}; \node[font=\itshape] at (3,0) {Italic}; \node[font=\ttfamily] at (6,0) {Monospace}; % Text color \node[text=red] at (0,-1) {Red Text}; \node[draw, text=blue, fill=yellow!20] at (3,-1) {Styled}; % Rotation \node[rotate=45] at (6,-1) {Rotated}; % Opacity \node[draw, opacity=0.5] at (0,-2) {Transparent}; % Combined \node[draw, thick, fill=green!20, font=\bfseries, text=green!50!black] at (4,-2) {Combined Style}; \end{tikzpicture}

Multi-line Text

\begin{tikzpicture} % Using \\ for line breaks \node[draw, align=center] at (0,0) {Line One\\Line Two\\Line Three}; % Text width with automatic wrapping \node[draw, text width=3cm, align=left] at (4,0) { This is a longer text that will automatically wrap to multiple lines. }; % Different alignments \node[draw, text width=3cm, align=right] at (8,0) {Right aligned text that wraps}; \end{tikzpicture}

Custom Node Styles

\tikzset{ process/.style={ draw, rectangle, rounded corners, minimum width=2.5cm, minimum height=1cm, fill=blue!20, font=\sffamily }, decision/.style={ draw, diamond, aspect=2, fill=yellow!30, inner sep=2pt }, startstop/.style={ draw, rectangle, rounded corners=10pt, fill=green!20, minimum width=2cm } } \begin{tikzpicture} \node[startstop] (start) {Start}; \node[process, below=of start] (proc) {Process Data}; \node[decision, below=of proc] (dec) {Valid?}; \end{tikzpicture}

Next Steps

Continue learning TikZ:

Underleaf Logo
Underleaf

Empowering students and researchers with AI-powered tools for academic writing.

Go to appContact us

Company

PricingBlogTutorialsAffiliate Program

Free Tools

Image to LaTeXExcel to LaTeXArXiv to LaTeXTikZ GeneratorThesis GeneratorChrome ExtensionAll Tools

© 2026 Underleaf. All rights reserved.