LaTeX / TikZ 几何图形绘制完整参考手册

发布时间:2026/5/26 11:54:21

LaTeX / TikZ 几何图形绘制完整参考手册 LaTeX / TikZ 几何图形绘制完整参考手册适用于 TeXStudio TeX Live 2025 / MiKTeX 2025 环境核心包pgf/tikz 3.1.112025年8月发布参考来源Wikibooks LaTeX/PGF/TikZ、Overleaf 官方教程、tikz.dev 手册、Wikipedia PGF/TikZ 词条扩展部分请点击这里前往文章目录LaTeX / TikZ 几何图形绘制完整参考手册1. 环境准备与基本结构1.1 TeXStudio 设置建议1.2 最小文档模板2. 通用绘图语法速查2.1 核心命令2.2 路径操作符2.3 常用选项参数2.4 颜色混合语法3. 平面二维图形3.1 直线与折线语法案例3.2 三角形语法案例3.3 矩形语法案例3.4 平行四边形语法案例3.5 圆与椭圆语法案例3.6 正多边形语法案例3.7 五角星案例3.8 不规则多边形与曲线不规则多边形贝塞尔曲线与有机形状4. 空间三维图形4.1 正方体方法手动斜投影cabinet projection方法使用 tikz-3dplot更精确的视角控制4.2 长方体Cuboid4.3 圆柱4.4 圆锥4.5 球体带渐变填充的实心球体更美观5. 样式与美化5.1 线型与粗细5.2 填充图案patterns 库5.3 渐变填充shading5.4 使用 \tikzset 定义可复用样式6. 综合实践案例案例一几何图形展示板案例二三维几何体展示板案例三带标注的几何图平面图形作图7. 常用宏包与库一览附录快速语法参考卡1. 环境准备与基本结构1.1 TeXStudio 设置建议在 TeXStudio 中使用 TikZ推荐编译链设置为编译器pdfLaTeX或XeLaTeX中文文档时推荐BibTeX不必须菜单路径Options → Configure TeXStudio → Build1.2 最小文档模板\documentclass[12pt]{article} \usepackage{tikz} % 核心包 \usetikzlibrary{shapes.geometric} % 几何形状库 \usetikzlibrary{patterns} % 填充图案库 \usetikzlibrary{3d} % 基础 3D 支持 \usepackage{tikz-3dplot} % 三维坐标系绘制球体等 \begin{document} \begin{tikzpicture} % 在此处写绘图命令 \end{tikzpicture} \end{document}说明tikzpicture是所有 TikZ 绘图的环境容器所有绘图命令必须写在其中。2. 通用绘图语法速查2.1 核心命令命令说明\draw绘制路径不填充\fill填充路径不描边\filldraw同时填充并描边\node放置带文字的节点形状\coordinate定义命名坐标点2.2 路径操作符操作符说明示例--直线连接两点(0,0) -- (1,1)cycle闭合路径回到起点(0,0) -- (1,0) -- cyclerectangle矩形对角两点(0,0) rectangle (2,1)circle圆形半径(0,0) circle (1cm)ellipse椭圆x半轴 and y半轴(0,0) ellipse (2cm and 1cm)arc圆弧起始角:结束角:半径(1,0) arc (0:90:1).. controls贝塞尔曲线(0,0) .. controls (1,1) .. (2,0)2.3 常用选项参数\draw[ colorred, % 颜色 fillblue!30, % 填充色30%蓝色 line width2pt, % 线宽 dashed, % 虚线 dotted, % 点线 thick, % 粗线约0.8pt very thick, % 更粗约1.2pt ultra thick, % 极粗约1.6pt opacity0.5, % 整体透明度 fill opacity0.3, % 仅填充透明度 rotate45, % 旋转角度度 scale1.5, % 缩放 xshift1cm, % 水平偏移 yshift0.5cm, % 垂直偏移 ]2.4 颜色混合语法red!50 % 50% 红色混入白色 red!50!blue % 50% 红 50% 蓝 blue!30!black % 30% 蓝 70% 黑3. 平面二维图形3.1 直线与折线语法\draw[选项] (起点) -- (终点); % 直线 \draw[选项] (P1) -- (P2) -- (P3) -- ...; % 折线案例\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 普通直线 \draw[blue, thick] (0,0) -- (4,0); % 带箭头的直线坐标轴风格 \draw[-, red, thick] (0,1) -- (4,1) node[right] {$x$}; % 折线 \draw[green!60!black, very thick] (0,2) -- (1,3) -- (2,2) -- (3,3) -- (4,2); % 虚线 \draw[dashed, gray] (0,3.5) -- (4,3.5); \end{tikzpicture} \end{document}3.2 三角形语法三角形通过连接三个点并使用cycle闭合路径来绘制\draw (x1,y1) -- (x2,y2) -- (x3,y3) -- cycle;案例\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 1. 普通三角形仅描边 \draw[blue, thick] (0,0) -- (3,0) -- (1.5,2.5) -- cycle; % 2. 填充三角形 \filldraw[fillorange!40, draworange!80!black, very thick] (4,0) -- (7,0) -- (5.5,2.5) -- cycle; % 3. 直角三角形 \filldraw[fillgreen!30, drawgreen!60!black] (0,-1.5) -- (2,-1.5) -- (0,-4) -- cycle; % 4. 等边三角形利用数学计算精确坐标 % 边长 3高 3*sqrt(3)/2 ≈ 2.598 \filldraw[fillpurple!30, drawpurple] (4,-4) -- (7,-4) -- (5.5,-1.402) -- cycle; % 标注顶点 \node[below left] at (0,0) {$A$}; \node[below right] at (3,0) {$B$}; \node[above] at (1.5,2.5) {$C$}; \end{tikzpicture} \end{document}3.3 矩形语法\draw (左下角) rectangle (右上角);rectangle是 TikZ 内置关键字只需提供对角线上的两个坐标。案例\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 1. 基本矩形 \draw[blue, thick] (0,0) rectangle (3,2); % 2. 填充矩形 \filldraw[fillyellow!50, drawblack, thick] (4,0) rectangle (7,2); % 3. 正方形 \filldraw[fillred!30, drawred] (0,-3) rectangle (2,-1); % 4. 圆角矩形rounded corners \draw[thick, rounded corners5pt, fillcyan!20] (4,-3) rectangle (7,-1); % 5. 旋转的矩形 \begin{scope}[rotate30] \draw[dashed, thick, fillpink!50] (0,-5) rectangle (3,-3.5); \end{scope} \end{tikzpicture} \end{document}3.4 平行四边形语法平行四边形没有内置命令通过指定四个顶点坐标并用cycle闭合绘制\draw (x1,y1) -- (x2,y2) -- (x3,y3) -- (x4,y4) -- cycle;坐标规律若底边从(a,b)到(aw,b)偏移量为d则左下(a, b)右下(aw, b)右上(awd, bh)左上(ad, bh)案例\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 1. 基本平行四边形向右倾斜 % 底边宽3高2水平偏移1 \filldraw[fillblue!20, drawblue, thick] (0,0) -- (3,0) -- (4,2) -- (1,2) -- cycle; % 标注顶点 \node[below left] at (0,0) {$A$}; \node[below right] at (3,0) {$B$}; \node[above right] at (4,2) {$C$}; \node[above left] at (1,2) {$D$}; % 2. 向左倾斜的平行四边形 \filldraw[fillred!20, drawred, thick] (6,0) -- (9,0) -- (8,2) -- (5,2) -- cycle; % 3. 菱形特殊平行四边形 \filldraw[fillgreen!30, drawgreen!60!black, thick] (1,-3) -- (3,-1.5) -- (5,-3) -- (3,-4.5) -- cycle; \node[below] at (3,-4.5) {菱形}; \end{tikzpicture} \end{document}3.5 圆与椭圆语法% 圆在圆心处绘制指定半径 \draw (cx,cy) circle (radius); % 椭圆指定 x 半轴和 y 半轴 \draw (cx,cy) ellipse (xradius and yradius); % 圆弧从某点出发指定起止角度和半径 \draw (start_x, start_y) arc (start_angle : end_angle : radius);案例\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 1. 基本圆 \draw[blue, thick] (0,0) circle (1.5cm); % 2. 填充圆 \filldraw[fillorange!40, draworange, thick] (4,0) circle (1.2cm); % 3. 椭圆 \filldraw[fillpurple!30, drawpurple, thick] (0,-4) ellipse (2.5cm and 1.2cm); % 4. 圆弧半圆 \draw[red, very thick] (2,-3) arc (0:180:1.5); % 5. 同心圆 \draw[gray] (7,0) circle (0.5); \draw[gray] (7,0) circle (1.0); \draw[gray] (7,0) circle (1.5); \filldraw[red] (7,0) circle (0.1); \end{tikzpicture} \end{document}3.6 正多边形正多边形使用shapes.geometric库中的regular polygon形状通过node来绘制。语法\usetikzlibrary{shapes.geometric} \node[regular polygon, regular polygon sides N, % N 为边数 draw, fill 颜色, minimum size 尺寸 ] at (x,y) {};案例\documentclass{standalone} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \begin{document} \begin{tikzpicture} % 正三角形3边 \node[regular polygon, regular polygon sides3, drawblue, fillblue!20, minimum size2cm] at (0,0) {$n3$}; % 正四边形4边 正方形 \node[regular polygon, regular polygon sides4, drawred, fillred!20, minimum size2cm] at (3,0) {$n4$}; % 正五边形 \node[regular polygon, regular polygon sides5, drawgreen!60!black, fillgreen!20, minimum size2cm] at (6,0) {$n5$}; % 正六边形 \node[regular polygon, regular polygon sides6, draworange, fillorange!20, minimum size2cm] at (0,-3) {$n6$}; % 正七边形 \node[regular polygon, regular polygon sides7, drawpurple, fillpurple!20, minimum size2cm] at (3,-3) {$n7$}; % 正八边形 \node[regular polygon, regular polygon sides8, drawcyan!60!black, fillcyan!20, minimum size2cm] at (6,-3) {$n8$}; \end{tikzpicture} \end{document}3.7 五角星TikZ 提供两种方式绘制五角星方法一使用shapes.geometric库的star形状推荐\usetikzlibrary{shapes.geometric} \node[star, star points 5, % 角的数量 star point ratio 2.5, % 外径/内径比越大角越尖 draw, fill 颜色, minimum size 尺寸 ] at (x,y) {};方法二手动连接10个顶点坐标精确控制案例\documentclass{standalone} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \begin{document} \begin{tikzpicture} % 方法一使用 star 节点黄色五角星 \node[star, star points5, star point ratio2.5, drawblack, fillyellow, minimum size3cm] at (0,0) {}; % 红色五角星角更尖 \node[star, star points5, star point ratio3, drawred!80!black, fillred, minimum size2.5cm] at (4,0) {}; % 六角星 \node[star, star points6, star point ratio2, drawblue, fillblue!30, minimum size2.5cm] at (8,0) {}; % 方法二手动绘制五角星精确坐标版 % 外半径 R2内半径 r0.8以 (2,-4) 为中心 \filldraw[fillgold!80!orange, drawblack, thick] (2,-2) -- (2.588,-3.809) -- (0.382,-4.951) -- (2,-3.236) -- (3.618,-4.951) -- (1.412,-3.809) -- cycle; % 正规计算版五角星以原点为中心外径R1.5内径r0.6 \def\R{1.5} \def\r{0.6} \filldraw[fillyellow!80, draworange, thick] ({-4\R*sin(0)}, {-4\R*cos(0)}) -- ({-4\r*sin(36)}, {-4\r*cos(36)}) -- ({-4\R*sin(72)}, {-4\R*cos(72)}) -- ({-4\r*sin(108)}, {-4\r*cos(108)}) -- ({-4\R*sin(144)}, {-4\R*cos(144)}) -- ({-4\r*sin(180)}, {-4\r*cos(180)}) -- ({-4\R*sin(216)}, {-4\R*cos(216)}) -- ({-4\r*sin(252)}, {-4\r*cos(252)}) -- ({-4\R*sin(288)}, {-4\R*cos(288)}) -- ({-4\r*sin(324)}, {-4\r*cos(324)}) -- cycle; \end{tikzpicture} \end{document}3.8 不规则多边形与曲线不规则多边形任意形状的多边形通过罗列顶点坐标 cycle来实现\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 不规则五边形 \filldraw[fillteal!30, drawteal, thick] (0,0) -- (3,0.5) -- (4,2) -- (2,3.5) -- (-0.5,2) -- cycle; % L 形凹多边形 \filldraw[fillpink!60, drawred!60, thick] (5,0) -- (9,0) -- (9,1.5) -- (7,1.5) -- (7,3) -- (5,3) -- cycle; % 箭头形状 \filldraw[fillblue!30, drawblue!70, thick] (0,-5) -- (2.5,-5) -- (2.5,-4) -- (4,-5.5) -- (2.5,-7) -- (2.5,-6) -- (0,-6) -- cycle; \end{tikzpicture} \end{document}贝塞尔曲线与有机形状\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 简单二次贝塞尔曲线一个控制点 \draw[blue, very thick] (0,0) .. controls (1,3) .. (4,0); % 三次贝塞尔曲线两个控制点 \draw[red, very thick] (0,-2) .. controls (1,0) and (3,-4) .. (4,-2); % 闭合有机形状水滴 \filldraw[fillgreen!30, drawgreen!60!black, thick] (0,-5) .. controls (-1.5,-3.5) and (-1.5,-6.5) .. (0,-5) .. controls (1,-4) and (2,-3) .. (1,-5.5) .. controls (0.5,-6.5) and (-0.5,-6.5) .. (0,-5); % 波浪线 \draw[orange, thick] (0,-7.5) .. controls (0.5,-7) and (0.5,-8) .. (1,-7.5) .. controls (1.5,-7) and (1.5,-8) .. (2,-7.5) .. controls (2.5,-7) and (2.5,-8) .. (3,-7.5); \end{tikzpicture} \end{document}4. 空间三维图形三维图形在 TikZ 中通过斜投影或tikz-3dplot包实现真实的三维坐标变换。4.1 正方体方法手动斜投影cabinet projection\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture}[scale1.5, % 定义三维方向向量斜等轴测 x{(1cm,0cm)}, y{(0cm,1cm)}, z{(0.4cm,0.3cm)} ] % 定义边长 \def\a{2} % 后面隐藏面用虚线 \draw[dashed, gray] (0,0,0) -- (\a,0,0) (0,0,0) -- (0,\a,0) (0,0,0) -- (0,0,\a); % 正面实线 \filldraw[fillblue!10, drawblack, thick] (\a,0,0) -- (\a,\a,0) -- (\a,\a,\a) -- (\a,0,\a) -- cycle; % 顶面 \filldraw[fillblue!20, drawblack, thick] (0,\a,0) -- (\a,\a,0) -- (\a,\a,\a) -- (0,\a,\a) -- cycle; % 右侧面侧面偏暗 \filldraw[fillblue!30, drawblack, thick] (\a,0,0) -- (\a,0,\a) -- (\a,\a,\a) -- (\a,\a,0) -- cycle; % 前面可见的三条棱 \draw[black, thick] (\a,0,0) -- (0,0,0) (0,\a,0) -- (0,0,0) (0,0,\a) -- (0,0,0); \end{tikzpicture} \end{document}方法使用tikz-3dplot更精确的视角控制\documentclass{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} % 设置视角俯仰角60°方位角125° \tdplotsetmaincoords{60}{125} \begin{document} \begin{tikzpicture}[tdplot_main_coords, scale1.5] \def\a{2} % 隐藏棱虚线 \draw[dashed, gray] (0,0,0) -- (\a,0,0) (0,0,0) -- (0,\a,0) (0,0,0) -- (0,0,\a); % 底面 \filldraw[fillcyan!15, drawblack] (\a,0,0) -- (\a,\a,0) -- (0,\a,0) -- (0,0,0) -- cycle; % 正面 \filldraw[fillcyan!25, drawblack] (0,0,0) -- (\a,0,0) -- (\a,0,\a) -- (0,0,\a) -- cycle; % 侧面 \filldraw[fillcyan!35, drawblack] (\a,0,0) -- (\a,\a,0) -- (\a,\a,\a) -- (\a,0,\a) -- cycle; % 顶面 \filldraw[fillcyan!20, drawblack] (0,0,\a) -- (\a,0,\a) -- (\a,\a,\a) -- (0,\a,\a) -- cycle; % 后面两个侧面 \filldraw[fillcyan!10, drawblack] (0,\a,0) -- (\a,\a,0) -- (\a,\a,\a) -- (0,\a,\a) -- cycle; \filldraw[fillcyan!15, drawblack] (0,0,\a) -- (0,\a,\a) -- (0,\a,0) -- (0,0,0) -- cycle; \end{tikzpicture} \end{document}4.2 长方体Cuboid长方体是正方体的延伸只需将三个方向的尺寸设置为不同值\documentclass{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} \tdplotsetmaincoords{60}{125} \begin{document} \begin{tikzpicture}[tdplot_main_coords, scale1] % 长方体尺寸x方向4y方向2z方向2.5 \def\W{4} % 宽x方向 \def\D{2} % 深y方向 \def\H{2.5} % 高z方向 % 隐藏棱 \draw[dashed, gray!60] (0,0,0) -- (\W,0,0) (0,0,0) -- (0,\D,0) (0,0,0) -- (0,0,\H); % 底面 \filldraw[fillorange!15, drawblack] (\W,0,0) -- (\W,\D,0) -- (0,\D,0) -- (0,0,0) -- cycle; % 正面 \filldraw[fillorange!25, drawblack] (0,0,0) -- (\W,0,0) -- (\W,0,\H) -- (0,0,\H) -- cycle; % 右侧面 \filldraw[fillorange!35, drawblack] (\W,0,0) -- (\W,\D,0) -- (\W,\D,\H) -- (\W,0,\H) -- cycle; % 顶面 \filldraw[fillorange!20, drawblack] (0,0,\H) -- (\W,0,\H) -- (\W,\D,\H) -- (0,\D,\H) -- cycle; % 后左侧面 \filldraw[fillorange!10, drawblack] (0,0,0) -- (0,\D,0) -- (0,\D,\H) -- (0,0,\H) -- cycle; % 后面 \filldraw[fillorange!10, drawblack] (0,\D,0) -- (\W,\D,0) -- (\W,\D,\H) -- (0,\D,\H) -- cycle; % 标注尺寸可选 \draw[-, red] (\W0.3,0,0) -- (\W0.3,0,\H) node[midway,right]{$H$}; \draw[-, red] (0,-0.3,0) -- (\W,-0.3,0) node[midway,below]{$W$}; \draw[-, red] (\W,0,-0.3) -- (\W,\D,-0.3) node[midway,right]{$D$}; \end{tikzpicture} \end{document}4.3 圆柱\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 方法斜投影法绘制圆柱 % 参数 \def\rx{1} % 椭圆 x 半径 \def\ry{0.35} % 椭圆 y 半径透视压缩 \def\h{3.5} % 高度 % 侧面矩形 弧线效果 \fill[gray!20] (-\rx, 0) rectangle (\rx, \h); \draw[thick] (-\rx, 0) -- (-\rx, \h); \draw[thick] (\rx, 0) -- (\rx, \h); % 底面椭圆虚线后半 \draw[dashed, gray] (\rx,0) arc (0:180:\rx cm and \ry cm); \draw[thick] (\rx,0) arc (0:-180:\rx cm and \ry cm); % 顶面椭圆完整实线 \filldraw[fillgray!40, drawblack, thick] (0,\h) ellipse (\rx cm and \ry cm); \end{tikzpicture} \end{document}4.4 圆锥\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} \def\rx{1.5} % 底面 x 半径 \def\ry{0.4} % 底面 y 半径透视压缩 \def\h{4} % 高度 % 侧面两条母线 \fill[orange!20] (-\rx, 0) -- (0, \h) -- (\rx, 0) arc (0:-180:\rx cm and \ry cm) -- cycle; \draw[thick] (-\rx, 0) -- (0, \h) -- (\rx, 0); % 底面椭圆 \draw[dashed, gray] (\rx,0) arc (0:180:\rx cm and \ry cm); \draw[thick] (\rx,0) arc (0:-180:\rx cm and \ry cm); % 顶点标注 \filldraw[black] (0,\h) circle (1.5pt) node[right]{$A$顶点}; % 高度标注 \draw[dashed, gray] (0,0) -- (0,\h); \draw[-, blue] (0.2,0) -- (0.2,\h) node[midway,right]{$h$}; \end{tikzpicture} \end{document}4.5 球体球体使用tikz-3dplot 渐变填充来模拟三维效果\documentclass{standalone} \usepackage{tikz} \usepackage{tikz-3dplot} \tdplotsetmaincoords{60}{115} \begin{document} \begin{tikzpicture}[tdplot_main_coords, scale2.5] % 绘制赤道圆虚线后半实线前半 \draw[dashed, gray] (1,0,0) arc (0:180:1cm and 1cm); % 赤道后半 \draw[thick, black] (1,0,0) arc (0:-180:1cm and 1cm); % 赤道前半 % 绘制两条经线虚线为隐藏部分 \tdplotsetrotatedcoords{90}{90}{90} \draw[dashed, gray, tdplot_rotated_coords] (1,0,0) arc (0:180:1); % 经线隐藏部分 \draw[thick, tdplot_rotated_coords] (1,0,0) arc (0:-180:1); % 经线可见部分 \tdplotsetrotatedcoords{0}{90}{90} \draw[dashed, gray, tdplot_rotated_coords] (1,0,0) arc (0:180:1); \draw[thick, tdplot_rotated_coords] (1,0,0) arc (0:-180:1); % 坐标轴 \draw[-stealth, thick] (0,0,0) -- (1.5,0,0) node[right]{$x$}; \draw[-stealth, thick] (0,0,0) -- (0,1.3,0) node[right]{$y$}; \draw[-stealth, thick] (0,0,0) -- (0,0,1.3) node[above]{$z$}; \end{tikzpicture} \end{document}带渐变填充的实心球体更美观\documentclass{standalone} \usepackage{tikz} \begin{document} \begin{tikzpicture} % 使用径向渐变模拟光照球体 \shade[ball colorblue!60!white] (0,0) circle (2cm); % 橙色球 \shade[ball colororange!80!red] (5,0) circle (1.5cm); % 红色小球 \shade[ball colorred!70!black] (9,0) circle (1cm); \end{tikzpicture} \end{document}5. 样式与美化5.1 线型与粗细\draw[ultra thin] ... % 0.1 pt \draw[very thin] ... % 0.2 pt \draw[thin] ... % 0.4 pt \draw[thick] ... % 0.8 pt \draw[very thick] ... % 1.2 pt \draw[ultra thick] ... % 1.6 pt \draw[line width3pt] ... % 自定义线宽 \draw[dashed] ... % 虚线 \draw[dotted] ... % 点线 \draw[dash dot] ... % 点划线5.2 填充图案patterns 库\usetikzlibrary{patterns} \draw[patterndots] ... % 点状 \draw[patterngrid] ... % 网格 \draw[patterncrosshatch] ... % 交叉线 \draw[patternnorth east lines] ... % 斜线 \draw[patternfivepointed stars] ... % 五角星图案 \draw[patternhorizontal lines] ... % 水平线5.3 渐变填充shading% 线性渐变左→右 \shade[left colorblue, right colorred] (0,0) rectangle (4,2); % 线性渐变上→下 \shade[top coloryellow, bottom colororange] (0,0) rectangle (4,2); % 径向渐变球体效果 \shade[inner colorwhite, outer colorblue!60] (0,0) circle (1.5); % ball color最像真实球体 \shade[ball colorgreen!50!black] (0,0) circle (1.5);5.4 使用\tikzset定义可复用样式\tikzset{ myshape/.style { draw blue!70!black, fill blue!20, thick, rounded corners 3pt }, highlight/.style { fill yellow!60, draw orange, very thick } } % 使用自定义样式 \draw[myshape] (0,0) rectangle (3,2); \draw[highlight] (0,0) circle (1);6. 综合实践案例案例一几何图形展示板\documentclass[12pt]{article} \usepackage{tikz} \usetikzlibrary{shapes.geometric, patterns} \usepackage[a4paper, margin2cm]{geometry} \begin{document} \begin{center} \textbf{\Large 平面几何图形展示} \end{center} \begin{tikzpicture}[scale0.9] % 第一行基本多边形 % 三角形 \filldraw[fillred!25, drawred!70, thick] (0,0) -- (2,0) -- (1,1.73) -- cycle; \node[below] at (1,-0.2) {等边三角形}; % 矩形 \filldraw[fillblue!20, drawblue, thick] (3,0) rectangle (5.5,1.5); \node[below] at (4.25,-0.2) {矩形}; % 平行四边形 \filldraw[fillgreen!25, drawgreen!60!black, thick] (6.5,0) -- (9,0) -- (9.8,1.5) -- (7.3,1.5) -- cycle; \node[below] at (8.15,-0.2) {平行四边形}; % 第二行圆形系列 % 圆 \filldraw[fillorange!30, draworange, thick] (1,3.5) circle (1.2); \node[below] at (1,2.1) {圆}; % 椭圆 \filldraw[fillpurple!25, drawpurple, thick] (4.5,3.5) ellipse (1.8 and 1); \node[below] at (4.5,2.3) {椭圆}; % 五角星 \node[star, star points5, star point ratio2.5, drawblack, fillyellow, minimum size2.5cm] at (8.5,3.5) {}; \node[below] at (8.5,2.1) {五角星}; % 第三行正多边形 \node[regular polygon, regular polygon sides5, drawteal, fillteal!20, minimum size2.2cm] at (1,7) {}; \node[below] at (1,5.7) {正五边形}; \node[regular polygon, regular polygon sides6, drawbrown, fillbrown!20, minimum size2.2cm] at (4.5,7) {}; \node[below] at (4.5,5.7) {正六边形}; \node[regular polygon, regular polygon sides8, drawmagenta, fillmagenta!15, minimum size2.2cm] at (8,7) {}; \node[below] at (8,5.7) {正八边形}; \end{tikzpicture} \end{document}案例二三维几何体展示板\documentclass[12pt]{article} \usepackage{tikz} \usepackage{tikz-3dplot} \usepackage[a4paper, margin2cm]{geometry} \begin{document} \begin{center} \textbf{\Large 空间几何体展示} \end{center} \vspace{1cm} % --- 正方体 --- \begin{minipage}{0.3\textwidth} \centering \begin{tikzpicture}[x{(1cm,0)}, y{(0,1cm)}, z{(0.4cm,0.3cm)}, scale1.2] \def\a{2} \draw[dashed,gray] (0,0,0)--(\a,0,0) (0,0,0)--(0,\a,0) (0,0,0)--(0,0,\a); \filldraw[fillblue!15,drawblack] (0,0,\a)--(\a,0,\a)--(\a,\a,\a)--(0,\a,\a)--cycle; \filldraw[fillblue!25,drawblack] (\a,0,0)--(\a,\a,0)--(\a,\a,\a)--(\a,0,\a)--cycle; \filldraw[fillblue!20,drawblack] (0,\a,0)--(\a,\a,0)--(\a,\a,\a)--(0,\a,\a)--cycle; \draw[black,thick] (\a,0,0)--(0,0,0) (0,\a,0)--(0,0,0) (0,0,\a)--(0,0,0); \end{tikzpicture} \textbf{正方体} \end{minipage} % \begin{minipage}{0.3\textwidth} \centering \begin{tikzpicture}[scale0.9] \def\rx{1.2} \def\ry{0.3} \def\h{3} \fill[gray!20] (-\rx,0) rectangle (\rx,\h); \draw[thick] (-\rx,0)--(-\rx,\h) (\rx,0)--(\rx,\h); \draw[dashed,gray] (\rx,0) arc (0:180:\rx cm and \ry cm); \draw[thick] (\rx,0) arc (0:-180:\rx cm and \ry cm); \filldraw[fillgray!40, drawblack, thick] (0,\h) ellipse (\rx cm and \ry cm); \end{tikzpicture} \textbf{圆柱} \end{minipage} % \begin{minipage}{0.3\textwidth} \centering \begin{tikzpicture}[scale0.9] \def\rx{1.3} \def\ry{0.35} \def\h{3.5} \fill[orange!20] (-\rx,0) -- (0,\h) -- (\rx,0) arc (0:-180:\rx cm and \ry cm) -- cycle; \draw[thick] (-\rx,0)--(0,\h)--(\rx,0); \draw[dashed,gray] (\rx,0) arc (0:180:\rx cm and \ry cm); \draw[thick] (\rx,0) arc (0:-180:\rx cm and \ry cm); \filldraw[black] (0,\h) circle (1.5pt); \end{tikzpicture} \textbf{圆锥} \end{minipage} \vspace{1.5cm} \begin{center} \begin{tikzpicture} % 球体渐变填充 \shade[ball colorblue!50!white] (0,0) circle (1.8cm); \node[below] at (0,-2) {\textbf{球体}}; % 长方体 \begin{scope}[x{(1cm,0)}, y{(0,1cm)}, z{(0.35cm,0.28cm)}, xshift5cm, yshift-0.5cm, scale1.1] \def\W{3} \def\D{1.5} \def\H{2} \draw[dashed,gray] (0,0,0)--(\W,0,0) (0,0,0)--(0,\D,0) (0,0,0)--(0,0,\H); \filldraw[fillgreen!15,drawblack] (0,0,\H)--(\W,0,\H)--(\W,\D,\H)--(0,\D,\H)--cycle; \filldraw[fillgreen!25,drawblack] (\W,0,0)--(\W,\D,0)--(\W,\D,\H)--(\W,0,\H)--cycle; \filldraw[fillgreen!20,drawblack] (0,\D,0)--(\W,\D,0)--(\W,\D,\H)--(0,\D,\H)--cycle; \draw[black,thick] (\W,0,0)--(0,0,0) (0,\D,0)--(0,0,0) (0,0,\H)--(0,0,0); \end{scope} \node[below] at (6.5,-2) {\textbf{长方体}}; \end{tikzpicture} \end{center} \end{document}案例三带标注的几何图平面图形作图\documentclass{standalone} \usepackage{tikz} \usetikzlibrary{angles, quotes, decorations.markings} \begin{document} \begin{tikzpicture}[scale1.5] % 绘制三角形 ABC \coordinate (A) at (0,0); \coordinate (B) at (4,0); \coordinate (C) at (1.5,3); \filldraw[fillblue!10, drawblue, thick] (A) -- (B) -- (C) -- cycle; % 顶点标注 \node[below left] at (A) {$A$}; \node[below right] at (B) {$B$}; \node[above] at (C) {$C$}; % 高从 C 到 AB 的垂线 \draw[dashed, red] (C) -- (1.5,0) node[below]{$H$}; \draw[red, thick] (1.4,0) -- (1.4,0.1) -- (1.5,0.1); % 直角标记 % 边长标注 \draw[-, orange] (-0.3,0) -- (-0.3,3) node[midway, left]{$h$}; % 角度标注需要 angles 和 quotes 库 \pic[drawgreen!60!black, thick, angle radius0.6cm, $\alpha$] {angle B--A--C}; \pic[drawpurple, thick, angle radius0.5cm, $\beta$] {angle A--B--C}; \end{tikzpicture} \end{document}7. 常用宏包与库一览宏包 / 库加载方式用途tikz\usepackage{tikz}核心绘图包必须tikz-3dplot\usepackage{tikz-3dplot}真实 3D 坐标系、球体pgfplots\usepackage{pgfplots}数据可视化/函数图像shapes.geometric\usetikzlibrary{shapes.geometric}正多边形、星形等预定义形状shapes.symbols\usetikzlibrary{shapes.symbols}符号形状云、爆炸等patterns\usetikzlibrary{patterns}图案填充斜线、网格等3d\usetikzlibrary{3d}基础 3D 平面变换angles\usetikzlibrary{angles}角度弧标注quotes\usetikzlibrary{quotes}引用语法标注角度decorations.markings\usetikzlibrary{decorations.markings}路径上添加箭头等装饰positioning\usetikzlibrary{positioning}节点相对定位arrows.meta\usetikzlibrary{arrows.meta}现代箭头样式库calc\usetikzlibrary{calc}坐标计算如中点、偏移fit\usetikzlibrary{fit}自动拟合节点的包围框附录快速语法参考卡% 基本框架 \usepackage{tikz} \begin{tikzpicture}[选项] ... \end{tikzpicture} % 点、线 \draw (0,0) -- (1,1); % 直线 \draw[-, thick] (0,0) -- (3,0); % 带箭头直线 \draw[rounded corners] (0,0) -- (1,1) -- (2,0); % 圆角折线 % 基本形状 \draw (cx,cy) circle (r); % 圆 \draw (cx,cy) ellipse (rx and ry); % 椭圆 \draw (x1,y1) rectangle (x2,y2); % 矩形 \draw (A) -- (B) -- (C) -- cycle; % 三角形/多边形 % 填充 \fill[blue!30] (0,0) circle (1); \filldraw[fillred!20, drawred] (0,0) rectangle (2,1); \shade[ball colorblue] (0,0) circle (1); % 球形渐变 % 正多边形 / 星形需库 \usetikzlibrary{shapes.geometric} \node[regular polygon, regular polygon sides6, draw] at (0,0) {}; \node[star, star points5, draw, fillyellow] at (0,0) {}; % 坐标定义 \coordinate (P) at (1,2); \draw (P) -- (3,4); % 3D需包 \usepackage{tikz-3dplot} \tdplotsetmaincoords{60}{125} \begin{tikzpicture}[tdplot_main_coords] ... \end{tikzpicture} % 文字标注 \node[above] at (1,2) {文字}; \node[draw, circle] at (0,0) {文字};参考资料Wikibooks: LaTeX/PGF/TikZ2025年2月更新tikz.dev — TikZ PGF Manual官方在线手册对应 pgf 3.1.11Overleaf: TikZ package tutorialWikipedia: PGF/TikZstable release 3.1.11, 2025-08-14texample.net — TikZ 示例社区

相关新闻