TikZ 代碼編輯器

將 TikZ 程式碼透過 node-tikzjax 編譯為 SVG

TikZ 代碼
預覽
等待輸入
在左側輸入 TikZ 代碼以查看預覽

範例代碼

點擊「使用此範例」自動貼上並編譯

國中13

junior-01
【國中】一次函數 y=2x+1
% 一次函數 y=2x+1,流派 A(pgfplots)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}
\begin{axis}[
  % axis lines=middle:把座標軸放在原點而非外框,函數圖標準畫法
  axis lines=middle,
  xlabel=$x$, ylabel=$y$,
  % x/y 範圍對稱 [-4,4] + 圖框 10cm × 10cm = 正方形:1 cm 對 1 unit,
  % grid 是正方形格子,符合學生熟悉的「方眼紙」習慣;斜率 2 從圖上目測
  % (上升 2 格 / 右移 1 格)直接看得到。非正方形比例會扭曲斜率視感。
  xmin=-4, xmax=4, ymin=-4, ymax=4,
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  major grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=10cm, height=10cm,
]
% samples=2:直線只需兩點。給多浪費 + 拖慢編譯。
\addplot[blue, thick, samples=2, domain=-3:3] {2*x+1};
\addlegendentry{$y=2x+1$}
% 兩個紅色 mark + 命名點 A / B 標截距,中學課本「截距」概念的視覺錨點
% 加 A、B 點名是中學講課慣例:老師可以講「A 點是 y 截距」「過 B 作對稱點」,
% 比每次唸座標更直觀,後續延伸題(中點、距離、向量 AB)也直接接得起來。
\addplot[mark=*, red] coordinates {(0,1)};
% label 的 axis cs anchor 故意設 (0,0.5) 不是 (0,1):配 above right,
% 文字會落在 mark 點下方右側、貼近 y 軸但不蓋住 mark,避免「文字壓住點」。
% axis cs: 不能省!在 axis env 裡省掉會被當 picture coords 跑到圖外
% 點名 A 整個放 math mode($A(0,1)$ 不是 A$(0,1)$):A 變 math italic,
% 配合中學講義「點/變數用斜體」的排版慣例,跟後續向量 \overrightarrow{AB}
% 等寫法字體一致;另一好處是 A 跟括號 baseline / metrics 自動統一,不會
% 出現文字模式 A 跟 math 模式括號高度對不齊的問題。
\node[red, above right] at (axis cs:0,0.5) {$A(0,1)$};
\addplot[mark=*, red] coordinates {(-0.5,0)};
% \dfrac 強制 display style 分數(比 \frac 大):inline math 內 \frac 會
% 變很小不好讀,圖上的分子分母用 \dfrac 才能跟主文字尺寸對齊。
\node[red, below right] at (axis cs:-0.5,0) {$B(-\dfrac{1}{2},0)$};
\end{axis}
\end{tikzpicture}
junior-02
【國中】二次函數 y=x²-2x+1(拋物線)
% 二次函數 y=x²-2x+1 = (x-1)²,流派 A(pgfplots)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xlabel=$x$, ylabel=$y$,
  xmin=-2, xmax=4, ymin=-1, ymax=5,
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  major grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=10cm, height=8cm,
]
% samples=200:拋物線需要密集採樣才平滑。1000 會超時,200 是甜蜜點。
% domain=-1.5:3.5:domain 比 xmin/xmax 略窄,避免曲線在邊框外伸出去。
\addplot[blue, thick, samples=200, domain=-1.5:3.5] {x^2-2*x+1};
\addlegendentry{$y=x^2-2x+1$}
% 頂點 (1,0) 用 red mark + 標 vertex:中學二次函數核心概念是頂點,
% 不標頂點等於少了 50% 教學價值。
\addplot[mark=*, red] coordinates {(1,0)};
\node[red, above right] at (axis cs:1,0) {$(1,0)$ vertex};
% 對稱軸 x=1 用 dashed gray:視覺強化「拋物線左右對稱」這個性質。
% 為什麼用 \addplot coordinates 而不是 \draw:axis env 內 \draw 會用
% picture coords 跑掉,要嘛改 axis cs: 要嘛就用 \addplot 統一。
\addplot[dashed, gray, thick] coordinates {(1,-1) (1,5)};
\end{axis}
\end{tikzpicture}
junior-03
【國中】二元一次聯立方程式(交點)
% 二元一次聯立方程式 y=x+1 與 y=-x+3,流派 A(pgfplots)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xlabel=$x$, ylabel=$y$,
  % x/y 範圍 [-3,5] + 圖框 10cm × 10cm 正方形:1 cm 對 1 unit,grid 是方形
  % 格子,斜率 ±1 從圖上目測(右上 1 / 左上 1)直接看得出。範圍對稱於
  % 交點 (1,2) 周圍,兩條直線在四個方向都伸得出去看得到斜率。
  xmin=-3, xmax=5, ymin=-3, ymax=5,
  % 單層 grid (.2pt, gray!50):移除原本的 minor + major 兩層設計。
  % 兩層的好處是「主刻度線比次要線粗」帶層級感,但對「找交點」這類目的
  % 反而是視覺雜訊;單層所有格線同樣粗細,讓使用者注意力直接聚焦在兩線交點。
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=10cm, height=10cm,
]
% 兩條直線顏色 blue/red 對比強烈,「兩線」概念一秒識別。同色會混。
% 沒有 samples=:直線不需要(pgfplots 預設對 polynomial 自動兩點)。
\addplot[blue, thick, domain=-3:5] {x+1};
\addlegendentry{$y=x+1$}
\addplot[red, thick, domain=-3:5] {-x+3};
\addlegendentry{$y=-x+3$}
% 交點 (1,2) 用 black mark + label:三色平衡,交點當主角不被兩條線搶戲。
\addplot[mark=*, black] coordinates {(1,2)};
% label anchor 故意設 (1.25, 1.7) 不是 (1,2):兩條直線在交點處 X 形相交,
% 把 label 直接放交點上方會擠進兩條線中間;挪到「右下方一點點」避開所有
% 交叉路徑,文字坐落在 X 形右下空白象限,視覺最乾淨。
\node[above right] at (axis cs:1.25,1.7) {$(1,2)$};
\end{axis}
\end{tikzpicture}
junior-04
【國中】畢氏定理(直角三角形 3-4-5)
% 畢氏定理視覺化 3-4-5,流派 B(純 TikZ 幾何)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}[scale=1.2]
\coordinate[label=above:$A$] (A) at (0,3);
\coordinate[label=below left:$B$] (B) at (0,0);
\coordinate[label=below right:$C$] (C) at (4,0);

% z-order 順序很重要:TikZ 後畫的疊在前畫的之上。
% 兩個 a²/b² 正方形要在「最底層」,不然會蓋掉邊長 label;
% 三角形 + 直角符號 + 邊長 label 全部後畫,確保浮在正方形之上。

% 兩個正方形 a²、b² 用淡藍/淡紅(blue!10、red!10):配色與 c²(藍邊主三角形)呼應,
% 但又區分得開。塗實色會蓋掉旁邊的標籤,所以**只能用 !10 等淡色。
% ++(...) 用相對位移畫正方形,比硬寫絕對座標好讀(改邊長只要動一個數字)。
\fill[blue!10] (A) -- (B) -- ++(-3,0) -- ++(0,3) -- cycle;
\node at (-1.5,1.5) {$3^2=9$};

\fill[red!10] (B) -- (C) -- ++(0,-4) -- ++(-4,0) -- cycle;
\node at (2,-2) {$4^2=16$};

% 三角形主體放在正方形之後畫,邊線浮在 fill 之上看得清楚
\draw[thick, blue] (A) -- (B) -- (C) -- cycle;

% 直角符號 rectangle ++(0.3,0.3):直角三角形 must-have。
% 0.3 unit 是縮圖也看得到的最小邊長;0.2 在 SampleCard 縮成糊點。
\draw (B) rectangle ++(0.3,0.3);

