\draw (始点) -- (終点);
| 直線を描く |
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (3,0);
\end{tikzpicture}
\end{document}
|
| コンパイルする |
$ lualatex t001.tex t001.pdf が作成される。 |
\draw (始点) -- (第2点) -- (終点) -- cycle;
| 三角形を描く |
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (3,0) -- (1.5, 3) -- cycle;
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t002.tex |
\draw (左下点) rectangle (右上点);
| 長方形を描く |
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) rectangle (3, 2);
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t003.tex |
\draw[fill=色] (左下点) rectangle (右上点);
| 長方形を塗りつぶす |
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[fill=gray!20] (0,0) rectangle (3, 2);
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t004.tex |
draw (中心座標,0) circle (半径);
| 円を描く |
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (5,5) circle (5cm);
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t005.tex |
draw[fill=色] (中心座標,0) circle (半径); draw[draw=色, fill=色] (中心座標,0) circle (半径);
| 円を塗りつぶす |
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[fill=blue!20] (5,5) circle (5cm);
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t006.tex |
| 円の枠を描き、を塗りつぶす |
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[draw=blue, fill=yellow] (5,5) circle (5cm);
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t007.tex |
\node at (座標) {文字};
| 文字を描く |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {中央};
\node at (3,1) {右上};
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t008.tex |
above | 上 |
below | 下 |
left | 右 |
right | 左 |
above right | 右上 |
below left | 左下 |
| 点の近くに文字を描く |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\fill (3,3) circle (2pt);
\node[above] at (3,3) {点A};
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t009.tex |
| 点と線を組み合わせる |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\coordinate (C) at (1,3);
\draw (A) -- (B) -- (C) -- cycle;
\fill (A) circle (2pt);
\fill (B) circle (2pt);
\fill (C) circle (2pt);
\node[below left] at (A) {$A$};
\node[below right] at (B) {$B$};
\node[above] at (C) {$C$};
\node at (4, 2) {三角形ABC};
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t010.tex |
| 矢印を描く |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[blue] (0,0) -- (4,1);
\draw[red, thick, dashed] (0,1) -- (4,2);
\draw[gree, very thick, dotted] (0,2) -- (4,3);
\node[below left] at (0,0) {O};
\node[above right] at (4,3) {A (4,3)};
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t011.tex |
thin | 細い線 |
thick | 太い線 |
very thick | さらに太い線 |
dashed | 破線 |
dotted | 点線 |
| 線の種類を変更する |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[blue] (0,0) -- (4,1);
\draw[red, thick, dashed] (0,1) -- (4,2);
\draw[green, very thick, dotted] (0,2) -- (4,3);
\node[below left] at (0,0) {O};
\node[above right] at (4,3) {A (4,3)};
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t012.tex |
| 座標軸を描く |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (-0.5,0) -- (4.5,0) node[right] {$x$};
\draw[->] (0,-0.5) -- (0,3.5) node[above] {$y$};
\foreach \x in {1,2,3,4} {
\draw (\x,0.1) -- (\x,-0.1);
\node[below] at (\x,-0.1) {\x};
}
\foreach \y in {1,2,3} {
\draw (0.1,\y) -- (-0.1,\y);
\node[left] at (-0.1,\y) {\y};
}
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t013.tex |
| 関数y=x^2のグラフを描く |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[->] (-2.5,0) -- (2.5,0) node[right] {$x$};
\draw[->] (0,-0.5) -- (0,4.5) node[above] {$y$};
\draw[domain=-2:2, samples=100, thick]
plot (\x, {\x*\x});
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t014.tex |
| フローチャートを描く |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
box/.style={
draw,
rectangle,
rounded corners,
minimum width=3cm,
minimum height=1cm,
align=center
},
node distance=1.5cm
]
\node[box] (start) {開始};
\node[box, below=of start] (input) {データを入力};
\node[box, below=of input] (process) {計算する};
\node[box, below=of process] (end) {終了};
\draw[->] (start) -- (input);
\draw[->] (input) -- (process);
\draw[->] (process) -- (end);
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t015.tex |
\usetikzlibrary{positioning}
上の宣言を追加しておくと、below=of start のように、他の要素を基準に位置を指定できる。
node 自体を図形にする| node自体を図形にする |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[draw, rectangle] at (0,0) {四角};
\node[draw, circle] at (3,0) {円};
\node[
draw=blue,
fill=blue!10,
rounded corners,
minimum width=3cm,
minimum height=1cm
] at (2,5) {説明};
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t016.tex |
[定義] スタイル名/.style={設定内容}
[使用] \node[スタイル名]...
同じ書式を何度も使う場合は、スタイルを定義するとよい。
| スタイルを定義する |
\documentclass[a4paper,11pt]{ltjsarticle}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
mybox/.style={
draw,
thick,
rounded corners,
fill=gray!10,
minimum width=3cm,
minimum height=1cm
}
]
\node[mybox] at (0,0) {箱1};
\node[mybox] at (4,0) {箱2};
\end{tikzpicture}
\end{document}
|
| texからpdfを生成する |
$ lualatex t017.tex |