Underleaf Logo
Underleaf
PricingAboutBlog
Log InGet started

Learn TikZ

Getting Started

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

TikZ for Beginners

A step-by-step guide to creating your first graphics with TikZ in LaTeX.

Your First TikZ Drawing

Let's start with the simplest possible TikZ code. Every TikZ drawing begins with the tikzpicture environment:

\usepackage{tikz} \begin{tikzpicture} % Your drawing commands go here \end{tikzpicture}

Drawing Lines

The most basic TikZ command is \draw. To draw a line, specify two coordinates:

\begin{tikzpicture} \draw (0,0) -- (2,0); % Horizontal line \draw (0,0) -- (0,2); % Vertical line \draw (0,0) -- (2,2); % Diagonal line \end{tikzpicture}

Coordinates are given as (x,y) pairs. The default unit is centimeters.

Drawing Shapes

TikZ has built-in commands for common shapes:

\begin{tikzpicture} % Circle: center at (0,0), radius 1cm \draw (0,0) circle (1cm); % Rectangle: from (2,0) to (4,2) \draw (2,0) rectangle (4,2); % Ellipse: center at (6,1), x-radius 1cm, y-radius 0.5cm \draw (6,1) ellipse (1cm and 0.5cm); \end{tikzpicture}

Adding Colors

Add color to your drawings using options in square brackets:

\begin{tikzpicture} % Blue line \draw[blue] (0,0) -- (2,0); % Red thick line \draw[red, thick] (0,0.5) -- (2,0.5); % Green filled circle \draw[green, fill=green!30] (1,-1) circle (0.5cm); % Yellow rectangle with blue border \draw[blue, fill=yellow] (2,-1.5) rectangle (4,-0.5); \end{tikzpicture}

The fill=color!30 syntax creates a lighter shade (30% opacity).

Adding Text with Nodes

Use \node to add text labels to your diagrams:

\begin{tikzpicture} % Simple text at a position \node at (0,0) {Hello TikZ!}; % Text with positioning \draw (0,-1) -- (3,-1); \node[above] at (1.5,-1) {Above the line}; \node[below] at (1.5,-1) {Below the line}; % Text inside a shape \node[draw, circle] at (5,0) {A}; \node[draw, rectangle] at (5,-1) {Box}; \end{tikzpicture}

Arrows

Add arrowheads to your lines with arrow options:

\begin{tikzpicture} % Arrow at end \draw[->] (0,0) -- (2,0); % Arrow at start \draw[<-] (0,-0.5) -- (2,-0.5); % Arrows at both ends \draw[<->] (0,-1) -- (2,-1); % Stealth arrow (modern style) \draw[-stealth] (0,-1.5) -- (2,-1.5); \end{tikzpicture}

Line Styles

Customize line appearance with various style options:

\begin{tikzpicture} \draw[thin] (0,0) -- (3,0); \draw[thick] (0,-0.5) -- (3,-0.5); \draw[very thick] (0,-1) -- (3,-1); \draw[dashed] (0,-1.5) -- (3,-1.5); \draw[dotted] (0,-2) -- (3,-2); \draw[dash dot] (0,-2.5) -- (3,-2.5); \end{tikzpicture}

Complete Beginner Example

Here's a complete example combining everything we've learned:

\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} % Draw a simple flowchart \node[draw, rectangle, fill=blue!20] (start) at (0,0) {Start}; \node[draw, rectangle, fill=yellow!20] (process) at (0,-2) {Process}; \node[draw, rectangle, fill=green!20] (end) at (0,-4) {End}; % Connect with arrows \draw[->, thick] (start) -- (process); \draw[->, thick] (process) -- (end); \end{tikzpicture} \end{document}

Common Beginner Mistakes

  • Forgetting semicolons: Every TikZ command must end with a semicolon.
  • Missing \usepackage{tikz}: Always include the tikz package in your preamble.
  • Wrong coordinate order: Remember it's (x,y), not (y,x).
  • Confusing -- and -: Use -- (double dash) to connect coordinates, not a single dash.

Next Steps