% 邊長用 \overline{AB} 而非裸 AB:中學慣例,\overline 表示「線段」,
% 裸 AB 在數學上指「直線 AB」(無限延伸)。線段長 \overline{AB}=3 是
% 約定俗成寫法(嚴格寫應 |\overline{AB}|=3 但中學省略絕對值)。
% 邊長 label 位置:BC 底邊用 below;AB 左邊用 left;
% AC 斜邊用 [above right, sloped] 才會跟邊平行,不然字橫躺會擠到三角形內。
% AB label y=1 不是 1.5:正方形內的 $3^2=9$ 在 (−1.5, 1.5),如果 AB
% 也放 y=1.5 兩個 label 會同一水平、視覺上連成「$3^2=9 \overline{AB}=3$」
% 一條長字串。錯開 0.5 unit 讓兩 label 各據其位、視線一眼能分開。
\node[below] at (2,0) {$\overline{BC}=4$};
\node[left] at (0,1) {$\overline{AB}=3$};
\node[above right, sloped] at (2,1.5) {$\overline{AC}=5$};

\node[above] at (3.5,3.5) {$3^2+4^2=5^2$};
\end{tikzpicture}
junior-05
【國中】等腰三角形(含底角標記)
% 等腰三角形 + 底角相等標記,流派 B(純 TikZ 幾何 + angles+quotes)。設計原則詳見 ../DESIGN_NOTES.md
\usetikzlibrary{angles,quotes}
\begin{tikzpicture}[scale=1.5]
\coordinate[label=above:$A$] (A) at (2,3);
\coordinate[label=below left:$B$] (B) at (0,0);
\coordinate[label=below right:$C$] (C) at (4,0);

% 兩個底角都標 \beta(同符號)= 視覺上直接告訴學生「等腰 → 底角相等」,
% 不需要額外文字解釋。這是「圖即定理」的設計。底角故意都用 8mm 統一以強調「同」。
% **兩 beta 用同色**(green!60!black + green!15 fill):同符號 + 同色雙重強調
% 「相等」概念。如果用不同色會破壞 invariant 的視覺直覺。
% angle eccentricity=1.4:label 推到弧外面 1.4 倍距離,避免標籤跟弧重疊。
% 1.0 = 弧上(被弧切過);1.6+ 跑太遠;1.4 = 弧外清晰。
% pic 中 angle = C--B--A 表示在 B 角畫弧;頂點放中間是 TikZ 慣例。
% 順序:\pic 在 \draw 邊之前畫 → 後面 thick blue 邊蓋在 fill 之上,
% 確保三角形邊在角度弧之上(z-order)。
\pic [draw=green!60!black, thick, fill=green!15, angle radius=8mm, angle eccentricity=1.4, "$\beta$"] {angle = C--B--A};
\pic [draw=green!60!black, thick, fill=green!15, angle radius=8mm, angle eccentricity=1.4, "$\beta$"] {angle = A--C--B};
% 頂角 \alpha:不放 pic 內建 "$\alpha$" label。pic 的 quotes label 沿 bisector
% 推出去,但 ∠A 的 bisector 正好沿中線方向 — \alpha 會貼在中線上很難讀。
% 改用獨立 \node 把符號推到中線右側 (2.2, 2.45);仍在 ∠A 內、距 A 點
% ~0.58 unit > 6mm 弧半徑,落在弧外。
\pic [draw=red, thick, fill=red!15, angle radius=6mm] {angle = B--A--C};
\node[red] at (2.2, 2.45) {$\alpha$};

% 邊放在 \pic 之後:fill 先畫,thick blue 邊蓋在弧 fill 楔形邊緣上,
% 三角形主結構視覺上在角度標記之上。
\draw[thick, blue] (A) -- (B) -- (C) -- cycle;

\node[left, sloped] at (1, 1.6) {$\overline{AB}$};
\node[right, sloped] at (3, 1.6) {$\overline{AC}$};
% BC label y=-0.45:M 點在 (2,0)、M label 用 [below] 錨點落在 ~y=-0.15。
% 把 BC 拉到 -0.45 跟 M 拉開 ~0.3 unit(scale=1.5 下 ~4.5mm),
% 兩個 label 不再貼著。
\node[below] at (2,-0.45) {$\overline{BC}$};

% 中線 (A) -- (2,0) 虛線 + 標 M:展示「等腰三角形頂角的角平分線就是底邊的垂直平分線」,
% 教學上是核心性質。
\draw[thick, dashed] (A) -- (2,0);
\filldraw (2,0) circle (1pt) node[below] {$M$};
\end{tikzpicture}
junior-06
【國中】平行四邊形(含對角線)
% 平行四邊形 + 對角線交點,流派 B(純 TikZ 幾何)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}[scale=1.2]
% 平行四邊形傾斜偏移 (1.5,2.5):故意不畫成「正四邊形」(C 在 B 正上方),
% 傾斜形狀更能突出「平行四邊形 ≠ 矩形」的差異。
\coordinate[label=below left:$A$] (A) at (0,0);
\coordinate[label=below right:$B$] (B) at (4,0);
\coordinate[label=above right:$C$] (C) at (5.5,2.5);
\coordinate[label=above left:$D$] (D) at (1.5,2.5);

\draw[thick, blue] (A) -- (B) -- (C) -- (D) -- cycle;
% 對角線兩條都用 dashed red:虛線提示「輔助線」(不是平行四邊形的邊),
% 紅色與藍色邊形成對比。雙紅虛線 + 中點 M 視覺強調「對角線互相平分」。
\draw[thick, dashed, red] (A) -- (C);
\draw[thick, dashed, red] (B) -- (D);

% M 點用 circle (1.5pt) 比邊上的點略大:中點是性質的核心,點大強調主角。
% 標籤改用 [above=2pt]:對角線在 M 處切出四個楔形,正上方楔形(約 24°→135°)最寬,
% 不會壓到 AC(往右上)或 BD(往左上)兩條紅虛線。
\coordinate (M) at (2.75, 1.25);
\filldraw (M) circle (1.5pt) node[above=2pt] {$M$};

% 只標兩條對邊 AB、CD:其他兩條對邊不重複標,避免擁擠。
% 學生看到 AB ∥ CD 能自己推出 AD ∥ BC。
\node[below] at (2,0) {$\overline{AB}$};
\node[above] at (3.5,2.5) {$\overline{CD}$};
\end{tikzpicture}
junior-07
【國中】圓與切線、半徑、弦
% 圓的切線、半徑、弦,流派 B(純 TikZ 幾何 + calc library)。設計原則詳見 ../DESIGN_NOTES.md
% 三色語意:藍=主圓 / 紅=切線 / 紫=弦,正好對應中學圓的三大要素。
\begin{tikzpicture}[scale=1.5]
\draw[thick, blue] (0,0) circle (2);
\filldraw (0,0) circle (1.2pt) node[below left] {$O$};

% 半徑用 \draw[->]:加箭頭強調「從圓心向外」的方向感,符合中學課本繪法。
% r label 用 midway+sloped+below 推到線的右下側,避免文字壓在半徑線上。
% 上側(above)會被切線蓋到,下側(below)是空的,所以選 below。
\draw[->, thick] (0,0) -- (60:2) node[midway, sloped, below] {$r$};

\coordinate (P) at (60:2);
\filldraw (P) circle (1.2pt) node[above right] {$P$};
% 切線位移 (-1.7,0.98) 與 (1.7,-0.98):這是 P 點(60° 處)的切線方向單位向量 × 1.7,
% 即 (cos150°, sin150°)×1.7 ≈ (-1.47, 0.85)... 實際手工微調讓切線在 P 兩側等長。
% 寫 ($(P)+(60+90:1.7)$)(極座標旋轉 90°)更語意清楚也可以。
\draw[red, thick] ($(P)+(-1.7,0.98)$) -- ($(P)+(1.7,-0.98)$);
% 切線 ⊥ 半徑(切線性質)的直角符號:從 P 沿半徑反方向(240°)+ 切線方向(-30°)
% 各推 0.18 unit 畫 L 形。放在切線 \draw 之後,直角線不會被切線蓋住。
% 選右下側(240°+(-30°))而非左上側(60°+150°),因為 P label 在右上、
% \ell label 在右,左上跟弦端 Q 鄰近 — 右下是視覺上最空的象限。
\draw ($(P)+(240:0.18)$) -- ($(P)+(240:0.18)+(-30:0.18)$) -- ($(P)+(-30:0.18)$);
% \ell 是課本慣例的直線命名(花體 l)。「(tangent)」用英文不用中文 —
% \node 內中文會 UTF-8 silent timeout。見 README.md §4-1。
\node[red, right] at ($(P)+(1.7,-0.98)$) {$\ell$ (tangent)};

