Underleaf Logo
Underleaf
PricingAboutBlog
Log InGet started

Learn TikZ

Getting Started

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

Lines and Paths in TikZ

Master the fundamental drawing commands for lines, curves, and complex paths in TikZ.

Drawing Straight Lines

The basic line command connects two points with a straight line:

\begin{tikzpicture} % Simple line from (0,0) to (3,0) \draw (0,0) -- (3,0); % Line with multiple segments (polyline) \draw (0,1) -- (1,2) -- (2,1) -- (3,2); % Closed shape (triangle) \draw (0,3) -- (1.5,4) -- (3,3) -- cycle; \end{tikzpicture}

Use -- cycle to close a path back to its starting point.

Line Style Options

OptionEffect
thin0.4pt line width
thick0.8pt line width
very thick1.2pt line width
ultra thick1.6pt line width
line width=2ptCustom line width
dashedDashed line
dottedDotted line
dash dotAlternating dash-dot
dash pattern=on 2pt off 1ptCustom dash pattern
\begin{tikzpicture} \draw[thick] (0,0) -- (3,0); \draw[dashed] (0,0.5) -- (3,0.5); \draw[dotted, very thick] (0,1) -- (3,1); \draw[line width=2pt, blue] (0,1.5) -- (3,1.5); \end{tikzpicture}

Curved Lines with Bezier Curves

Create smooth curves using .. controls .. for Bezier curves:

\begin{tikzpicture} % Quadratic Bezier (one control point) \draw (0,0) .. controls (1,1) .. (2,0); % Cubic Bezier (two control points) \draw (0,2) .. controls (0.5,3) and (1.5,3) .. (2,2); % Show control points for reference \draw[gray, dashed] (0,2) -- (0.5,3); \draw[gray, dashed] (1.5,3) -- (2,2); \filldraw[red] (0.5,3) circle (2pt); \filldraw[red] (1.5,3) circle (2pt); \end{tikzpicture}

Smooth Curves Through Points

Use plot[smooth] to draw curves through multiple points:

\begin{tikzpicture} % Smooth curve through points \draw plot[smooth] coordinates { (0,0) (1,1) (2,0.5) (3,1) (4,0) }; % Smooth cycle (closed curve) \draw plot[smooth cycle] coordinates { (0,2) (1,3) (2,2.5) (3,3) (2,2) }; % Control smoothness with tension \draw[red] plot[smooth, tension=0.5] coordinates { (0,-1) (1,0) (2,-0.5) (3,0) (4,-1) }; \end{tikzpicture}

Horizontal and Vertical Lines

Use -| and |- for right-angle paths:

\begin{tikzpicture} % Horizontal then vertical (-|) \draw (0,0) -| (2,1); % Vertical then horizontal (|-) \draw[red] (0,0) |- (2,1); % Combined in a path \draw[blue] (0,2) -| (1,3) -| (2,2); \end{tikzpicture}

Rounded Corners

Add rounded corners to any path:

\begin{tikzpicture} % Default rounded corners \draw[rounded corners] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle; % Custom radius \draw[rounded corners=5pt] (2,0) rectangle (4,1); % Mixed sharp and rounded \draw[rounded corners=3mm] (0,2) -- (1,2) -- (1,3) [sharp corners] -- (0.5,3) -- (0,2.5) [rounded corners] -- cycle; \end{tikzpicture}

Arc Paths

Draw circular arcs with the arc command:

\begin{tikzpicture} % Arc: start angle, end angle, radius \draw (2,0) arc (0:90:2cm); % Arc with different x and y radii (elliptical) \draw (4,0) arc (0:180:1cm and 0.5cm); % Arc as part of a path \draw (0,2) -- ++(1,0) arc (180:0:0.5cm) -- ++(1,0); \end{tikzpicture}

Grid Lines

Draw grids for reference or backgrounds:

\begin{tikzpicture} % Basic grid \draw[step=1cm, gray, very thin] (0,0) grid (4,3); % Custom step size \draw[step=0.5cm, lightgray] (5,0) grid (8,3); % Different x and y steps \draw[xstep=0.5cm, ystep=1cm, blue!20] (0,4) grid (4,6); \end{tikzpicture}

Line Caps and Joins

Control how line ends and corners are drawn:

\begin{tikzpicture} % Line caps \draw[line width=4pt, line cap=butt] (0,0) -- (2,0); \draw[line width=4pt, line cap=round] (0,0.5) -- (2,0.5); \draw[line width=4pt, line cap=rect] (0,1) -- (2,1); % Line joins \draw[line width=4pt, line join=miter] (3,0) -- (4,0.5) -- (5,0); \draw[line width=4pt, line join=round] (3,1) -- (4,1.5) -- (5,1); \draw[line width=4pt, line join=bevel] (3,2) -- (4,2.5) -- (5,2); \end{tikzpicture}

Double Lines

Create double lines (useful for roads, walls, etc.):

\begin{tikzpicture} \draw[double, double distance=2pt] (0,0) -- (3,0); \draw[double=red, double distance=3pt] (0,0.5) -- (3,0.5); \draw[double, double distance=4pt, thick] (0,1) -- (3,1); \end{tikzpicture}

Next Steps

