> 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/zh-tw/tu-biao-yu-biao-ge/04-picture-environment.md).

# 直接在 LaTeX 中繪製圖表

## 簡介

LaTeX 內建的 `picture` 環境可用來建立圖表／圖形——你不需要 *需要* 載入任何外部套件即可使用它，但像 [`pict2e`](https://ctan.org/pkg/pict2e?lang=en) 和 [`picture`](https://ctan.org/pkg/picture) 這類套件已被撰寫出來，以增強或改善其功能。

本文提供對 `picture` 環境的簡要介紹，所有範例都使用 [`pict2e` 套件](https://ctan.org/pkg/pict2e?lang=en). 更完整的文件與一系列有幫助的範例，可在以下資源中輕易取得：

* [LaTeX2e 非官方參考手冊](https://latexref.xyz/picture.html)
* [《LaTeX2ε 的不那麼簡短入門》](https://tobi.oetiker.ch/lshort/lshort.pdf) （見第 5 章）
* [Wikibooks](https://en.wikibooks.org/wiki/LaTeX/Picture)
* [標記為 `picture-mode` 於 tex.stackexchange](https://tex.stackexchange.com/questions/tagged/picture-mode)
* [`pict2e` 套件說明文件](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/pict2e/pict2e.pdf)

與像 [TikZ/PGF](https://en.wikipedia.org/wiki/PGF/TikZ), [MetaPost](https://tug.org/metapost.html), [PSTricks](https://ctan.org/topic/pstricks?lang=en) 或 [Asymptote](https://ctan.org/pkg/asymptote?lang=en) 該 `picture` 環境看起來可能相當受限，但有時候，它可能足以滿足你的需求。

## 建立新的圖形

建立新的圖形通常包括以下步驟：

1. 定義你想使用的繪圖單位大小；
2. 宣告一個 `picture` 環境，以定義圖形大小；
3. 使用 `\put`, `\multiput` 或 `\qbezier` 命令繪製各個圖形元件。

### 定義繪圖單位大小

要建立一個圖形，通常先從設定 *繪圖單位* 開始，透過命令 `\unitlength`，而且這必須在 `picture` 環境之外使用。例如，如果你寫

```latex
\setlength{\unitlength}{1cm}
```

，那麼繪圖單位將被解釋為 1cm 的倍數。預設單位是 1pt。

### 定義你的圖形大小

的通用格式如下： `picture` 環境

```latex
\begin{picture}(width, height)(Xoffset, Yoffset)
 ...
\end{picture}
```

其中

* `width` 和 `高度` 是以 `\unitlength`為單位的值，用來定義圖形大小。LaTeX 會使用這些值建立一個盒子，其尺寸為
  * 盒子（圖形）寬度 = `width` × `\unitlength`
  * 盒子（圖形）高度 = `高度` × `\unitlength`
* `(Xoffset, Yoffset)` 是一個可選座標，用來設定圖形的原點（左下角），以一個 *偏移量* 相對於預設位置來表示。 `Xoffset` 和 `Yoffset` 也以由目前 `\unitlength`.

請注意 `Xoffset` 和 `Yoffset` 的值決定的單位表示，並不影響 LaTeX 保留的空間量；也就是盒子尺寸。

#### 理解圖形尺寸

我們將建立兩個圖形，兩者都使用 `\setlength{\unitlength}{1cm}` ，而且各自有一個 `width` 和 `高度` 為 3 單位的

第一個圖形使用預設的原點 `(0,0)`:

```latex
\begin{picture}(3,3)
...
\end{picture}
```

第二個圖形將原點偏移（平移） `(1,1)`:

```latex
\begin{picture}(3,3)(1,1)
...
\end{picture}
```

### 繪製圖形

圖形是透過一連串 `\put`, `\multiput`、或 `\qbezier` 命令建立的，這些命令產生構成圖形或插圖的個別「元件」（或「物件」）：

* `\put(x, y){*component*}` 會在位置 `*component*` 繪製 `(x, y)`.
* `\multiput(x, y)(dx, dy){n}{*component*}` 會在位置 `*component*` `n` 次：從位置 `(x, y)` 開始，並重複以 `(dx, dy)` 平移來重新繪製 `*component*`.
* `\qbezier[n](x<sub>1</sub>, y<sub>1</sub>)(x, y)(x<sub>2</sub>, y<sub>2</sub>)`：繪製一條 [二次貝茲曲線](https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_B%C3%A9zier_curves) 其中：
  * `n` 一個可選整數，用來決定用於繪製／產生曲線的點數
  * `(x<sub>1</sub>, y<sub>1</sub>)` 是曲線的起點
  * `(x<sub>2</sub>, y<sub>2</sub>)` 是曲線的終點
  * `(x, y)` 表示（二次）貝茲曲線控制點

一個 `*component*` 是一個圖形元素，通常使用以下圖形原語產生，如 `\line`, `\oval`, `\circle`, `\vector` 等等——詳情請見 [LaTeX2e 非官方參考手冊](https://latexref.xyz/picture.html) 或 [《LaTeX2ε 的不那麼簡短入門》](https://tobi.oetiker.ch/lshort/lshort.pdf) （第 5 章），以了解可用原語的細節。

**注意**： [`pict2e` 套件](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/pict2e/pict2e.pdf) 延伸了原本的 `picture` 環境，提供數個繪製貝茲曲線的命令： `\bezier`, `\qbezier`, `\cbezier` 和 `\qbeziermax`.

### 理解偏移與原點

在以下範例中， `\put` 命令用來繪製彩色圓點，標示圖形中的關鍵座標（位置）。兩個範例都使用 LaTeX 的 `\fbox` 命令，在 LaTeX 建立用來容納我們圖形的盒子周圍畫出邊框，顯示 *外框盒* 。

**範例 1：使用預設原點**

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\usepackage[dvipsnames]{xcolor}
\begin{document}
\setlength{\unitlength}{1cm}
\setlength{\fboxsep}{0pt}

這是我的圖形\fbox{%
\begin{picture}(3,3)
\put(0,0){{\color{blue}\circle*{0.25}}\hbox{\kern3pt \texttt{(0,0)}}}
\put(3,3){{\color{red}\circle*{0.25}}\hbox{\kern3pt \texttt{(3,3)}}}
\end{picture}}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=understanding+picture+dimensions+example+1\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cusepackage%5Bdvipsnames%5D%7Bxcolor%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B1cm%7D%0A%5Csetlength%7B%5Cfboxsep%7D%7B0pt%7D%0A%0AThis+is+my+picture%5Cfbox%7B%25%0A%5Cbegin%7Bpicture%7D%283%2C3%29%0A%5Cput%280%2C0%29%7B%7B%5Ccolor%7Bblue%7D%5Ccircle%2A%7B0.25%7D%7D%5Chbox%7B%5Ckern3pt+%5Ctexttt%7B%280%2C0%29%7D%7D%7D%0A%5Cput%283%2C3%29%7B%7B%5Ccolor%7Bred%7D%5Ccircle%2A%7B0.25%7D%7D%5Chbox%7B%5Ckern3pt+%5Ctexttt%7B%283%2C3%29%7D%7D%7D%0A%5Cend%7Bpicture%7D%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![LaTeX picture 環境的尺寸](/files/13eade816dc63feba505ff445db633b35e04955f)

該 `\fbox` 命令會在圖形的外框盒周圍畫出邊框，顯示 LaTeX 保留的空間（區域）：

* 圖形寬度 = `width` × `\unitlength` = 3 × 1cm = 3cm。
* 圖形高度 = `高度` × `\unitlength` = 3 × 1cm = 3cm。

第一個範例顯示，原點 `(0,0)`，位於 `\begin{picture}` 命令執行的那個點，也就是文字「This is my picture」之後立刻的位置。此外，右上角位於 `(3,3)`，而 `(width,height)` 提供給 `\begin{picture}(3,3)`.

**範例 2：將原點平移 (1,1)**

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\usepackage[dvipsnames]{xcolor}
\begin{document}
\setlength{\unitlength}{1cm}
\setlength{\fboxsep}{0pt}

這是我的圖形\fbox{%
\begin{picture}(3,3)(1,1)
\put(0,0){{\color{blue}\circle*{0.25}}\hbox{\kern3pt\texttt{(0,0)}}}
\put(1,1){{\color{orange}\circle*{0.25}}\hbox{\kern3pt\texttt{(1,1)}}}
\put(3,3){{\color{red}\circle*{0.25}}\hbox{\kern3pt\texttt{(3,3)}}}
\put(4,4){{\color{black}\circle*{0.25}}\hbox{\kern3pt\texttt{(4,4)}}}
\end{picture}}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=understanding+picture+dimensions+example+2\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cusepackage%5Bdvipsnames%5D%7Bxcolor%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B1cm%7D%0A%5Csetlength%7B%5Cfboxsep%7D%7B0pt%7D%0A%0AThis+is+my+picture%5Cfbox%7B%25%0A%5Cbegin%7Bpicture%7D%283%2C3%29%281%2C1%29%0A%5Cput%280%2C0%29%7B%7B%5Ccolor%7Bblue%7D%5Ccircle%2A%7B0.25%7D%7D%5Chbox%7B%5Ckern3pt%5Ctexttt%7B%280%2C0%29%7D%7D%7D%0A%5Cput%281%2C1%29%7B%7B%5Ccolor%7Borange%7D%5Ccircle%2A%7B0.25%7D%7D%5Chbox%7B%5Ckern3pt%5Ctexttt%7B%281%2C1%29%7D%7D%7D%0A%5Cput%283%2C3%29%7B%7B%5Ccolor%7Bred%7D%5Ccircle%2A%7B0.25%7D%7D%5Chbox%7B%5Ckern3pt%5Ctexttt%7B%283%2C3%29%7D%7D%7D%0A%5Cput%284%2C4%29%7B%7B%5Ccolor%7Bblack%7D%5Ccircle%2A%7B0.25%7D%7D%5Chbox%7B%5Ckern3pt%5Ctexttt%7B%284%2C4%29%7D%7D%7D%0A%5Cend%7Bpicture%7D%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![LaTeX picture 環境的尺寸](/files/6569948f8bbce78e9f9e030fdcc6d7601b13a8fe)

第二個範例顯示平移原點的效果，並突顯幾個重點：

* 由 `\fbox` 建立的邊框顯示圖形的外框盒，也就是 LaTeX 建立的盒子寬度與高度， *不受影響* ，因為平移原點：它仍然由 `(width,height)` 提供給 `\begin{picture}(3,3)(1,1)`
  * 圖形寬度 = `width` × `\unitlength` = 3 × 1cm = 3cm
  * 圖形高度 = `高度` × `\unitlength` = 3 × 1cm = 3cm
* 決定；繪圖元素並不受限（裁切）於 LaTeX 建立的區域（外框盒尺寸）。例如，藍色圓點與 `(0,0)` 座標被繪製在由 `\fbox`產生的邊界線之外，該線表示外框盒。
  * 使用者必須確保繪圖元素保持在外框盒內，且不會覆蓋周圍文字。
* 原點 `(0,0)`， *不再* 位於文字「This is my picture」之後立刻的位置，也就是 `\begin{picture}` 命令執行的那個點：原點現在向左平移 1 單位，並向下平移 1 單位
* 右上角現在位於 `(4,4)`

## picture 環境範例

### 來自 LaTeX2e 非官方參考手冊的範例

該 [LaTeX2e 非官方參考手冊](https://latexref.xyz/picture.html) 包含許多 `picture` 環境範例，其中一些在此重現，並附上可在 Overleaf 中開啟的連結，讓你可以編輯並探索程式碼。

#### 範例 1：\vector 命令

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\begin{document}
\setlength{\unitlength}{1cm}
\begin{picture}(6,6)      % 圖形盒子寬 6cm、高 6cm
  \put(0,0){\vector(2,1){4}}  % 每往右 2 單位，這個向量往上 1 單位
    \put(2,1){\makebox(0,0)[l]{\ 第一段}}
  \put(4,2){\vector(1,2){2}}
    \put(5,4){\makebox(0,0)[l]{\ 第二段}}
  \put(0,0){\vector(1,1){6}}
    \put(3,3){\makebox(0,0)[r]{總和\ }}
\end{picture}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=picture+environment+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B1cm%7D%0A%5Cbegin%7Bpicture%7D%286%2C6%29++++++%25+picture+box+will+be+6cm+wide+by+6cm+tall%0A++%5Cput%280%2C0%29%7B%5Cvector%282%2C1%29%7B4%7D%7D++%25+for+every+2+over+this+vector+goes+1+up%0A++++%5Cput%282%2C1%29%7B%5Cmakebox%280%2C0%29%5Bl%5D%7B%5C+first+leg%7D%7D%0A++%5Cput%284%2C2%29%7B%5Cvector%281%2C2%29%7B2%7D%7D%0A++++%5Cput%285%2C4%29%7B%5Cmakebox%280%2C0%29%5Bl%5D%7B%5C+second+leg%7D%7D++%0A++%5Cput%280%2C0%29%7B%5Cvector%281%2C1%29%7B6%7D%7D%0A++++%5Cput%283%2C3%29%7B%5Cmakebox%280%2C0%29%5Br%5D%7Bsum%5C+%7D%7D++%0A%5Cend%7Bpicture%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![picture 環境範例](/files/664aae3264ac9d6159fa72b90cc9b8bc5f9042cd)

#### 範例 2：\qbezier、\line、\vector、\thinlines 與 \thicklines 命令

請注意 `\qbezier` 指令 *沒有* 在 `\put{...}` 中使用，而其他原語命令，例如 `\line`, `\vector` *已* 在 `\put{...}`.

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\begin{document}
\setlength{\unitlength}{1cm}
\begin{picture}(8,4)
  \thinlines % 先使用細線
  \put(0,0){\vector(1,0){8}}  % x 軸
  \put(0,0){\vector(0,1){4}}  % y 軸
  \put(2,0){\line(0,1){3}}    % 左邊
  \put(4,0){\line(0,1){3.5}}  % 右邊
  \thicklines % 對 \qbezier 命令使用較粗的線條
  \qbezier(2,3)(2.5,2.9)(3,3.25)
  \qbezier(3,3.25)(3.5,3.6)(4,3.5)
  \thinlines % 回到使用細線
  \put(2,3){\line(4,1){2}}
  \put(4.5,2.5){\framebox{梯形法則}}
\end{picture}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=qbezier+picture+environment+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B1cm%7D%0A%5Cbegin%7Bpicture%7D%288%2C4%29%0A++%5Cthinlines+%25+Start+with+thin+lines%0A++%5Cput%280%2C0%29%7B%5Cvector%281%2C0%29%7B8%7D%7D++%25+x+axis%0A++%5Cput%280%2C0%29%7B%5Cvector%280%2C1%29%7B4%7D%7D++%25+y+axis%0A++%5Cput%282%2C0%29%7B%5Cline%280%2C1%29%7B3%7D%7D++++%25+left+side%0A++%5Cput%284%2C0%29%7B%5Cline%280%2C1%29%7B3.5%7D%7D++%25+right+side%0A++%5Cthicklines+%25+Use+thicker+lines+for+the+%5Cqbezier+commands%0A++%5Cqbezier%282%2C3%29%282.5%2C2.9%29%283%2C3.25%29%0A++%5Cqbezier%283%2C3.25%29%283.5%2C3.6%29%284%2C3.5%29%0A++%5Cthinlines+%25+Back+to+using+thin+lines%0A++%5Cput%282%2C3%29%7B%5Cline%284%2C1%29%7B2%7D%7D%0A++%5Cput%284.5%2C2.5%29%7B%5Cframebox%7BTrapezoidal+Rule%7D%7D%0A%5Cend%7Bpicture%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![LaTeX picture 環境範例](/files/27295dd3868480b4ba01d39f4588794c29932ca7)

#### 範例 3：\multiput 與 \linethickness 命令

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\begin{document}
\setlength{\unitlength}{1cm}
\thicklines
\begin{picture}(10,10)
  \linethickness{0.05mm}
  \multiput(0,0)(1,0){10}{\line(0,1){10}}
  \multiput(0,0)(0,1){10}{\line(1,0){10}}
  \linethickness{0.5mm}
  \multiput(0,0)(5,0){3}{\line(0,1){10}}
  \multiput(0,0)(0,5){3}{\line(1,0){10}}
\end{picture}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=multiput+command+picture+environment+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B1cm%7D%0A%5Cthicklines%0A%5Cbegin%7Bpicture%7D%2810%2C10%29%0A++%5Clinethickness%7B0.05mm%7D%0A++%5Cmultiput%280%2C0%29%281%2C0%29%7B10%7D%7B%5Cline%280%2C1%29%7B10%7D%7D+%0A++%5Cmultiput%280%2C0%29%280%2C1%29%7B10%7D%7B%5Cline%281%2C0%29%7B10%7D%7D%0A++%5Clinethickness%7B0.5mm%7D%0A++%5Cmultiput%280%2C0%29%285%2C0%29%7B3%7D%7B%5Cline%280%2C1%29%7B10%7D%7D%0A++%5Cmultiput%280%2C0%29%280%2C5%29%7B3%7D%7B%5Cline%281%2C0%29%7B10%7D%7D%0A%5Cend%7Bpicture%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![\multiput 命令 LaTeX picture 環境範例](/files/7496894848a46c374a1a4592d41a50ffc4e16a48)

### 其他範例

#### 基本的貝茲曲線

以下範例使用了 `\qbezier` 命令來繪製貝茲曲線：

```latex
\qbezier(1,1)(5,5)(9,0.5)
```

請注意以下事項：

* 該 `\qbezier` 命令沒有在 `\put` 指令
* 貝茲曲線起點是 `(1,1)`
* 貝茲曲線終點是 `(9,0.5)`
* 貝茲曲線控制點是 `(5,5)`
* 我們沒有使用那個可選整數，它用來決定繪製／產生貝茲曲線所使用的點數

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\begin{document}
\setlength{\unitlength}{0.8cm}
\begin{picture}(10,5)
\thicklines
\qbezier(1,1)(5,5)(9,0.5)
\put(2,1){{Bézier curve}}
\end{picture}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=multiput+command+picture+environment+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B0.8cm%7D%0A%5Cbegin%7Bpicture%7D%2810%2C5%29%0A%5Cthicklines%0A%5Cqbezier%281%2C1%29%285%2C5%29%289%2C0.5%29%0A%5Cput%282%2C1%29%7B%7BB%C3%A9zier+curve%7D%7D%0A%5Cend%7Bpicture%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![使用 LaTeX 繪製貝茲曲線](/files/43cad2ff3fca62bb4ea8090bd76855f8634b91db)

#### 橢圓、線條與圓形

以下範例展示了 `\line`, `\circle` 和 `\oval` 命令——請注意它們如何 *已* 都在 `\put{...}` 命令：

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\begin{document}
\setlength{\unitlength}{1cm}
\thicklines
\begin{picture}(10,6)
\put(2,2.2){\line(1,0){6}}
\put(2,2.2){\circle{2}}
\put(6,2.2){\oval(4,2)[r]}
\end{picture}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=picture+environment+example\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B1cm%7D%0A%5Cthicklines%0A%5Cbegin%7Bpicture%7D%2810%2C6%29%0A%5Cput%282%2C2.2%29%7B%5Cline%281%2C0%29%7B6%7D%7D%0A%5Cput%282%2C2.2%29%7B%5Ccircle%7B2%7D%7D%0A%5Cput%286%2C2.2%29%7B%5Coval%284%2C2%29%5Br%5D%7D%0A%5Cend%7Bpicture%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![LaTeX picture 環境範例](/files/045b53de319f95bca621b102bfc8c3bb378ca3b7)

以下是這些命令的說明：

* `\put(2,2.2){\line(1,0){6}}`: 繪製一條 `6` 單位長，使用「方向向量」 `(1,0)`
* `\put(6,2.2){\oval(4,2)[r]}`: 繪製一個以該點為中心的橢圓 `(4,2)`。參數 `[r]` 是可選的，你可以使用 `r`, `l`, `的區域變數中` 和 `b` 來顯示橢圓的右、左、上或下部分。
* `\put(2,2.2){\circle{2}}`: 繪製一個以該點為中心且直徑為 `(2,2.2)` 的圓。 `2`.

#### 結合線條、圓形與文字

不同的基本元素可以結合起來建立更複雜的圖形。在這個範例中，多條線和圓形被結合起來建立一個圖形，並以文字標示各個點：

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\begin{document}
\setlength{\unitlength}{0.8cm}
\begin{picture}(12,4)
\thicklines
\put(8,3.3){{\footnotesize $3$-simplex}}
\put(9,3){\circle*{0.1}}
\put(8.3,2.9){$a_2$}
\put(8,1){\circle*{0.1}}
\put(7.7,0.5){$a_0$}
\put(10,1){\circle*{0.1}}
\put(9.7,0.5){$a_1$}
\put(11,1.66){\circle*{0.1}}
\put(11.1,1.5){$a_3$}
\put(9,3){\line(3,-2){2}}
\put(10,1){\line(3,2){1}}
\put(8,1){\line(1,0){2}}
\put(8,1){\line(1,2){1}}
\put(10,1){\line(-1,2){1}}
\end{picture}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=understanding+picture+dimensions+example+1\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B0.8cm%7D%0A%5Cbegin%7Bpicture%7D%2812%2C4%29%0A%5Cthicklines%0A%5Cput%288%2C3.3%29%7B%7B%5Cfootnotesize+%243%24-simplex%7D%7D%0A%5Cput%289%2C3%29%7B%5Ccircle%2A%7B0.1%7D%7D%0A%5Cput%288.3%2C2.9%29%7B%24a_2%24%7D%0A%5Cput%288%2C1%29%7B%5Ccircle%2A%7B0.1%7D%7D%0A%5Cput%287.7%2C0.5%29%7B%24a_0%24%7D%0A%5Cput%2810%2C1%29%7B%5Ccircle%2A%7B0.1%7D%7D%0A%5Cput%289.7%2C0.5%29%7B%24a_1%24%7D%0A%5Cput%2811%2C1.66%29%7B%5Ccircle%2A%7B0.1%7D%7D%0A%5Cput%2811.1%2C1.5%29%7B%24a_3%24%7D%0A%5Cput%289%2C3%29%7B%5Cline%283%2C-2%29%7B2%7D%7D%0A%5Cput%2810%2C1%29%7B%5Cline%283%2C2%29%7B1%7D%7D%0A%5Cput%288%2C1%29%7B%5Cline%281%2C0%29%7B2%7D%7D%0A%5Cput%288%2C1%29%7B%5Cline%281%2C2%29%7B1%7D%7D%0A%5Cput%2810%2C1%29%7B%5Cline%28-1%2C2%29%7B1%7D%7D%0A%5Cend%7Bpicture%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![LaTeX picture 環境範例](/files/2c0652544ab2f711fb1d9307389a96ae10bb6780)

以下是所使用的一些命令摘要：

* `\thicklines`: 這會增加線條的粗細。 `\thinlines` 命令則有相反的效果。
* `\put(8,3.3){{\footnotesize $3$-simplex}}`: 文字「3-simplex」插入在點 `(8,3.3)`，字型大小設為 `\footnotesize`。同一命令也用來標示每個點。
* `\put(9,3){\circle*{0.1}}`: 這會繪製一個實心圓，中心在 `(9,3)` ，直徑很小為 `0.1` （繪圖單位），因此可用作一個點。
* `\put(10,1){\line(3,2){1}}`: 會建立一條起點在 `(10,1)` 且沿著 `(3,2)` 方向繪製、長度為 1（繪圖單位）的直線。

#### 使用箭頭

箭頭也可以在 `picture` 環境中使用，因此這裡有第二個範例：

```latex
\documentclass{article}
\usepackage[pdftex]{pict2e}
\begin{document}
\setlength{\unitlength}{0.20mm}
\begin{picture}(400,250)
\put(75,10){\line(1,0){130}}
\put(75,50){\line(1,0){130}}
\put(75,200){\line(1,0){130}}
\put(120,200){\vector(0,-1){150}}
\put(190,200){\vector(0,-1){190}}
\put(97,120){$\alpha$}
\put(170,120){$\beta$}
\put(220,195){上態}
\put(220,45){下態 1}
\put(220,5){下態 2}
\end{picture}
\end{document}
```

[在 Overleaf 中開啟這個範例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+arrows+in+LaTeX+picture+environment\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%5Bpdftex%5D%7Bpict2e%7D%0A%5Cbegin%7Bdocument%7D%0A%5Csetlength%7B%5Cunitlength%7D%7B0.20mm%7D%0A%5Cbegin%7Bpicture%7D%28400%2C250%29%0A%5Cput%2875%2C10%29%7B%5Cline%281%2C0%29%7B130%7D%7D%0A%5Cput%2875%2C50%29%7B%5Cline%281%2C0%29%7B130%7D%7D%0A%5Cput%2875%2C200%29%7B%5Cline%281%2C0%29%7B130%7D%7D%0A%5Cput%28120%2C200%29%7B%5Cvector%280%2C-1%29%7B150%7D%7D%0A%5Cput%28190%2C200%29%7B%5Cvector%280%2C-1%29%7B190%7D%7D%0A%5Cput%2897%2C120%29%7B%24%5Calpha%24%7D%0A%5Cput%28170%2C120%29%7B%24%5Cbeta%24%7D%0A%5Cput%28220%2C195%29%7Bupper+state%7D%0A%5Cput%28220%2C45%29%7Blower+state+1%7D%0A%5Cput%28220%2C5%29%7Blower+state+2%7D%0A%5Cend%7Bpicture%7D%0A%5Cend%7Bdocument%7D)

此範例會產生以下輸出：

![LaTeX picture 環境中的箭頭範例](/files/f57c987bb4c8d10a39537195cdf681d5853eedde)

該 `\vector` 命令使用與 `\line`:

* `\put(120,200){\vector(0,-1){150}}`相同的語法：會繪製一個向量，其起點是 `(120,200)`，長度是 `150` 且繪製方向是 `(0,-1)`.

## 延伸閱讀

更多資訊請參見以下資源：

* [LaTeX2e 非官方參考手冊](https://latexref.xyz/picture.html)
* [《LaTeX2ε 的不那麼簡短入門》](https://tobi.oetiker.ch/lshort/lshort.pdf) （見第 5 章）
* [Wikibooks](https://en.wikibooks.org/wiki/LaTeX/Picture)
* [標記為 `picture-mode` 於 tex.stackexchange](https://tex.stackexchange.com/questions/tagged/picture-mode)
* [`pict2e` 套件說明文件](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/pict2e/pict2e.pdf)
* [TikZ 套件](/latex/zh-tw/tu-biao-yu-biao-ge/05-tikz-package.md)
* [Pgfplots 套件](/latex/zh-tw/te-ding-ling-yu/08-pgfplots-package.md)
* [圖片與表格的定位](/latex/zh-tw/tu-biao-yu-biao-ge/02-positioning-images-and-tables.md)
* [表格與圖形清單](/latex/zh-tw/tu-biao-yu-biao-ge/03-lists-of-tables-and-figures.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/zh-tw/tu-biao-yu-biao-ge/04-picture-environment.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.