\coordinate (Q) at (200:2);
\coordinate (R) at (340:2);
\draw[thick, dashed, purple] (Q) -- (R);
% 弦 y ≈ -0.684(Q/R 都在 200°/340°);label 用 (270:1.0) → (0,-1.0),
% 離弦 ~0.32 unit,文字貼著弦但不疊上去。
\node[purple] at (270:1.0) {chord $\overline{QR}$};
\filldraw (Q) circle (1.2pt) node[left] {$Q$};
\filldraw (R) circle (1.2pt) node[right] {$R$};
\end{tikzpicture}
junior-08
【國中】圓周角與圓心角
% 圓周角與圓心角(2倍關係),流派 B(純 TikZ + angles+quotes + positioning)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}[scale=1.5]
\draw[thick, blue] (0,0) circle (2);

% C 點放上方 (90°)、A/B 在下方:讓圓周角從上俯瞰下方弦 AB,圓心角在中間。
% 這個 layout 比 A/B/C 都在同側更能讓兩個角不重疊。
\coordinate (O) at (0,0);
\coordinate (A) at (200:2);
\coordinate (B) at (-20:2);
\coordinate (C) at (90:2);

% 兩個角故意用對應顏色:紅=圓心角(2θ)、綠=圓周角(θ)。
% 色彩同時強化「他們對著同一條弧 AB」這個概念。
% green!60!black 而不是 green:純綠在白底上糊掉,加 40% 黑提升對比。
\draw[thick, red] (A) -- (O) -- (B);
\draw[thick, green!60!black] (A) -- (C) -- (B);

% angle = A--O--B 從 OA(200°)逆時針掃到 OB(340°)= 140°,弧落在下方(不含 C 的那條弧),
% 與圓周角 ∠ACB 對到同一條弧。寫反成 B--O--A 會掃 220° 經過 C,變成對到大弧、2θ 關係不成立。
\pic [draw=red, angle radius=6mm, "$2\theta$"] {angle = A--O--B};
\pic [draw=green!60!black, angle radius=6mm, "$\theta$"] {angle = A--C--B};

% 點放在線/弧之後畫,z-order 才會「點在線上面」(否則 thick 線比 1.2pt 點還粗,點會被蓋住中心)。
% O 的 label 放正上方:2θ 紅弧落在 O 下方,放 [below] 會疊到文字;O 上方至 C 是空白沒線。
\filldraw (O) circle (1pt) node[above] {$O$};
\filldraw (A) circle (1.2pt) node[left] {$A$};
\filldraw (B) circle (1.2pt) node[right] {$B$};
\filldraw (C) circle (1.2pt) node[above] {$C$};

% 說明文字放在圓的正下方(圓外):
% scale=1.5、半徑 2 → 圓底視覺位於 (0,-3cm)。原本 [below=10mm of O] 只下移 1cm,
% 文字被吃進圓的內部,壓在 2θ 紅弧附近,既擠又難看。
% 改成 at (0,-2.2) + [below]:在 TikZ 座標往下到 -2.2 (視覺 -3.3cm),
% 比圓底再多 3mm 留白,文字就完全落在圓外正下方。
\node[below, align=center] at (0,-2.2) {central angle $=2\times$ inscribed angle};
\end{tikzpicture}
junior-09
【國中】統計長條圖(各班人數)
% 統計長條圖,流派 A(pgfplots,但用 ybar 不是 axis lines=middle)。設計原則詳見 ../DESIGN_NOTES.md
% 沒有 axis lines=middle:類別軸沒有「原點」概念,軸該畫在邊框(預設 box 樣式)。
% 這跟函數圖的設計慣例剛好相反 — 統計圖要 box,函數圖要 middle。
\begin{tikzpicture}
\begin{axis}[
  ybar,
  xlabel={Class},
  ylabel={Students},
  % symbolic x coords:不能用「一班、二班」中文,UTF-8 active token 會 silent timeout。
  % 班名要用 ASCII;真要中文意涵就在 ylabel 或圖標題加英文翻譯。
  symbolic x coords={A,B,C,D,E},
  xtick=data,
  ymin=0, ymax=40,
  % bar width=0.6cm + enlarge x limits=0.15:bar 寬 0.6cm 配 15% 邊距,
  % 讓 bar 之間有呼吸空間。bar=1cm 太擠;bar=0.3cm 太瘦看不到色塊。
  bar width=0.6cm,
  width=11cm, height=7cm,
  % nodes near coords:在每根 bar 上方標數值。中學統計題核心目標是「讀數據」,
  % 不標數字等於圖只剩美感沒有資訊。
  nodes near coords,
  nodes near coords style={font=\small},
  enlarge x limits=0.15,
]
% fill=blue!50 + draw=blue!70!black:邊比填色深一階,bar 有立體感不會糊成一片。
% 所有 ybar 樣本都該照這個慣例。
\addplot[fill=blue!50, draw=blue!70!black] coordinates {
  (A,32) (B,28) (C,35) (D,30) (E,33)
};
\end{axis}
\end{tikzpicture}
junior-10
【國中】機率樹(投兩次硬幣)
% 機率樹(投兩次硬幣),流派 C(特殊樹結構)。設計原則詳見 ../DESIGN_NOTES.md
% 用 TikZ child {...} 樹語法而不是手動 \draw:結構清楚、改層級不必重算座標。
% 代價是語法陡峭(熟了之後是高階 TikZ 經典題型)。
\begin{tikzpicture}[
  % level 1/level 2 分開設:第 1 層 sibling 5cm 拉開兩主分支(H/T),
  % 第 2 層 sibling 縮到 2.2cm 因為節點變多。兩層用同 sibling 距離會擠到不能讀。
  level 1/.style={sibling distance=5cm, level distance=2.2cm},
  level 2/.style={sibling distance=2.2cm, level distance=2.2cm},
  % every node/.style:節點外型統一一個地方控制。改成 oval 或拿掉 draw 一行就改完。
  every node/.style={circle, draw, minimum size=8mm, font=\small},
  % >=latex 箭頭風格:不用 >=Stealth(arrows.meta library 在 bundle 不穩,見 README §4-3)。
  edge from parent/.style={draw, ->, >=latex}
]
% phantom path 點 (0,0.7) 強制 bbox 上緣抬到 y=0.7,防止 dvisvgm 算 SVG
% viewBox 時把 root(Start)節點上緣 stroke 切掉。outer sep 只動 anchor、
% 不影響 bbox,沒用;只能用 \path 顯式擴 bbox。
\path (0,0.7);
% edge from parent node[draw=none, ...]:draw=none 必須要寫,
% 不然 1/2 標籤會被 every node 的圓圈套住變泡泡。
% 機率值用 \dfrac{1}{2} 不是 0.5:中學課本慣例分數,展現「一半」的概念。
\node {Start}
  child { node {$H$}
    child { node {$H$} edge from parent node[left, draw=none, font=\scriptsize]{$\dfrac{1}{2}$} }
    child { node {$T$} edge from parent node[right, draw=none, font=\scriptsize]{$\dfrac{1}{2}$} }
    edge from parent node[left, draw=none, font=\scriptsize]{$\dfrac{1}{2}$}
  }
  child { node {$T$}
    child { node {$H$} edge from parent node[left, draw=none, font=\scriptsize]{$\dfrac{1}{2}$} }
    child { node {$T$} edge from parent node[right, draw=none, font=\scriptsize]{$\dfrac{1}{2}$} }
    edge from parent node[right, draw=none, font=\scriptsize]{$\dfrac{1}{2}$}
  };