Now that you understand the basics, explore more TikZ features:

  • Basic Shapes - More shape options and customizations
  • Nodes and Labels - Advanced text and node positioning
  • Flowcharts - Create professional flowchart diagrams

TikZ for Beginners

A step-by-step guide to creating your first graphics with TikZ in LaTeX.

Your First TikZ Drawing

Let's start with the simplest possible TikZ code. Every TikZ drawing begins with the tikzpicture environment:

\usepackage{tikz} \begin{tikzpicture} % Your drawing commands go here \end{tikzpicture}

Drawing Lines

The most basic TikZ command is \draw. To draw a line, specify two coordinates:

\begin{tikzpicture} \draw (0,0) -- (2,0); % Horizontal line \draw (0,0) -- (0,2); % Vertical line \draw (0,0) -- (2,2); % Diagonal line \end{tikzpicture}

Coordinates are given as (x,y) pairs. The default unit is centimeters.

Drawing Shapes

TikZ has built-in commands for common shapes:

\begin{tikzpicture} % Circle: center at (0,0), radius 1cm \draw (0,0) circle (1cm); % Rectangle: from (2,0) to (4,2) \draw (2,0) rectangle (4,2); % Ellipse: center at (6,1), x-radius 1cm, y-radius 0.5cm \draw (6,1) ellipse (1cm and 0.5cm); \end{tikzpicture}

Adding Colors

Add color to your drawings using options in square brackets:

\begin{tikzpicture} % Blue line \draw[blue] (0,0) -- (2,0); % Red thick line \draw[red, thick] (0,0.5) -- (2,0.5); % Green filled circle \draw[green, fill=green!30] (1,-1) circle (0.5cm); % Yellow rectangle with blue border \draw[blue, fill=yellow] (2,-1.5) rectangle (4,-0.5); \end{tikzpicture}

The fill=color!30 syntax creates a lighter shade (30% opacity).

Adding Text with Nodes

Use \node to add text labels to your diagrams:

\begin{tikzpicture} % Simple text at a position \node at (0,0) {Hello TikZ!}; % Text with positioning \draw (0,-1) -- (3,-1); \node[above] at (1.5,-1) {Above the line}; \node[below] at (1.5,-1) {Below the line}; % Text inside a shape \node[draw, circle] at (5,0) {A}; \node[draw, rectangle] at (5,-1) {Box}; \end{tikzpicture}

Arrows

Add arrowheads to your lines with arrow options:

\begin{tikzpicture} % Arrow at end \draw[->] (0,0) -- (2,0); % Arrow at start \draw[<-] (0,-0.5) -- (2,-0.5); % Arrows at both ends \draw[<->] (0,-1) -- (2,-1); % Stealth arrow (modern style) \draw[-stealth] (0,-1.5) -- (2,-1.5); \end{tikzpicture}

Line Styles

Customize line appearance with various style options:

\begin{tikzpicture} \draw[thin] (0,0) -- (3,0); \draw[thick] (0,-0.5) -- (3,-0.5); \draw[very thick] (0,-1) -- (3,-1); \draw[dashed] (0,-1.5) -- (3,-1.5); \draw[dotted] (0,-2) -- (3,-2); \draw[dash dot] (0,-2.5) -- (3,-2.5); \end{tikzpicture}

Complete Beginner Example

Here's a complete example combining everything we've learned:

\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} % Draw a simple flowchart \node[draw, rectangle, fill=blue!20] (start) at (0,0) {Start}; \node[draw, rectangle, fill=yellow!20] (process) at (0,-2) {Process}; \node[draw, rectangle, fill=green!20] (end) at (0,-4) {End}; % Connect with arrows \draw[->, thick] (start) -- (process); \draw[->, thick] (process) -- (end); \end{tikzpicture} \end{document}

Common Beginner Mistakes

  • Forgetting semicolons: Every TikZ command must end with a semicolon.
  • Missing \usepackage{tikz}: Always include the tikz package in your preamble.
  • Wrong coordinate order: Remember it's (x,y), not (y,x).
  • Confusing -- and -: Use -- (double dash) to connect coordinates, not a single dash.

Next Steps

Now that you understand the basics, explore more TikZ features:

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.