Tikz Coordinates 2019
Tikz Coordinates 2019
In-Sung Cho
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 tikz picture box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 picture box sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3 box sizes: scale, xscale, and yscale . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Coordinates: Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1 Cartesian coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 dots and circles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.3 xshift, yshift, and shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4 polar coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3 Relative coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1 relative coordinates: current point and + and ++ . . . . . . . . . . . . . . . . . . . 14
3.2 turn: rotational relative coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4 Basic Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.1 lines and polygons: -- and cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 lines: |- and -| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
4.3 rectangles and grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.4 curves: controls and to . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.5 curves: plot coordinates: smooth and tension . . . . . . . . . . . . . . . . . . 21
5 Opacity and Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.1 filling and opacity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.2 background layer: backgrounds library . . . . . . . . . . . . . . . . . . . . . . . . 24
5.3 more layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
ii
6 Coordinates Calculations: calc library . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
6.1 coordinate calculation: basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
6.2 projection to the axes: |- and -| . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
7 Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
7.1 nodes: basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
7.2 nodes: coloring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
7.3 node dots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
7.4 nodes: positioning texts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
7.5 nodes: scaling and rotating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
7.6 node coordinate system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
8 Built-in Absolute Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
8.1 current bounding box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
8.2 current page box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
8.3 remember picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
8.4 More Page Decorating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
9 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
iii
1 Introduction
1
Graphic basics:
imaginary pen
current point
path
stroke (or draw)
fill
2
Where to put pictures (with tikz)?
move
3
tikz picture box
\tikz{<tikz codes>}
or
\begin{tikzpicture}
<tikz codes>
\end{tikzpicture}
tikz coordinates
absolute coordinates
relative coordinates
4
1.1 tikz picture box
%%\usepackage{tikz}
%%\begin{document}
% tikz picture box
\begin{tikzpicture}
<tikz codes>
\end{tikzpicture}
This\begin{tikzpicture}
\draw (2,2) rectangle (5,5); % not from (0,0)
\end{tikzpicture}is a tikz picture box.
5
1.2 picture box sizes
% [overlay]
What is this?\par
It\begin{tikzpicture}[overlay] What is this?
\draw [use as bounding box] (0,0) rectangle (1,1); Itis a box.
\draw (1,1) -- (2,2);
\end{tikzpicture}is a box.
\begin{tikzpicture}
\draw (0,0) rectangle (1,1);
\draw (1,1) -- (2,2);
\end{tikzpicture}
\begin{tikzpicture}[scale=1.5] % scale
\draw (0,0) rectangle (1,1);
\draw [overlay] (1,1) -- (2,2); % overlay
\end{tikzpicture}
\begin{tikzpicture}[xscale=1.5] % xscale
\draw (0,0) rectangle (1,1);
\draw (1,1) -- (2,2);
\end{tikzpicture}
% xscale, yscale
\begin{tikzpicture}[xscale=1.5,yscale=.5]
\draw (0,0) rectangle (1,1);
\draw (1,1) -- (2,2);
\end{tikzpicture}
7
2 Coordinates: Basics
8
2.1 Cartesian coordinates
canvas coordinate system: (<x>,<y>)
example: (3,2), (3cm,20pt)
\begin{tikzpicture}
\draw[help lines] (0,0) grid (4,3);
\coordinate (A) at (0,0);
\coordinate (B) at (3,2);
\draw (A) -- (B);
\end{tikzpicture}
9
2.2 dots and circles
\draw [<opt>] (<coor>) circle (<radius dim>);
\draw [fill,<opt>] (<coor>) circle (<radius dim>);
\draw [fill=<color>,<opt>] (<coor>) circle (<radius dim>);
% draw: line, fill: interior
10
2.3 xshift, yshift, and shift
[shift={(<coor>)}]
11
2.4 polar coordinates
canvas polar coordinate system: (<angle>:<radius>)
canvas polar coordinate system: (<angle>:<x radius> and <y radius>)
12
3 Relative coordinates
13
3.1 relative coordinates: current point and + and ++
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\filldraw [red] (1,1) circle (2pt);
\draw [->] (1,1) (0,1) -- +(1,1) -- (1,1);
\filldraw (0,1) circle (2pt); % liftpen, moveto,
lineto
\end{tikzpicture}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\filldraw [red] (1,1) circle (2pt);
\draw [->] (1,1) +(0,1) -- +(1,1) -- (1,1);
\end{tikzpicture}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\filldraw [red] (1,1) circle (2pt);
\draw [->] (1,1) ++(0,1) -- +(1,1) -- (1,1);
\filldraw (1,2) circle (2pt);
\end{tikzpicture}
14
3.2 turn: rotational relative coordinates
15
4 Basic Graphics
16
4.1 lines and polygons: -- and cycle
\draw [<opt>] (coor1) -- (coor2);
\draw [<opt>] (coor1) -- (coor2) -- (coord3);
\draw [<opt>] (coor1) -- (coor2) -- (coord3) -- cycle;
% lines
\begin{tikzpicture}
\draw [help lines,dotted] (0,0) grid (4,3);
\draw (0,0) -- (2,0);
\draw [blue] (0,.5) -- (3,.5);
\draw [thick] (0,1) -- (4,1);
\draw [line width=2pt,red] (1,3) -- (4,0);
\end{tikzpicture}
% polygons: cycle
\begin{tikzpicture}
\draw [help lines,dotted] (0,0) grid (4,3);
\draw [red] (4,1) -- (1,3) -- (0,0) -- (4,2);
\draw [very thick,blue]
(2,0)--(0,2)--(3,3)--(2,0);
\draw [very thick]
(3,0)--(1,2)--(4,3)--cycle;
\end{tikzpicture}
17
4.2 lines: |- and -|
\draw [<opt>] (coor1) |- (coor2);
\draw [<opt>] (coor1) -| (coor2);
\begin{tikzpicture}
\draw [help lines,dotted] (0,0) grid (4,4);
\draw [->] (0,3) |- (3,1);
\draw [->,red] (1,2) -| (4,0);
\draw [->,blue]
(0,0)--(1,.5) -| (2.5,4) -| (4,3)--(2,2.5);
\end{tikzpicture}
18
4.3 rectangles and grid
\draw [<opt>] (coor1) rectange (coor2);
\draw [<opt>] (coor1) grid (coor2);
\draw [help lines] (coor1) grid (coor2);
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\draw [very thick] (0,0) rectangle (2,3);
\draw [very thick] (1,1) rectangle (4,2);
\end{tikzpicture}
\begin{tikzpicture}
\draw [step=.5cm,very thin] (0,0) grid (4,2);
\draw (0,0) grid (4,2);
\end{tikzpicture}
\begin{tikzpicture}
\draw [step=1mm,red,ultra thin] (0,0) grid (4,2);
\draw [step=.5cm] (0,0) grid (4,2);
\draw [thick] (0,0) grid (4,2);
\end{tikzpicture}
19
4.4 curves: controls and to
% to [out= ,in=]
\begin{tikzpicture}[show background grid]
\draw (0,0) to [out=90, in=180] (3,2);
\draw [blue] (1,2) to [out=-135,in=45 ] (4,0);
\end{tikzpicture}
20
4.5 curves: plot coordinates: smooth and tension
% ribbon
\begin{tikzpicture}
\draw [help lines,dotted] (0,0) grid (4,3);
\draw [yellow,line width=5.5mm]
plot [smooth] coordinates
{(0,0) (1.6,2) (1,3) (.4,2.3) (2,.2)};
\draw [dotted] plot coordinates
{(0,0) (1.6,2) (1,3) (.4,2.3) (2,.2)};
\draw [blue!40,thick]
plot [smooth,tension=1] coordinates
{(2,0) (3,1) (4,3)};
\end{tikzpicture}
21
5 Opacity and Layers
22
5.1 filling and opacity
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\draw [fill=yellow] (0,1) rectangle (4,2);
\draw (2,1.5) node {some text}; some text
\draw [red,line width=2mm] (0,3) -- (4,0);
\draw [fill=blue!30] (2,0) rectangle (3,3);
\end{tikzpicture}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\draw [fill=yellow] (0,1) rectangle (4,2);
\draw (2,1.5) node {some text};
\draw [red,opacity=.3,line width=2mm] (0,3) -- (4,0);
some text
\draw [fill=blue,fill opacity=.3]
(2,0) rectangle (3,3);
\end{tikzpicture}
23
5.2 background layer: backgrounds library
\usetikzlibrary{backgrounds}
% scoping with [on background layer]
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\draw [fill=yellow] (0,1) rectangle (4,2);
\draw (2,1.5) node {some text};
\draw [red,line width=2mm] (0,3) -- (4,0); some text
\begin{scope}[on background layer]
\draw [fill=blue!30] (2,0) rectangle (3,3);
\end{scope}
\end{tikzpicture}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\draw [fill=yellow] (0,1) rectangle (4,2);
\draw (2,1.5) node {some text};
\begin{scope}[on background layer]
\draw [red,line width=2mm] (0,3) -- (4,0);
some text
\draw [fill=blue,fill opacity=.3]
(2,0) rectangle (3,3);
\end{scope}
\end{tikzpicture}
24
5.3 more layers
% in preamble
\pgfdeclarelayer{background}
\pgfdeclarelayer{behind}
\pgfdeclarelayer{above}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,behind,main,above,foreground}
% usage: \begin{pgfonlayer}{behind}
% <tikz codes>
% \end{pgfonlayer}
\begin{tikzpicture}
\draw [help lines] (0,0) grid (4,3);
\draw [fill=yellow] (0,1) rectangle (4,2);
\begin{pgfonlayer}{above}
\draw (2,1.5) node {some text};
\end{pgfonlayer}
\draw [red,line width=2mm] (0,3) -- (4,0);
some text
\begin{pgfonlayer}{behind}
\draw [fill=blue!30,fill]
(2,0) rectangle (3,3);
\end{pgfonlayer}
\end{tikzpicture}
25
6 Coordinates Calculations: calc library
\usetikzlibrary{calc}
26
6.1 coordinate calculation: basics
%% \usetikzlibrary{calc}
% general syntax for coordinates
([<opt>]$<coor calculation>$)
% linear combination
\begin{tikzpicture}[semithick,show background grid]
\draw [dotted,fill] (0,0) -- ([xshift=1cm]2,1);
\draw [dotted,fill] (0,0) -- (1,2);
C
\draw [fill] ($.4*(3,1)$) coordinate (A) circle (1pt);
B
\draw [fill] ($.7*(1,2)$) coordinate (B) circle (1pt);
\draw ($.4*(3,1)+.7*(1,2)$) coordinate (C); %
\draw (A) node [below right] {A} -- (0,0) -- (B);
\draw [dashed] (A) -- (C) -- (B) node [left] {B}; A
\draw (C) circle (1pt) node [right] {C};
\draw [fill] (1,2) circle (1pt) (3,1) circle (1pt);
\end{tikzpicture}
27
% affine combination
syntax: (<coor1>)!<t>!<angle>:(<coor2>)
\begin{tikzpicture}[semithick]
\draw [help lines] (0,0) grid (4,3);
\draw (0,0) -- (3,2);
\draw ($(0,0)!.7!(3,2)$) coordinate (A) circle (.5pt);
\draw [red] (A) -- (4,0); C
\draw ($(0,0)!.4!(3,2)$) coordinate (B) circle (.5pt);
\draw ($(0,0)!.4!60:(3,2)$) coordinate (C); B
\draw (C) circle (.5pt) node [above] {C};
\draw [dashed] (B) node [above] {B} -- (C) -- (0,0);
\end{tikzpicture}
28
6.2 projection to the axes: |- and -|
\begin{tikzpicture}[semithick]
\draw [help lines,dotted] (0,0) grid (4,3);
\draw [<->] (0,3) |- (4,0);
\draw (3,2) coordinate (A); A
\draw [fill] (A) circle (1pt) node [above right] {A};
\draw (A|-9,0) coordinate (X);
\draw (A-|0,7) coordinate (Y);
\draw [dashed] (A) -- (X);
\draw [dotted] (A) -- (Y);
\end{tikzpicture}
\begin{tikzpicture}[semithick]
\draw [help lines,dotted] (0,0) grid (4,3);
\draw [<->] (0,3) |- (4,0);
\draw (3,2) coordinate (A); A
\draw [fill] (A) circle (1pt) node [above right] {A};
\draw (A|-9,1) coordinate (X);
\draw (A-|.5,7) coordinate (Y);
\draw [dashed] (A) -- (X);
\draw [dotted] (A) -- (Y);
\end{tikzpicture}
29
7 Nodes
30
7.1 nodes: basics
A node is a small part of a picture (drawn after a path is completed).
position
shape: rectangle, draw=none (default)
empty text: {}
31
nodes: basics
inner sep, inner xsep, inner ysep: initially .3333em
outer sep: no default
minimum size
32
7.2 nodes: coloring
\begin{tikzpicture}[xscale=.5,inner sep=0pt]
\draw [help lines] (0,0) grid (3,3);
\draw (0,0) circle (3pt);
\draw [fill] (0,1) circle (3pt);
\draw [fill=red] (0,2) circle (3pt);
\draw (1,1) node [ circle,fill,minimum size=6pt] {};
\draw (1,0) node [draw,circle,fill,minimum size=6pt] {};
\draw (2,1) node [circle,fill=blue,minimum size=6pt] {};
\draw (2,0) node [draw,circle,minimum size=6pt] {};
\draw (2,2) node [draw,circle,fill=red,minimum size=6pt]
{};
\end{tikzpicture}
33
7.4 nodes: positioning texts
34
xshift and yshift
text
\begin{tikzpicture}[show background grid]
\draw (0,0) node [draw] {text};
\draw (2,1) node [draw,scale=3] {text};
\end{tikzpicture}
text
t
tex
\begin{tikzpicture}[show background grid]
\draw (0,0) node [draw,red,rotate=90] {text};
\draw (2,1) node [draw,scale=3,rotate=-30] {text}; tex
\draw (3,2) node [scale=2,rotate=30,blue] {text};
\end{tikzpicture} t
text
35
7.6 node coordinate system
36
8 Built-in Absolute Nodes
37
8.1 current bounding box
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam
nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante. Donec ullamcorper, felis
non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede. Vivamus
nunc nunc, molestie ut, ultricies vel, semper in, velit. Ut porttitor. Praesent in sapien. Lorem
ipsum dolor sit amet, consectetuer adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit amet ante
lobortis sollicitudin. Praesent blandit blandit mauris. Praesent lectus tellus, aliquet aliquam,
luctus a, egestas a, turpis. Mauris lacinia lorem sit amet ipsum. Nunc quis urna dictum turpis
accumsan semper.
\begin{tikzpicture}
%% \usepackage{blindtext}
%% \usetikzlibrary{calc,backgrounds}
\node at (0,0) {\parbox{.98\linewidth}{\blindtext}};
\coordinate (SW) at (current bounding box.south west);
\coordinate (NW) at (current bounding box.north west);
\coordinate (SE) at (current bounding box.south east);
\coordinate (NE) at (current bounding box.north east);
\begin{scope}[on background layer]
\path [fill=yellow!50] (SW) rectangle (NE);
\end{scope}
\draw [red,line width=2pt] ($(SE)!.5!(SW)$) -| ($(SE)!2cm!(NE)$);
\end{tikzpicture}
38
8.2 current page box
DO NOT FORGET [remember picture, overlay]
And you NEED to compile twice.
Everything on the current page before the picture will be hidden by the picture.
\clearpage
(text not shown: covered by the picture)
39
아리랑 아리랑 홀로 아리랑
아리랑 고개를 넘어가 보자
8.3 remember picture 가다가 힘들면 쉬어가더라도
손잡고 가보자 같이 가보자
저 멀리 동해바다 외로운 섬 금강산 맑은물은 동해로 흐르고 백두산 두만강에서 배타고 떠나라
오늘도 거센 바람 불어 오겠지 설악산 맑은물도 동해가는데 한라산 제주에서 배타고 간다
조그만 얼굴로 바람 맞으니 우리네 마음들은 어디로 가는가 가다가 홀로 섬에 닻을 내리고
독도야 간밤에 잘 잤느냐 언제쯤 우리는 하나가 될까 떠오르는 아침해를 맞이해보자
랑
독도\tikz[remember picture,overlay]{\node(A){};}야 간밤에...
언제쯤 우리는 하나가 될까\tikz[remember picture,overlay]{\node(B){};}
홀로 섬\tikz[remember picture,overlay]{\node(C){};}에...
아 리
\begin{tikzpicture}[remember picture,overlay,font={\sffamily \scriptsize}]
홀 로
\draw (current page.north east) node (Z) [below left,fill=green!50,rounded corners]
{\parbox{.2\linewidth}{아리랑...같이 가보자}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture,overlay]
\draw [->,red] (A.center) to [out=-30,in=60] (C.center);
\draw [->,dashed] (B.center) to [out=0,in=180] (Z.180);
\draw (current page.center) node [rotate=30,scale=4,opacity=.3,blue]
{ \bfseries 홀로 아리랑 };
\end{tikzpicture}
40
8.4 More Page Decorating
Practices:
See also:
• Martin Scharrer, tikzpagenodes
• 허혁재, memtikzpagenodes
9 References
• Till Tantau, The TikZ and PGF Packages: Manual for version 3.1.4b (https://github.com/
pgf-tikz/pgf).
• 조인성, 그림과 함수 플로팅 (http://wiki.ktug.org/wiki/wiki.php/LaTeXWorkshop/2018#
s-4).
41