\node[draw=none] at (-3.5,-5.1) {$P(HH)=\dfrac{1}{4}$};
\end{tikzpicture}
junior-11
【國中】直方圖(成績分布)
% 直方圖(成績分布),流派 A(pgfplots ybar interval)。設計原則詳見 ../DESIGN_NOTES.md
% 直方圖 vs 長條圖(09 號)的關鍵差異:
% - 長條圖 = 類別資料(ybar + symbolic x coords):x 軸是離散類別,
%   bar 與 bar 之間有間隙,順序可換。
% - 直方圖 = 連續資料分組(ybar interval):x 軸是連續數值刻度(40, 50, 60...),
%   bar 之間沒有間隙(代表分數連續),不能換順序。
\begin{tikzpicture}
\begin{axis}[
  % ybar interval 自動讓 bar 緊靠不留空隙,符合直方圖的視覺定義。
  ybar interval,
  xlabel={Score},
  ylabel={Frequency},
  xmin=40, xmax=100,
  ymin=0, ymax=15,
  width=11cm, height=7cm,
  % xtick={40,50,...,100}:強制每 10 分一個刻度。pgfplots 自動可能跳到每 20 一格,
  % 失去組距資訊。
  xtick={40,50,60,70,80,90,100},
]
% 不加 nodes near coords:直方圖看的是「分布形狀」,不是精確數字。加了反而擁擠失焦。
% 長條圖才該標數字。
% 資料最後一筆是 (100, 0):ybar interval 用「左閉右開」區間,要畫到 90~100 區間
% 就需要再給一個 (100, ...) 當右界。給 0 表示「100 分以上沒有人」,不影響視覺。
% 少了這筆 (100, 0) 最後一根 bar 不會出現。
\addplot+[fill=blue!40, draw=blue!70!black] coordinates {
  (40,2) (50,5) (60,8) (70,12) (80,9) (90,4) (100,0)
};
\end{axis}
\end{tikzpicture}
junior-12
【國中】相似三角形
% 相似三角形(1:2 比例),流派 B(純 TikZ + scope shift 並列)。設計原則詳見 ../DESIGN_NOTES.md
% 大小三角形形狀完全相同(同樣的角度):小三角形 (0,0)(3,0)(1,3),
% 大三角形 (0,0)(6,0)(2,6),所有座標 ×2。視覺上一秒看出「相似 = 等比放大」。
\begin{tikzpicture}[scale=1]
\coordinate[label=above:$A$] (A) at (1,3);
\coordinate[label=below left:$B$] (B) at (0,0);
\coordinate[label=below right:$C$] (C) at (3,0);
\draw[thick, blue] (A) -- (B) -- (C) -- cycle;
% 邊長標 3 / 6:刻意只標一邊(底邊),其他邊不標,因為相似 = 所有邊同比,
% 標一邊就夠。多標只是視覺噪音。
\node[below] at (1.5,0) {$3$};

