> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/ja/xiang-xi-ji-shi/26-how-to-draw-vector-graphics-using-tikz-in-latex.md).

# LaTeXでTikZを使ってベクターグラフィックを描く方法

**著者: Cody Herring（2013年5月）**

### LaTeXにおける手続き型グラフィックス: 基本

従来、グラフィックスはビットマップとして表現され、1ビット（白黒）から24ビット（フルカラー）までさまざまです。これにより、従来の（長方形の）コンピュータ画面上でグラフィックスを簡単に表示できます。しかし、文書や紙面に表示すべき内容を正確に表すビットマップを生成するのは、難しく手間がかかることがあります。

手続き型グラフィックスは、この点に役立ちます。より明確で理解しやすいシステム、たとえばScalable Vector Graphics（SVG）を使用できるからです。個々のピクセルではなく、ベクトル、線、図形を定義することで、さまざまなサイズ、アスペクト比、画素密度、印刷品質などに対応した画像を簡単に生成できます。このチュートリアルでは、Portable Graphics FormatとTikZを用いた手続き型グラフィックスの簡単な入門を示します:

* **ポータブル・グラフィックス・フォーマット** （PGF）は、簡単なグラフィックスや図を作成できる基本的なツールセットです。
* **TikZ** はPGFの拡張であり、多数のあらかじめ用意された図形を利用できます。

TikZとPGFに関する詳しいドキュメントは、 [PGFマニュアル](http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf).

### PGFとTikZの使い方

TikZパッケージを使用するには、読み込む必要があります:

```latex
\usepackage{tikz}
```

図を描くには、 `tikzpicture` 環境を使用する必要があります:

```latex
\begin{tikzpicture}
コマンドをここに記述
\end{tikzpicture}
```

### 基本的な描画

TikZでは、さまざまな図形やパスを描画できます。ここでは基本的な描画技法をいくつか示します。これらの技法を組み合わせることで、より複雑な図を作成できます。

#### 直線パス

ある点から別の点への直線パスは、次の `\draw` コマンドで、X/Y（水平/垂直）座標系に従って、次のように描画できます:

```latex
\begin{tikzpicture}
\draw (5,0) -- (-5, 0);
\end{tikzpicture}
```

複数の `\draw` 呼び出しを連ねることもできます。これにより、X方向に-5から+5、Y方向に-2から+2の軸が描画されます。

```latex
\begin{tikzpicture}
\draw   (5,0) -- (-5, 0)
        (0,2) -- (0,-2);
\end{tikzpicture}
```

![TikZFigure 1.png](/files/01fff360023a4a1ee81108e6fecb1d722c8a2391)

追加のパラメータを加えることで、これらの線にスタイルを適用できます。以下は同じ図ですが、緑色の点線で、極太の線を15度反時計回りに回転させたものです:

```latex
\begin{tikzpicture}
\draw[green, dotted, ultra thick, rotate=15]
        (5,0) -- (-5, 0)
        (0,2) -- (0,-2);
\end{tikzpicture}
```

![TiKZFigure 2.png](/files/a2c0c33289341223402c508540df579a3903d646)

#### 図のサイズを変更する

図の既定サイズが大きすぎたり小さすぎたりすることがあります。次の `scale` パラメータを `tikzpicture` 環境を宣言すると、比率を保ったまま異なるサイズにできます:

```latex
\begin{tikzpicture}[scale=0.3]
\draw   (5,0) -- (-5, 0)
        (0,2) -- (0,-2);
\end{tikzpicture}
```

次の画像は、適用前と適用後の様子を示しています `[scale=0.3]`:

![TiKZFigure 3.png](/files/cce55424e97c69465ffe8e5eaeeed0048883eccb)

#### 矢印の先端を追加する

矢印はグラフや図で便利であり、TikZの図に簡単に追加できます。先ほど示したスタイルを使うこともでき、さまざまな矢印の先端も利用できます。

```latex
\begin{tikzpicture}
\draw[->](0,0) -- (5,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw[<<->>](0,0) -- (5,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw[<<->>, ultra thick, blue](0,0) -- (5,0);
\end{tikzpicture}

\begin{tikzpicture}
\draw[|->>, thick, red](0,0) -- (5,0);
\end{tikzpicture}
```

![TiKZFigure 4.png](/files/313164280a321293d90fe297bb47005e3eff5930)

### 曲線を描く

TikZで曲線を描く最も簡単な方法は、始点と終点、そして始点を離れる角度と終点に到達する角度を指定することです。

```latex
\begin{tikzpicture}
\draw[ultra thick]
(0,0) to [out=75,in=135](3,4);
\end{tikzpicture}
```

![TiKZFigure 5.png](/files/e5fbe9b7df9dc38d9344e5339b8abd81f1b62be2)

連続した呼び出しを使えば、さらに複雑な図も作成できます。PGFは、指定された方向を使って、できるだけ滑らかな線を描こうとします。

```latex
\begin{tikzpicture}
\draw[ultra thick]
(0,0)
to [out=90,in=180] (2,2)
to [out=270,in=0](0,0)
to [out=0,in=90](2,-2)
to [out=180,in=270](0,0)
to [out=270,in=0](-2,-2)
to [out=90,in=180](0,0)
to [out=180,in=270](-2,2)
to [out=0,in=90](0,0);
\end{tikzpicture}
```

![TIkZFigure 6.png](/files/e352ad148d0e1688f35760395bac1c74948fccaf)

### 結論

ベクターグラフィックスで描けるものに限りはありませんし、拡大縮小可能で編集しやすい図や画像を作れることは、グラフィックスを手軽に使いたいLaTeXユーザーにとって大きな利点です。この投稿は可能性の表面をなぞっているにすぎませんが、ベクターグラフィックスとTikZ/PGF環境の機能を知るためのよい入門になるはずです。

追加リソース:

* [TikZの最小限の入門](http://cremeronline.com/LaTeX/minimaltikz.pdf);
* [TikZとPGFに関するCTANドキュメント](http://mirrors.ctan.org/graphics/pgf/base/doc/pgfmanual.pdf);
* [Overleafの学習Wikiページ](/latex/ja/to/05-tikz-package.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/ja/xiang-xi-ji-shi/26-how-to-draw-vector-graphics-using-tikz-in-latex.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