Continue learning TikZ drawing techniques:

  • Basic Shapes - Circles, rectangles, and polygons
  • Arrows - Arrow tips and styles
  • Colors and Styles - Color fills and custom styles

Lines and Paths in TikZ

Master the fundamental drawing commands for lines, curves, and complex paths in TikZ.

Drawing Straight Lines

The basic line command connects two points with a straight line:

\begin{tikzpicture} % Simple line from (0,0) to (3,0) \draw (0,0) -- (3,0); % Line with multiple segments (polyline) \draw (0,1) -- (1,2) -- (2,1) -- (3,2); % Closed shape (triangle) \draw (0,3) -- (1.5,4) -- (3,3) -- cycle; \end{tikzpicture}

Use -- cycle to close a path back to its starting point.

Line Style Options

OptionEffect
thin0.4pt line width
thick0.8pt line width
very thick1.2pt line width
ultra thick1.6pt line width
line width=2ptCustom line width
dashedDashed line
dottedDotted line
dash dotAlternating dash-dot
dash pattern=on 2pt off 1ptCustom dash pattern
\begin{tikzpicture} \draw[thick] (0,0) -- (3,0); \draw[dashed] (0,0.5) -- (3,0.5); \draw[dotted, very thick] (0,1) -- (3,1); \draw[line width=2pt, blue] (0,1.5) -- (3,1.5); \end{tikzpicture}

Curved Lines with Bezier Curves

Create smooth curves using .. controls .. for Bezier curves:

\begin{tikzpicture} % Quadratic Bezier (one control point) \draw (0,0) .. controls (1,1) .. (2,0); % Cubic Bezier (two control points) \draw (0,2) .. controls (0.5,3) and (1.5,3) .. (2,2); % Show control points for reference \draw[gray, dashed] (0,2) -- (0.5,3); \draw[gray, dashed] (1.5,3) -- (2,2); \filldraw[red] (0.5,3) circle (2pt); \filldraw[red] (1.5,3) circle (2pt); \end{tikzpicture}

Smooth Curves Through Points

Use plot[smooth] to draw curves through multiple points:

\begin{tikzpicture} % Smooth curve through points \draw plot[smooth] coordinates { (0,0) (1,1) (2,0.5) (3,1) (4,0) }; % Smooth cycle (closed curve) \draw plot[smooth cycle] coordinates { (0,2) (1,3) (2,2.5) (3,3) (2,2) }; % Control smoothness with tension \draw[red] plot[smooth, tension=0.5] coordinates { (0,-1) (1,0) (2,-0.5) (3,0) (4,-1) }; \end{tikzpicture}

Horizontal and Vertical Lines

Use -| and |- for right-angle paths:

\begin{tikzpicture} % Horizontal then vertical (-|) \draw (0,0) -| (2,1); % Vertical then horizontal (|-) \draw[red] (0,0) |- (2,1); % Combined in a path \draw[blue] (0,2) -| (1,3) -| (2,2); \end{tikzpicture}

Rounded Corners

Add rounded corners to any path:

\begin{tikzpicture} % Default rounded corners \draw[rounded corners] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle; % Custom radius \draw[rounded corners=5pt] (2,0) rectangle (4,1); % Mixed sharp and rounded \draw[rounded corners=3mm] (0,2) -- (1,2) -- (1,3) [sharp corners] -- (0.5,3) -- (0,2.5) [rounded corners] -- cycle; \end{tikzpicture}

Arc Paths

Draw circular arcs with the arc command:

\begin{tikzpicture} % Arc: start angle, end angle, radius \draw (2,0) arc (0:90:2cm); % Arc with different x and y radii (elliptical) \draw (4,0) arc (0:180:1cm and 0.5cm); % Arc as part of a path \draw (0,2) -- ++(1,0) arc (180:0:0.5cm) -- ++(1,0); \end{tikzpicture}

Grid Lines

Draw grids for reference or backgrounds:

\begin{tikzpicture} % Basic grid \draw[step=1cm, gray, very thin] (0,0) grid (4,3); % Custom step size \draw[step=0.5cm, lightgray] (5,0) grid (8,3); % Different x and y steps \draw[xstep=0.5cm, ystep=1cm, blue!20] (0,4) grid (4,6); \end{tikzpicture}

Line Caps and Joins

Control how line ends and corners are drawn:

\begin{tikzpicture} % Line caps \draw[line width=4pt, line cap=butt] (0,0) -- (2,0); \draw[line width=4pt, line cap=round] (0,0.5) -- (2,0.5); \draw[line width=4pt, line cap=rect] (0,1) -- (2,1); % Line joins \draw[line width=4pt, line join=miter] (3,0) -- (4,0.5) -- (5,0); \draw[line width=4pt, line join=round] (3,1) -- (4,1.5) -- (5,1); \draw[line width=4pt, line join=bevel] (3,2) -- (4,2.5) -- (5,2); \end{tikzpicture}

Double Lines

Create double lines (useful for roads, walls, etc.):

\begin{tikzpicture} \draw[double, double distance=2pt] (0,0) -- (3,0); \draw[double=red, double distance=3pt] (0,0.5) -- (3,0.5); \draw[double, double distance=4pt, thick] (0,1) -- (3,1); \end{tikzpicture}

Next Steps

Continue learning TikZ drawing techniques:

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.