% scope[shift={(5,0)}] 把第二個三角形平移到右邊:scope 內所有座標都自動偏移 (5,0),
% 程式碼不必手動加 5。改距離只動一個數字。
% 大三角形用紅色:跟小三角形(藍)區分,視覺上可清楚對應「兩個圖形」。
\begin{scope}[shift={(5,0)}]
\coordinate[label=above:$A'$] (Ap) at (2,6);
\coordinate[label=below left:$B'$] (Bp) at (0,0);
\coordinate[label=below right:$C'$] (Cp) at (6,0);
\draw[thick, red] (Ap) -- (Bp) -- (Cp) -- cycle;
\node[below] at (3,0) {$6$};
\end{scope}

% \sim 符號放兩個三角形中間 at (4, 1.5):這個位置剛好在兩個三角形高度的中間,
% 符合「A 相似於 B」的數學排版。
\node at (4,1.5) {$\sim$};
% 比例 ratio 1:2 寫在中央下方,用 align=center 多行置中。
% \\\\ 是兩條反斜線(JS 字串裡 escape 一次,變成 \\ 在 TikZ 內 = LaTeX 換行符)。
\node[align=center] at (4.5,-1.5)
  {$\triangle ABC \sim \triangle A'B'C'$\\ratio $1:2$};
\end{tikzpicture}
junior-13
【國中】三角形角度標記範例
% 三角形角度標記範例(三組三角形展示 angles+quotes 用法),流派 B(純 TikZ)。
% 設計原則詳見 ../DESIGN_NOTES.md
%
% 這支樣本同時是引擎的 UTF-8 trap canary:"$60^\circ$" 故意用 ASCII ^\circ 而非 UTF-8 °。
% 如果未來有人「優化」程式碼把 ^\circ 換回 °,validator 會立刻在這支樣本上 timeout
% (因為 node-tikzjax 對非 ASCII active token silent hang 10 秒),
% 把潛在 regression 從「靜默」變「紅燈」。詳見 README §4-1。
%
% 為什麼放在 shift 而不是分三個 tikzpicture:SampleCard 一次顯示一張 SVG。
% 三個分開要寫成三個樣本(膨脹清單),不如一張圖三個範例,讓學生一眼學會三種寫法。
%
% pic 角度語法的雷區:angle = A--B--C 中間 B 是頂點,A、C 是邊端點。
% 寫成 angle = B--A--C 也能畫出來但變成在 A 角畫弧(可能不是你想要的)。
% 慣例:頂點放中間。
\usetikzlibrary{angles,quotes}
\begin{tikzpicture}[scale=2]
% 第一組(原點):三個內角 α/β/γ 同時標記,展示「同色不同 radius」(8mm/6mm/7mm)
% 讓三個弧不重疊。β 用 fill=blue!20 色塊強調某一角是研究對象的常用招式。
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\coordinate (C) at (2,2);
\draw[thick] (A) -- (B) -- (C) -- cycle;
\pic [draw, angle radius=8mm, "$\alpha$"] {angle = B--A--C};
\pic [draw, fill=blue!20, angle radius=6mm, "$\beta$"] {angle = C--B--A};
\pic [draw, angle radius=7mm, "$\gamma$"] {angle = A--C--B};
\filldraw (A) circle (1pt) node[below left] {$A$};
\filldraw (B) circle (1pt) node[below right] {$B$};
\filldraw (C) circle (1pt) node[above] {$C$};

% 第二組(右上 shift 5,0):right angle pic 畫直角小方框 + 普通弧標 θ。
% 右角用 angle radius=4mm 比一般弧小,因為方框本身就有大小,弧太大會超出三角形邊。
\begin{scope}[shift={(5,0)}]
\coordinate (D) at (0,0);
\coordinate (E) at (2,0);
\coordinate (F) at (0,1.5);
\draw[thick] (D) -- (E) -- (F) -- cycle;
\pic [draw, angle radius=4mm] {right angle = E--D--F};
\pic [draw, angle radius=6mm, "$\theta$"] {angle = F--E--D};
\filldraw (D) circle (1pt) node[below left] {$D$};
\filldraw (E) circle (1pt) node[below right] {$E$};
\filldraw (F) circle (1pt) node[above left] {$F$};
\end{scope}

% 第三組(下方 shift 0,-3):具體角度 60° + 抽象 φ 對比 + 顏色填充。
% angle eccentricity=1.3 把 60° label 推到弧外避免重疊。
% 注意:使用 ^\circ 而非 UTF-8 度數符號(canary)。
\begin{scope}[shift={(0,-3)}]
\coordinate (P) at (0,0);
\coordinate (Q) at (3,0);
\coordinate (R) at (1,2);
\draw[thick] (P) -- (Q) -- (R) -- cycle;
\pic [draw=red, thick, angle radius=10mm, angle eccentricity=1.3, "$60^\circ$"] {angle = Q--P--R};
\pic [draw=green, fill=green!30, angle radius=8mm, "$\phi$"] {angle = R--Q--P};
\filldraw (P) circle (1pt) node[below left] {$P$};
\filldraw (Q) circle (1pt) node[below right] {$Q$};
\filldraw (R) circle (1pt) node[above] {$R$};
\end{scope}
\end{tikzpicture}

高中12

senior-01
【高中】三角函數 sin/cos 圖
% 三角函數 sin/cos 圖,流派 A(pgfplots)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xlabel=$x$, ylabel=$y$,
  xmin=-7, xmax=7, ymin=-1.5, ymax=1.5,
  % xtick 寫數值 -6.28/-3.14/0/3.14/6.28,但 xticklabels 顯示成符號 -2π/-π/0/π/2π。
  % 寫 xticklabels={π/2} 但裡面 π 是 Unicode 會 silent timeout,
  % 必須用 $\pi$(LaTeX 數學模式)。
  xtick={-6.28,-3.14,0,3.14,6.28},
  xticklabels={$-2\pi$,$-\pi$,$0$,$\pi$,$2\pi$},
  % enlarge y limits=0.05:sin/cos 最大值 1 剛好碰到 ymax=1.5 的話曲線頂端會貼到框邊。
  % enlarge 在計算後加邊距讓曲線不貼邊。
  enlarge y limits=0.05,
  ytick={-1,0,1},
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=12cm, height=6cm,
  % legend pos=north east:預設位置可能擋到曲線,手動指定。
  legend pos=north east,
]
% samples=300:三角函數週期密集需要更多採樣點才不抖。
% 200 在 -2π~2π 範圍會看到鋸齒,400 開始拖慢編譯。300 是 2π 函數的甜蜜點。
% {sin(deg(x))} 不是 {sin(x)}:pgfplots 的 sin 預設用度數,
% 寫 sin(x) 在 domain=-6.28:6.28 會看到極平緩近水平的線(因為 6.28 度是非常小的角度)。
% deg(x) 把 radian 轉度數。
\addplot[blue, thick, samples=300, domain=-6.28:6.28] {sin(deg(x))};
\addlegendentry{$y=\sin x$}
% cos 用 dashed 跟 sin 區分:除了顏色之外加線型差異,印黑白也分得開。
\addplot[red, thick, dashed, samples=300, domain=-6.28:6.28] {cos(deg(x))};
\addlegendentry{$y=\cos x$}
\end{axis}
\end{tikzpicture}
senior-02
【高中】單位圓與 30°/60° 角
% 單位圓與 30°/60° 角,流派 B(純 TikZ + 極座標)。設計原則詳見 ../DESIGN_NOTES.md
% scale=2.2:單位圓只有 1 unit 半徑,scale=1 會在 SampleCard 縮成小圓。
% 2.2 讓圓佔卡片約 80% 寬度,內部標籤都看得清。
\begin{tikzpicture}[scale=2.2]
% 軸用 gray 不用 black:這支圖主角是圓和角度,軸只是 reference,降到灰色避免搶戲。
\draw[->, gray] (-1.3,0) -- (1.3,0) node[right] {$x$};
\draw[->, gray] (0,-1.3) -- (0,1.3) node[above] {$y$};

\draw[thick, blue] (0,0) circle (1);

% 極座標 (30:1):1 是半徑、30 是角度。比手算 ($(0.866,0.5)$) 直觀且
% 不會因四捨五入誤差讓點偏離圓邊。
\draw[thick, red] (0,0) -- (30:1);
\fill[red] (30:1) circle (0.025);
% 座標值用分數而不是 0.866,因為這是中學重點要記的特殊角座標。
\node[red, above right] at (30:1) {$(\frac{\sqrt{3}}{2},\frac{1}{2})$};
% 角度弧用兩個不同 radius(0.3 vs 0.5):30° 弧內、60° 弧外,避免兩個弧重疊。
% 同 radius 會疊成一團不能讀。
\draw (0.3,0) arc (0:30:0.3);
% $30^\circ$ 而不是 30°:° 是 UTF-8 active token 會 silent timeout,見 README §4-1。
\node at (0.4,0.1) {\scriptsize $30^\circ$};

\draw[thick, green!60!black] (0,0) -- (60:1);
\fill[green!60!black] (60:1) circle (0.025);
\node[green!60!black, above right] at (60:1) {$(\frac{1}{2},\frac{\sqrt{3}}{2})$};
\draw (0.5,0) arc (0:60:0.5);
\node at (0.55,0.32) {\scriptsize $60^\circ$};

% (30:1 |- 0,0):TikZ 路徑運算,取 30:1 點的 x、原點的 y(交叉點),等於畫垂直投影。
% 比手算 (0.866, 0) 簡潔且不會跑掉。
\draw[dashed, gray!70] (30:1) -- (30:1 |- 0,0);
\draw[dashed, gray!70] (60:1) -- (60:1 |- 0,0);
\end{tikzpicture}
senior-03
【高中】指數函數與對數函數
% 指數與對數函數對照圖,流派 A(pgfplots)。設計原則詳見 ../DESIGN_NOTES.md
% 三條曲線視覺化「指數函數 y=2^x 與對數函數 y=log_2 x 互為反函數」這個高中核心概念。
% y=x 虛線就是「對稱軸」,兩條主曲線對它鏡射。
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xlabel=$x$, ylabel=$y$,
  xmin=-3, xmax=5, ymin=-3, ymax=5,
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=10cm, height=8cm,
  % legend pos=north west:左上角是這個圖唯一的「空白區域」(指數曲線在右半,
  % 對數曲線在右下,左上沒東西),把 legend 塞在那裡不擋圖。
  legend pos=north west,
  % legend cell align=left:三個 entry 都以 $y=$ 開頭,字數不同。
  % pgfplots 預設 cell 置中(短的 y=x 會內縮),改 left 讓 y= 起點對齊。
  legend cell align={left},
]
% 指數 domain 上限 2(不是 5):2^5=32 會讓圖被 32 拉伸到完全失衡;
% 2^2=4 剛好在 ymax=5 內,曲線飽滿但不爆框。
\addplot[blue, thick, samples=200, domain=-3:2] {2^x};
\addlegendentry{$y=2^x$}
% log 用 ln(x)/ln(2):pgfplots 沒有直接的 log_2,要用換底公式。
% log domain 從 0.05 開始:log 在 x→0 時趨近 -∞,從 0 開始會崩潰
% (除以 0 或極大負數渲染失敗)。0.05 是「靠近 0 但不會數值爆炸」的甜蜜點。
\addplot[red, thick, samples=200, domain=0.05:5] {ln(x)/ln(2)};
\addlegendentry{$y=\log_2 x$}
\addplot[gray, dashed, samples=2, domain=-3:5] {x};
\addlegendentry{$y=x$}
\end{axis}
\end{tikzpicture}
senior-04
【高中】向量加法(平行四邊形法)
% 向量加法(平行四邊形法則),流派 B(純 TikZ,自繪坐標軸非 axis env)。設計原則詳見 ../DESIGN_NOTES.md
% 為什麼用純 TikZ 而不是 pgfplots:向量加法重點是「箭頭與平移」,
% pgfplots 的 axis env 不適合畫帶箭頭線段(\addplot 不直覺)。
% 純 TikZ + \draw[->] 寫法更直覺。
\begin{tikzpicture}[scale=1]
% 格線用 gray!20 very thin:比函數圖的 gray!30 更淡,因為向量圖要讀的是箭頭方向不是格點,
% 格線要更隱形。
\draw[step=1, gray!20, very thin] (-0.5,-0.5) grid (5.5,5.5);
\draw[->, gray!50] (-0.5,0) -- (5.5,0) node[right] {$x$};
\draw[->, gray!50] (0,-0.5) -- (0,5.5) node[above] {$y$};

% 兩個原向量 a、b 用實線(blue/red)。(0,0)、(3,1)、(1,3)、(4,4) 都是整數格點:
% 好用 step=1 網格驗證。坐標非整數會讓「平行四邊形」概念失焦。
\draw[->, thick, blue] (0,0) -- (3,1) node[midway, below right] {$\vec{a}$};
\draw[->, thick, red] (0,0) -- (1,3) node[midway, above left] {$\vec{b}$};

% 平移後的副本用 dashed + !60 淡色:dashed 暗示「這是輔助結構」,淡色避免搶戲。
% 學生一看就知道:虛線 = 平移出來的、實線 = 原向量。
\draw[->, dashed, blue!60] (1,3) -- (4,4);
\draw[->, dashed, red!60] (3,1) -- (4,4);

% \vec{a}+\vec{b} 用 purple + very thick:結果向量必須最粗最顯眼。
\draw[->, thick, purple, very thick] (0,0) -- (4,4) node[midway, above, sloped] {$\vec{a}+\vec{b}$};

\filldraw[blue] (3,1) circle (1.5pt);
\filldraw[red] (1,3) circle (1.5pt);
% 終點 (4,4) 標 circle (2pt)(比起點大):結果在哪是核心,點放大強調。
\filldraw[purple] (4,4) circle (2pt);

\node[below right] at (3,1) {$(3,1)$};
\node[above left] at (1,3) {$(1,3)$};
\node[above right] at (4,4) {$(4,4)$};
\end{tikzpicture}
senior-05
【高中】圓錐曲線:橢圓 x²/9+y²/4=1
% 橢圓 x²/9 + y²/4 = 1,流派 A(pgfplots,參數方程畫法)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xlabel=$x$, ylabel=$y$,
  xmin=-5, xmax=5, ymin=-4, ymax=4,
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=11cm, height=11cm,
  % axis equal image:強制 x/y 比例 1:1。沒加的話 pgfplots 會自動拉伸讓圖填滿
  % width×height,橢圓會變成「拉長的橢圓」失去形狀。橢圓/圓錐曲線題目必須加。
  axis equal image,
  % legend 用 \dfrac 文字明顯比一般 baseline text 高,預設 frame 太緊;
  % inner ysep 加到 5pt 讓上下留空。marker 純幾何中心算下來應在 baseline
  % +2.8pt(\dfrac 上緣 ~+9pt / 下緣 ~-3.4pt 平均),但實際 render 後肉眼看
  % marker 偏高 — 大概是 \dfrac 的視覺重心因分母數字較重在下方,所以改用
  % 經驗值 yshift=-2pt(marker 落到 baseline 之下),視覺最平衡。
  legend cell align={left},
  legend style={font=\small, inner sep=4pt, inner ysep=5pt},
  legend image post style={yshift=-2pt},
]
% 參數方程 ({3*cos(x)}, {2*sin(x)}) + domain=0:360:用參數法畫橢圓最穩定。
% 寫成 implicit function x^2/9+y^2/4=1 反而不行(pgfplots 不支援隱函數繪圖)。
\addplot[blue, thick, samples=200, domain=0:360] ({3*cos(x)}, {2*sin(x)});
\addlegendentry{$\dfrac{x^2}{9}+\dfrac{y^2}{4}=1$}

% 兩個焦點 (±√5, 0) ≈ (±2.236, 0) 用 red mark + F_1, F_2:
% 中學橢圓重點是「兩焦點到橢圓上任一點距離和為定值」。沒標焦點等於少了 50% 概念。
\addplot[mark=*, red] coordinates {(2.236,0)};
\addplot[mark=*, red] coordinates {(-2.236,0)};
\node[red, above] at (axis cs:2.236,0) {$F_2$};
\node[red, above] at (axis cs:-2.236,0) {$F_1$};

% 四個頂點 (3,0)(-3,0)(0,2)(0,-2) 用 black mark:跟焦點(red)區分。
% 只標三個座標(右、左、上),下方 (0,-2) 不標避免擁擠。
% (3,0)/(-3,0) label 錨點往上挪到 y=0.75,避免文字疊到 x 軸線
% (axis 範圍 ±5×±4 + 11×11cm 圖框下,0.5 還是太貼,0.75 才有清楚間距)。
\addplot[mark=*, black] coordinates {(3,0) (-3,0) (0,2) (0,-2)};
\node[below right] at (axis cs:3,0.75) {$(3,0)$};
\node[below left] at (axis cs:-3,0.75) {$(-3,0)$};
\node[above right] at (axis cs:0,2) {$(0,2)$};
\end{axis}
\end{tikzpicture}
senior-06
【高中】不等式陰影區 y ≥ x²-1
% 不等式陰影區 y ≥ x²-1,流派 B/C(純 TikZ + 手繪坐標軸)。設計原則詳見 ../DESIGN_NOTES.md
% 為什麼用純 TikZ 而不是 pgfplots:pgfplots 想做「兩曲線間填滿」要 fillbetween library,
% 但 bundle 沒有這個 sub-library(README §4-2)會 crash。
% 所以改用純 TikZ \fill ... plot ... -- (右上) -- (左上) -- cycle 手刻陰影。
\begin{tikzpicture}[scale=0.85]
% 繪製順序(z-order)從底到頂:網格 → 陰影 → 座標軸/刻度 → 拋物線 → 區內標籤。
% 把陰影放在座標軸「之前」是關鍵:y≥x²-1 區涵蓋 y 軸(x=0)整段
% 與 x 軸介於 x=-1..1 之間,如果軸先畫、陰影後填,藍色 blue!15 雖淡但會把
% 黑色細軸線整段覆蓋掉(blue!15 不是真透明,只是顏色偏淡的不透明色)。
% 網格
\draw[gray!30, very thin, step=1] (-3,-2) grid (3,6);
% 陰影 path:沿著拋物線從 (-2.65,6) 到 (2.65,6),再連到 (2.65,6)(右上)→ (-2.65,6)(左上)→ cycle。
% 兩個 6 是 y 軸 ymax 一致,讓陰影頂端齊平不會留奇怪的缺口。
% 拋物線域 [-2.65, 2.65]:x²-1 = 6 解得 x=±2.65,正好是拋物線跟 y=6 的交點。
% 寫成 ±2.5 會讓陰影上緣超出拋物線形成空洞。
% samples=80(陰影):邊界容忍稍粗,被 fill 蓋掉看不到底下的鋸齒。
\fill[blue!15, domain=-2.65:2.65, samples=80] plot (\x, {\x*\x - 1}) -- (2.65,6) -- (-2.65,6) -- cycle;
% 坐標軸(畫在陰影上方,避免被藍色 blue!15 覆蓋)
\draw[->, thick] (-3.2,0) -- (3.2,0) node[right] {$x$};
\draw[->, thick] (0,-2.2) -- (0,6.5) node[above] {$y$};
% 自繪刻度用 \foreach:每個整數位置畫一短刻度 + 數字標籤。比寫 25 行 \draw 簡潔。
\foreach \x in {-3,-2,-1,1,2,3} \draw (\x,0) -- (\x,-0.08) node[below, font=\scriptsize] {\x};
\foreach \y in {-2,-1,1,2,3,4,5,6} \draw (0,\y) -- (-0.08,\y) node[left, font=\scriptsize] {\y};
% samples=120(曲線):本身要更密才平滑。120 是兩者甜蜜點的差。
\draw[blue, very thick, domain=-2.65:2.65, samples=120, smooth] plot (\x, {\x*\x - 1});
% 不等式式子 $y \geq x^2-1$ 放陰影區內,像「填滿區內標記區名」是 K-12 慣例。
% 位置 (-1.3, 4.5):刻意偏左,避免文字中心放在 (0,*) 時跨在 y 軸上(節點預設置中,
% (0,4) 會讓 "y≥x^2-1" 從 x≈-0.7 跨到 +0.7,文字被 y 軸切兩半很醜)。
% 偏左還有一個好處:跟右側曲線標籤 $y=x^2-1$@(1.8,4.0) 形成左/右視覺平衡。
% 在 y=4.5 處陰影區 x 範圍 ±√5.5≈±2.35,文字寬約 1.4 可以完全放下不踩拋物線。
\node[blue!70!black] at (-1.3, 4.5) {$y \geq x^2 - 1$};
\node[blue, right] at (1.8, 4.0) {$y=x^2-1$};
\end{tikzpicture}
senior-07
【高中】線性規劃可行區域
% 線性規劃可行區域,流派 B/C(純 TikZ,跟 16 同樣繞過 fillbetween)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}[scale=0.85]
% 可行區域用 \fill[green!25] 直接連四個頂點:多邊形可行區域用 cycle 一行解決,
% 比 fillbetween 簡單也避免 bundle 限制。
% 放在最上面(最下層 z-order)→ grid + 軸 + 邊界線都會 overlay 在綠色之上,
% grid 線可穿透看見、學生空間感更清楚。
\fill[green!25] (0,0) -- (5,0) -- (2,3) -- (0,4) -- cycle;
% 網格
\draw[gray!30, very thin, step=1] (-1,-1) grid (7,6);
% 坐標軸
\draw[->, thick] (-1.2,0) -- (7.5,0) node[right] {$x$};
\draw[->, thick] (0,-1.2) -- (0,6.5) node[above] {$y$};
% 兩條約束直線(藍 x+y=5、紅 x+2y=8)用 very thick:粗線強調是「邊界」。
% 實線而非虛線,因為 ≤ 不等式包含邊界。
\draw[blue, very thick, domain=-0.3:6] plot (\x, {-\x + 5});
\draw[red, very thick, domain=-0.3:6.5] plot (\x, {(-\x + 8)/2});
% 頂點用 \foreach:把 4 個頂點 + label + 位置寫成 foreach 變數,改座標只動一行。
% 比手寫 4 個 \filldraw 短、改起來不會漏。
% label 用 {...} 包起來:foreach 預設用逗號分隔 item,label 內的逗號 (5,0) 會
% 被當 item 邊界切碎;{$(5,\,0)$} 整組大括號告訴 foreach「這是一個 atom」。
% 逗號後 \, 加 thin space → 顯示「(5, 0)」,符合座標標準排版。
\foreach \p/\lab/\pos in {(0,0)/$O$/below left, (5,0)/{$(5,\,0)$}/below, (2,3)/{$(2,\,3)$}/above right, (0,4)/{$(0,\,4)$}/left}
  {\filldraw[black] \p circle (1.6pt) node[\pos, font=\small] {\lab};}
% 線標籤
% x+y=5 label x 從 5.3 → 5.5 右推 0.2 unit,離藍線拉開,不再貼線。
\node[blue, right, font=\small] at (5.5, -0.4) {$x+y=5$};
\node[red, right, font=\small] at (6.0, 1.1) {$x+2y=8$};
% feasible 標籤放區域中央偏內 (1.7, 1.2):不擋住任何頂點或邊界線。
\node[green!50!black, font=\small] at (1.7, 1.2) {feasible};
\end{tikzpicture}
senior-08
【高中】函數切線(微分意義)
% 函數切線(微分意義),流派 A(pgfplots)。設計原則詳見 ../DESIGN_NOTES.md
% 切線斜率 = 2(等於 f'(1)=2*1=2),方程式 y = f'(1)(x-1) + f(1) = 2x-1。
% 選 x=1 因為 f(1)=1, f'(1)=2 都是整數,方程式漂亮易記。
% 沒有額外輔助線(例如「Δx → 0」之類視覺):極簡只突出「切線剛好碰到曲線一點」的概念,
% 對切線概念入門最有效。
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xlabel=$x$, ylabel=$y$,
  xmin=-3, xmax=3, ymin=-2, ymax=8,
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=11cm, height=8cm,
]
% f(x)=x² 用 domain=-2:2.5 畫整段曲線。
\addplot[blue, thick, samples=200, domain=-2:2.5] {x^2};
\addlegendentry{$f(x)=x^2$}
% 切線 2x-1 用 domain=-1:3(切點附近,延伸出去看趨勢)+ samples=2(直線兩點足夠)。
\addplot[red, thick, samples=2, domain=-1:3] {2*x-1};
\addlegendentry{tangent at $x=1$}
% 切點 (1,1) 用 red mark:微分的核心是「在這一點」,點不標就失去重點。
\addplot[mark=*, red] coordinates {(1,1)};
\node[red, above left] at (axis cs:1,1) {$(1,1)$};
\end{axis}
\end{tikzpicture}
senior-09
【高中】黎曼和(積分視覺化)
% 黎曼和(積分視覺化),流派 A(pgfplots,雙 axis env 疊圖)。設計原則詳見 ../DESIGN_NOTES.md
% 兩個 \begin{axis} 疊在同一個 tikzpicture:
% 1. 第一層 ybar interval + samples=8 → 8 個藍色矩形,每個寬度 3/8,
%    高度等於 f(x)=x² 在該 x 值的值。代表「黎曼和」逼近積分。
% 2. 第二層 axis on top + ticks=none + 紅色平滑曲線 → 真實的 f(x)=x²。
% 兩層疊起來:藍色矩形(離散逼近) + 紅色曲線(連續真值),學生一秒理解
% 「矩形面積 → 積分」這個微積分基本概念。
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  xlabel=$x$, ylabel=$y$,
  xmin=-0.5, xmax=3.5, ymin=-0.5, ymax=10,
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=11cm, height=7cm,
  ybar interval, bar shift=0pt,
]
% samples=8(藍矩形)是設計重點:矩形數量少才看得出「逼近」的概念。
% 如果矩形太多(samples=50)會跟曲線重合,失去「逼近」的對比。
\addplot+[draw=blue!50!black, fill=blue!20, samples=8, domain=0:3]
  ({x}, {x^2});
\end{axis}
\begin{axis}[
  axis lines=middle,
  xmin=-0.5, xmax=3.5, ymin=-0.5, ymax=10,
  width=11cm, height=7cm,
  % axis on top 必須:讓紅曲線畫在藍矩形之上,不被遮住。
  axis on top,
  % ticks=none, xlabel=, ylabel=:把刻度跟 label 都拿掉,因為跟第一層重複會疊雙重字。
  ticks=none, xlabel=, ylabel=,
]
% samples=200(紅曲線):曲線必須密才平滑當參考。
\addplot[red, thick, samples=200, domain=0:3] {x^2};
\addlegendentry{$f(x)=x^2$}
\end{axis}
\end{tikzpicture}
senior-10
【高中】立體幾何:長方體
% 長方體 3D,流派 B(純 TikZ + 斜投影)。設計原則詳見 ../DESIGN_NOTES.md
% 投影偏移 (0.8, 0.6):3-4-5 比例,length=√(0.64+0.36)=1.000 → depth=1 unit
% 在 2D 視覺長度也 = 1 unit。投影角 atan(0.6/0.8) ≈ 36.87°。
% 這是 cavalier projection(深度全長保留),不是 cabinet(深度收縮 50%)。
% 選 cavalier 的理由:要讓 3/2/1 邊長標籤跟 2D 視覺長度 3:2:1 對應,
% 學生看得出「深度標 1 的邊視覺也 = 1 個 unit」。cabinet 的 0.5 收縮會讓
% depth=1 看起來只有 0.5,跟標籤不直觀對應。對邊等長性質兩種投影都保留。
% 8 個頂點 ABCD(前面)+ EFGH(後面)用課本慣例命名:前面四點逆時針
% A(左下)→ B(右下)→ C(右上)→ D(左上),後面對應 E、F、G、H。
\begin{tikzpicture}[scale=1.3]
% 前面四邊形(實線)
\draw[thick] (0,0) -- (3,0) -- (3,2) -- (0,2) -- cycle;
% 後面四邊形(實線,但其中一邊會被 dashed 蓋掉)
\draw[thick] (0.8,0.6) -- (3.8,0.6) -- (3.8,2.6) -- (0.8,2.6) -- cycle;
% 連接前後的可見邊
\draw[thick] (3,0) -- (3.8,0.6);
\draw[thick] (3,2) -- (3.8,2.6);
\draw[thick] (0,2) -- (0.8,2.6);
% 看不到的邊用 dashed:從前方視角看,AE(後左下接前左下)和 EH(後左下接後左上)是
% 「藏在物體後面」的邊。實線 vs 虛線是 3D 圖最重要的視覺區分,
% 沒有區分整張圖會像「12 條交叉線」看不出立體感。
\draw[dashed] (0,0) -- (0.8,0.6);
\draw[dashed] (0.8,0.6) -- (0.8,2.6);

\node[below left] at (0,0) {$A$};
\node[below right] at (3,0) {$B$};
% C/E 的 outward 對角方向(45°/225°)正好沿著 cabinet 投影邊 C-G/A-E(~37°/~217°),
% label 會疊在邊上。加 yshift 把 C 往上、E 往下推 5pt,沿垂直方向拉開不沿邊。
\node[above right, yshift=5pt] at (3,2) {$C$};
\node[above left] at (0,2) {$D$};
\node[below right] at (3.8,0.6) {$F$};
\node[above right] at (3.8,2.6) {$G$};
\node[above left] at (0.8,2.6) {$H$};
\node[below left, yshift=-5pt] at (0.8,0.6) {$E$};

% 邊長標 3 / 2 / 1:不寫單位、純數字。這支樣本主要展示「3D 投影怎麼畫」,不是具體題目。
\node[below] at (1.5,0) {$3$};
\node[left] at (0,1) {$2$};
% 深度邊 1 用 [sloped]:讓字跟邊平行,看起來像「沿著邊測量」。
% B-F 中點 = ((3+3.8)/2, (0+0.6)/2) = (3.4, 0.3)
\node[below right, sloped] at (3.4,0.3) {$1$};
\end{tikzpicture}
senior-11
【高中】立體幾何:圓錐
% 圓錐 3D,流派 B(純 TikZ + 橢圓 arc 模擬透視)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}[scale=1.5]
% 底面用兩段 arc 拼成橢圓:arc (180:360:2 and 0.5) 畫下半圈(實線,面對觀察者那半),
% arc (0:180:2 and 0.5) 畫上半圈(虛線,藏在背面)。
% 2 and 0.5 是橢圓的 x/y 半徑,0.5 < 2 才是「俯視角度的橢圓」
% (若用 circle (2) 會變成正圓,失去立體感)。
% 半徑長度比 0.5 / 2 = 0.25:相當於從上方 75 度俯視看圓的形狀。
% 0.3 = 接近側面看(橢圓很扁);0.7 = 接近正上方看(像圓)。0.5 是甜蜜點,3D 立體感最強。
% 底面實線 vs 虛線兩段必須:沒有虛線 = 看起來像個半圓盤;沒有實線 = 圓錐底面看不出深度。
\draw[thick] (-2,0) arc (180:360:2 and 0.5);
\draw[thick, dashed] (2,0) arc (0:180:2 and 0.5);
% 母線(slant)由三角形邊代表,不再額外畫實線。
\draw[thick] (-2,0) -- (0,3);
\draw[thick] (2,0) -- (0,3);
% 中軸 (0,0) -- (0,3) 用 dashed:中軸藏在錐體內(看不到),虛線表達。
\draw[dashed] (0,0) -- (0,3);
% 半徑 r 用藍 + \draw[->]、高 h 用紅 + \draw[->]:兩個方向的關鍵測量,
% 箭頭強調「從某點朝某方向」。
\draw[->, thick, blue] (0,0) -- (2,0);
\node[below] at (1,0) {$r$};
\draw[->, thick, red] (0,0) -- (0,3);
\node[left] at (0,1.5) {$h$};
\filldraw[black] (0,0) circle (1pt) node[below right] {$O$};
\filldraw[black] (0,3) circle (1pt) node[above] {$V$};
% 母線 \ell 不畫實線(已被三角形邊代表),只標 label:減少視覺雜訊。
\node[right] at (1.3,1.5) {$\ell$};
\end{tikzpicture}
senior-12
【高中】等差數列項數圖
% 等差數列項數圖,流派 A(pgfplots,only marks 散點不連線)。設計原則詳見 ../DESIGN_NOTES.md
\begin{tikzpicture}
\begin{axis}[
  axis lines=middle,
  % x 軸標 $n$、y 軸標 $a_n$:數列的標準慣例符號(項數 vs 第 n 項的值)。
  xlabel=$n$, ylabel=$a_n$,
  % 資料只到 a_9 不到 a_10:留 ymax=22 的空間給「下一項是多少?」這種延伸題目用的視覺空間。
  xmin=0, xmax=10, ymin=0, ymax=22,
  % xtick={1,2,...,9}:強制每個整數一個刻度,跟資料點一一對應。
  % 預設可能跳到每 2 或 5 一格,讓學生看不出「第 n 項」對齊哪個 x。
  xtick={1,2,3,4,5,6,7,8,9},
  grid=both,
  grid style={line width=.2pt, draw=gray!50},
  axis line style={->},
  width=11cm, height=6cm,
  % only marks 是關鍵 option:沒加這個 pgfplots 會把 9 個點用直線連起來,
  % 但數列是「離散的整數函數」,連線會誤導學生以為是連續函數。
  only marks,
]
% mark size=2.5pt:點稍大(預設 2pt 左右),視覺上強調「離散」性質,
% 不會被誤認成函數圖的細點。
\addplot[blue, mark=*, mark size=2.5pt] coordinates {
  (1,2) (2,4) (3,6) (4,8) (5,10) (6,12) (7,14) (8,16) (9,18)
};
\addlegendentry{$a_n=2n$}
\end{axis}
\end{tikzpicture}

其他(進階套件 demo)7

other-01
基本函數圖形
\begin{tikzpicture}[domain=0:4]
  \draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
  \draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$};
  \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
  \draw[color=red] plot (\x,\x) node[right] {$f(x) = x$};
  \draw[color=blue] plot (\x,{sin(\x r)}) node[right] {$f(x) = \sin x$};
  \draw[color=orange] plot (\x,{0.05*exp(\x)}) node[right] {$f(x) = \frac{1}{20} \mathrm e^x$};
\end{tikzpicture}
other-02
高斯鐘面曲線
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}
\begin{axis}[colormap/viridis]
\addplot3[
	surf,
	samples=18,
	domain=-3:3
]
{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}

\end{document}
other-03
纖維積與交換立方體圖
% 纖維積(pullback)+ 交換立方體,流派 D(tikz-cd)。
% 重要:tikzcd 內部不能有空白行 — TeX 會把連續換行解讀為 \par,
% 而 tikzcd cell 預設處於 math mode,math mode 不許 \par,結果 TeX 噴
% "! Missing $ inserted." 然後 emergency stop。要在環境裡留視覺呼吸,
% 寫 % 註解佔行(\par 被 % 吃掉),不要直接留空白行。
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
    T
    \arrow[drr, bend left, "x"]
    \arrow[ddr, bend right, "y"]
    \arrow[dr, dotted, "{(x,y)}" description] & & \\
    K & X \times_Z Y \arrow[r, "p"] \arrow[d, "q"]
    & X \arrow[d, "f"] \\
    & Y \arrow[r, "g"]
    & Z
\end{tikzcd}
\quad \quad
\begin{tikzcd}[row sep=2.5em]
A' \arrow[rr,"f'"] \arrow[dr,swap,"a"] \arrow[dd,swap,"g'"] &&
  B' \arrow[dd,swap,"h'" near start] \arrow[dr,"b"] \\
& A \arrow[rr,crossing over,"f" near start] &&
  B \arrow[dd,"h"] \\
C' \arrow[rr,"k'" near end] \arrow[dr,swap,"c"] && D' \arrow[dr,swap,"d"] \\
& C \arrow[rr,"k"] \arrow[uu,<-,crossing over,"g" near end]&& D
\end{tikzcd}
\end{document}
other-04
胜肽結構圖
\usepackage{chemfig}
\begin{document}

\chemfig{[:-90]HN(-[::-45](-[::-45]R)=[::+45]O)>[::+45]*4(-(=O)-N*5(-(<:(=[::-60]O)-[::+60]OH)-(<[::+0])(<:[::-108])-S>)--)}

\end{document}
other-05
五聚體環狀結構
\usepackage{chemfig}
\begin{document}
\definesubmol\fragment1{
    (-[:#1,0.85,,,draw=none]
    -[::126]-[::-54](=_#(2pt,2pt)[::180])
    -[::-70](-[::-56.2,1.07]=^#(2pt,2pt)[::180,1.07])
    -[::110,0.6](-[::-148,0.60](=^[::180,0.35])-[::-18,1.1])
    -[::50,1.1](-[::18,0.60]=_[::180,0.35])
    -[::50,0.6]
    -[::110])
    }
\chemfig{
!\fragment{18}
!\fragment{90}
!\fragment{162}
!\fragment{234}
!\fragment{306}
}
\end{document}
other-06
電流源並聯電阻電路
\usepackage{circuitikz}
\begin{document}

\begin{circuitikz}[american, voltage shift=0.5]
\draw (0,0)
to[isource, l=$I_0$, v=$V_0$] (0,3)
to[short, -*, i=$I_0$] (2,3)
to[R=$R_1$, i>_=$i_1$] (2,0) -- (0,0);
\draw (2,3) -- (4,3)
to[R=$R_2$, i>_=$i_2$]
(4,0) to[short, -*] (2,0);
\end{circuitikz}

\end{document}
other-07
Penrose 圖:平直時空與黑洞
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
% scale=0.5:原始座標範圍 x=±8、y=±4 → 16×8cm,在 sample card 預覽窗口會出
% 水平滾軸。縮 0.5 → 8×4cm,安全裝得下大部分容器。labels 不跟著縮(scale
% 只動座標跟線),縮圖後文字仍可讀。
\begin{tikzpicture}[scale=0.5]
\node (I)    at ( 4,0)   {I};
\node (II)   at (-4,0)   {II};
\node (III)  at (0, 2.5) {III};
\node (IV)   at (0,-2.5) {IV};

\path  % Four corners of left diamond
  (II) +(90:4)  coordinate[label=90:$i^+$]  (IItop)
       +(-90:4) coordinate[label=-90:$i^-$] (IIbot)
       +(0:4)   coordinate                  (IIright)
       +(180:4) coordinate[label=180:$i^0$] (IIleft)
       ;
\draw (IIleft) -- 
          node[midway, above left]    {$\cal{J}^+$}
          node[midway, below, sloped] {$\bar{u}=\infty$}
      (IItop) --
          node[midway, below, sloped] {$\bar{u}=0$}
      (IIright) -- 
          node[midway, below, sloped] {$\bar{u}=0$}
      (IIbot) --
          node[midway, above, sloped] {$\bar{v}=-\infty$}
          node[midway, below left]    {$\cal{J}^-$}    
      (IIleft) -- cycle;

\path % Four conners of the right diamond (no labels this time)
   (I) +(90:4)  coordinate (Itop)
       +(-90:4) coordinate (Ibot)
       +(180:4) coordinate (Ileft)
       +(0:4)   coordinate (Iright)
       ;
% No text this time in the next diagram
\draw  (Ileft) -- (Itop) -- (Iright) -- (Ibot) -- (Ileft) -- cycle;

% Squiggly lines
\draw[decorate,decoration=zigzag] (IItop) -- (Itop)
      node[midway, above, inner sep=2mm] {$r=0$};

\draw[decorate,decoration=zigzag] (IIbot) -- (Ibot)
      node[midway, below, inner sep=2mm] {$r=0$};

\end{tikzpicture}
\end{document}