Tikz 绘图的内容非常复杂,目前没有精力去仔细学习,只是简单记录一些可能用到的例子。一部分例子是我自己绘制的,更多的则是参考的网上公开资料。

Tikz 相关教程例如:TikZBolg

有一些在线绘图工具可以可视化绘制简单图形,并导出 Tikz 代码,例如:Mathcha

对于更复杂的需求,可以使用专业的矢量图绘制软件(例如 Inkscape) 绘制并导出 Tikz 代码。

函数图像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[->] (-0.5, 0) -- (6, 0) node[above] {$x$};
\draw[->] (0, -0.5) -- (0, 5) node[left] {$y$};

\draw (2.5, 0.1) -- (2.5, -0.1) node[below] {$1$};
\draw (-0.2, 0) node[below] {$0$};

\draw[domain=0:1.0, thick, dashed, smooth, variable=\x] plot ({2.5*\x}, {5*\x*\x}) node[left] {$5x^2$};
\draw[domain=0:2.2, thick, dashed, smooth, variable=\x] plot ({2.5*\x}, {\x*\x}) node[right] {$x^2$};
\draw[domain=0:1.2, thick, smooth, variable=\x] plot ({2.5*\x}, {\x*\x + 2*\x + 1}) node[right] {$x^2 + 2x + 1$};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
xlabel=$n$ (Input Size),
ylabel=$T(n)$ (Time Complexity),
xmin=2, xmax=8,
ymode=log,
xtick={1, 2, 3, 4, 5, 6, 7, 8},
ytick={1, 8, 64, 512, 4096},
yticklabels={1, 8, 64, 512, 4096},
domain=2:8,
samples=200,
clip=false,
]

% O(1) - Constant
\addplot[very thick, dashed] {1} node[right] {$O(1)$};

% O(log n) - Logarithmic
\addplot[very thick] {ln(x)} node[right] {$O(\log n)$};

% O(n) - Linear
\addplot[very thick] {x} node[right] {$O(n)$};

% O(n log n) - Linearithmic
\addplot[very thick] {x * ln(x)} node[right] {$O(n \log n)$};

% O(n^2) - Quadratic
\addplot[very thick] {x^2} node[right] {$O(n^2)$};

% O(2^n) - Exponential
\addplot[very thick] {2^x} node[right] {$O(2^n)$};

\addplot[very thick,domain=2:7] {sqrt(2*pi*x) * (x/e)^x} node[above] {$O(n!)$}; % ~ n!

\end{axis}
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[->] (-2,0) -- (3,0) node[right] {$\mathbb{R}$};
\draw[->] (0,-1) -- (0,2) node[above] {$\mathrm{i}\,\mathbb{R}$};
\draw[->,thick] (0,0) -- (2,1) node[above right] {$z = a + b\,\mathrm{i}$};
\draw[dashed] (2,1) -- (2,0);
\draw[dashed] (2,1) -- (0,1);
\draw (0.5,0) arc[start angle=0,end angle=26.57,radius=0.5];
\node at (1,0.25) {$\theta$};
\node at (1,.75) {$r$};
\node at (2,-0.5) {$a = r \cos(\theta)$};
\node at (-1.4,1) {$b = r \sin(\theta)$};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[domain=-4.5:4.5, smooth, variable=\x] plot ({\x}, {sin(\x r)}) node[right] {$\sin(x)$};
\draw[domain=-4.5:4.5, smooth, variable=\x] plot ({\x}, {cos(\x r)}) node[right] {$\cos(x)$};

\draw[->] (-5,0) -- (5,0) node [above] {$x$};
\draw[->] (0, -1.2) -- (0, 1.2) node[left] {$y$};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[->] (-1,0) -- (4.7,0) node[right] {$x$};
\draw[->] (0,-2.5) -- (0,2.5) node[above] {$y$};
\draw[thick,orange,domain=0:3.7,smooth,variable=\x] plot ({\x},{(\x - 2)*(\x - 2) - 2}) node[right] {$f(x)$};

\filldraw[thick, orange] (2, -2) circle (2pt) node[below right] {Global Min};

\draw[] (0.1,2) -- (-0.1,2) node[left] {$\max_{[a,b]} f(x)$};
\draw[dashed] (2,-2) -- (-0.1,-2) node[left] {$\min_{[a,b]} f(x)$};
\draw[] (0.1,-2) -- (-0.1,-2);

\node[below left] at (0,0) {$a$};
\draw[dashed] (3.7, 0.89) -- (3.7,0) node[below] {$b$};

\draw[dashed] (4, -1) -- (-0.1,-1) node[left] {$L$};

\draw[dashed] (3, -1) -- (3,0) node[above] {$c_1$};
\draw[dashed] (1, -1) -- (1,0) node[above] {$c_2$};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[scale=0.7, font=\Large]
\draw[->] (0,0) -- (11,0) node[pos=1.05] {$i$};
\draw[->] (0,0) -- (0,5) node[anchor=south, pos=1] {$\sigma_i$};

\draw[dashed] (0,1) -- (11,1);
\draw (0,1) -- (0.2,1);
\node[left] at (0,1) {$\alpha$};
\node[left] at (0,0) {$0$};

\def\radius{3pt}

\foreach \i in {1,...,10} {
\pgfmathsetmacro{\val}{4*exp(-0.5*(\i-1))}
\draw[black, thick] (\i,\val) circle (\radius);
\pgfmathsetmacro{\shiftVal}{max(\val - 1, 0)}
\fill[red] (\i,\shiftVal) circle (\radius);
\draw[->, red]
($(\i,\val) + (0,-\radius)$) --
($(\i,\shiftVal) + (0,\radius)$);
}

\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
\documentclass{article}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\pagestyle{empty}

\begin{document}

\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}[scale=1.3]
\draw[->] (-1.75, 0) -- (1.75, 0) node[right] {$x$};
\draw[->] (0, -1.25) -- (0, 1.25) node[above] {$y$};
\draw[thick, orange, domain=-1.5:1.5, samples=300] plot (\x, {cos(deg(1 / \x))});
\end{tikzpicture}
\caption*{$\cos\left(\frac{1}{x}\right)$}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}[scale=2]
\draw[->] (-1.2, 0) -- (1.2, 0) node[right] {$x$};
\draw[->] (0, -0.3) -- (0, 1.25) node[above] {$y$};
\draw[thick, orange, domain=-1.05:1.05, samples=200] plot (\x, {cos(deg(1 / \x)) * (\x * \x)});
\end{tikzpicture}
\caption*{$x^2 \cos\left(\frac{1}{x}\right)$}
\end{subfigure}
\begin{subfigure}[b]{0.47\textwidth}
\centering
\begin{tikzpicture}[scale=.8]
\draw[->] (-3,0) -- (3,0) node[right] {$x$};
\draw[->] (0,-3) -- (0,3) node[above] {$y$};

\draw[thick,orange,domain=0.37:2.5,smooth,variable=\x] plot ({\x},{1/\x}) node[right] {$f(x)$};
\draw[thick,orange,domain=-2.5:-0.37,smooth,variable=\x] plot ({\x},{1/\x});
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.47\textwidth}
\centering
\begin{tikzpicture}[scale=1]
\draw[->] (-3,0) -- (3,0) node[right] {$x$};
\draw[->] (0,-1.5) -- (0,1.5) node[above] {$y$};
\draw[thick,orange] (0,1) -- (2.5,1) node[right] {$f(x)$};
\draw[thick,orange] (-2.5,-1) -- (0,-1);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
% All norms
\begin{tikzpicture}[scale=0.7]
\begin{axis}[axis lines=middle,xtick=\empty,ytick=\empty,axis equal,enlargelimits,xmax=1.2,ymax=1.2,xmin=-1.2,ymin=-1.2]
%p=0.5
\begin{scope}[very thick,dotted,orange,domain=0:pi,samples=50]
\addplot[] ({(cos(deg(x)))^(4},{ (sin(deg(x))^(4});
\addplot[] ({(cos(deg(x)))^(4},{ -(sin(deg(x))^(4});
\addplot[] ({-(cos(deg(x)))^(4},{ (sin(deg(x))^(4});
\addplot[] ({-(cos(deg(x)))^(4},{-(sin(deg(x))^(4});
\end{scope}
%p=1
\addplot[blue,domain=0:pi] ({(cos(deg(x)))^2},{(sin(deg(x))^2});
\addplot[blue,domain=0:pi] ({(cos(deg(x)))^2},{-(sin(deg(x))^2});
\addplot[blue,domain=0:pi] ({-(cos(deg(x)))^2},{(sin(deg(x))^2});
\addplot[blue,domain=0:pi] ({-(cos(deg(x)))^2},{-(sin(deg(x))^2});
%p=2
\addplot[red,domain=-pi:0] ({(cos(deg(x)))},{(sin(deg(x))});
\addplot[red,domain=0:pi] ({(cos(deg(x)))},{(sin(deg(x))});
%p=inf
\draw[thick,dashdotted,gray] (axis cs:-1,-1) rectangle (axis cs:1,1);
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}[scale=0.7]
\begin{axis}[axis lines=middle,xtick=\empty,ytick=\empty,axis equal,enlargelimits,xmax=1.5,ymax=1.5,xmin=-1.5,ymin=-1.5]
%p=2
\addplot[red,domain=-pi:0] ({(cos(deg(x)))},{(sin(deg(x)))});
\addplot[red,domain=0:pi] ({(cos(deg(x)))},{(sin(deg(x)))});
%p=2-larger
\addplot[red,domain=-pi:0] ({(sqrt(2)*cos(deg(x)))},{((sqrt(2)*sin(deg(x))))});
\addplot[red,domain=0:pi] ({(sqrt(2)*cos(deg(x)))},{((sqrt(2)*sin(deg(x))))});
%p=inf
\draw[thick,dashdotted,gray] (axis cs:-1,-1) rectangle (axis cs:1,1);
\end{axis}
\end{tikzpicture}
\end{subfigure}
% \caption{XXX} % \label{fig:XXX}
\end{figure}

\end{document}

线性代数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
\documentclass{article}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{subcaption}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\pagestyle{empty}

\begin{document}

\begin{figure}[htbp]
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}[scale=1]
% Axes
\draw[->] (-2,0,0) -- (2,0,0) node[right] {$x_2$};
\draw[->] (0,-2,0) -- (0,2,0) node[above] {$x_3$};
\draw[->] (0,0,-2) -- (0,0,2) node[above] {$x_1$};

% Span of v
\foreach \t in {-1.2,1.2} {
\draw[thick] (0,0,0) -- (\t*1,\t*2,\t*1);
}

% Vector v
\draw[thick,->] (0,0,0) -- (1,2,1) node[midway,right] {$\vec{v}$};
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}[scale=1]
% Axes
\draw[->] (-2,0,0) -- (2,0,0) node[right] {$x_2$};
\draw[->] (0,-2,0) -- (0,2,0) node[above] {$x_3$};
\draw[->] (0,0,-2) -- (0,0,2) node[above] {$x_1$};

% Span of v1 and v2
\fill[cyan!50,opacity=0.3] (-1.8,-1.2,-1.7) -- (1,2,1) -- (2,1,1) -- (-1,-2,-1) -- cycle;
\draw[thick,cyan!50,opacity=0.3] (-1.8,-1.2,-1.7) -- (1,2,1) -- (2,1,1) -- (-1,-2,-1) -- cycle;

% Vectors v1 and v2
\draw[thick,->] (0,0,0) -- (1,2,1) node[above] {$\vec{v_1}$};
\draw[thick,->] (0,0,0) -- (2,1,1) node[right] {$\vec{v_2}$};
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.47\textwidth}
\centering
\begin{tikzpicture}[scale=2.5]
% Axes
\draw[->] (-0.8,0) -- (1.2,0) node[right] {$x_1$};
\draw[->] (0,-0.2) -- (0,1.2) node[above] {$x_2$};

% Original vectors
\draw[thick,->] (0,0) -- (1,0) node[midway, below] {$\vec{u}$};
\draw[thick,->] (0,0) -- (0,1) node[midway, left] {$\vec{v}$};
\draw[thick,->] (0,0) -- (-0.6,1) node[midway, left] {T($\vec{v})$};

% Shaded area
\fill[cyan!50,opacity=0.3] (0,0) -- (1,0) -- (0.4,1) -- (-0.6,1) -- cycle;
\draw[dashed] (1,0) -- (1,1) -- (0,1);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.47\textwidth}
\centering
\begin{tikzpicture}[scale=2.5]
% Axes
\draw[->] (-0.8,0,0) -- (1.2,0,0) node[right] {$x_1$};
\draw[->] (0,-0.2,0) -- (0,1.2,0) node[above] {$x_2$};
\draw[->] (0,0,0.2) -- (0,0,-1.2) node[below right] {$x_3$};

% Original vectors
\draw[thick,->] (0,0,0) -- (1,0,0) node[midway, below] {$\vec{u}$};
\draw[thick,->] (0,0,0) -- (-0.6,1,0) node[midway, left] {$\vec{v}$};
\draw[thick,->] (0,0,0) -- (0,0,-1) node[midway, right] {$\vec{w}$};

% Shaded area
\fill[cyan!50,opacity=0.3] (0,0,0) -- (1,0,0) -- (0.4,1,0) -- (-0.6,1,0) -- cycle;
\fill[cyan!50,opacity=0.3] (0,0,0) -- (1,0,0) -- (1,0,-1) -- (0,0,-1) -- cycle;
\draw[dashed] (1,0,0) -- (1,0,-1) -- (0,0,-1) -- (-0.6,1,-1) -- (-0.6,1,0) -- (0.4,1,0) -- cycle;
\draw[dashed] (1,0,-1) -- (0.4,1,-1) -- (-0.6,1,-1);
\draw[dashed] (0.4,1,0) -- (0.4,1,-1);
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}[scale=2.5]
% Axes
\draw[->] (-0.2,0) -- (1.2,0) node[right] {$x_1$};
\draw[->] (0,-0.2) -- (0,1.2) node[above] {$x_2$};

\draw[thick,->] (0,0) -- (1,0) node[midway, below] {$\vec{u}$};
\draw[thick,->] (0,0) -- (0,1) node[midway, left] {$\vec{v}$};

\draw[thick,->] (0,0) -- (0.7,0.5) node[midway, above] {$\vec{w}$};

\fill[cyan!50,opacity=0.3] (0,0) -- (1,0) -- (1,1) -- (0,1) -- cycle;
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\begin{tikzpicture}[scale=2.5]
% Axes
\draw[->] (-0.2,0) -- (1.2,0) node[right] {$x_1$};
\draw[->] (0,-0.2) -- (0,1.2) node[above] {$x_2$};

\draw[thick,->] (0,0) -- (0.8,0.1) node[midway, below=0.1cm] {$T(\vec{u})$};
\draw[thick,->] (0,0) -- (0.2,1.1) node[midway, left=0.2cm] {$T(\vec{v})$};

\draw[thick,->] (0,0) -- (0.7,0.8) node[midway, above=0.3cm] {$T(\vec{w})$};

\fill[cyan!50,opacity=0.3] (0,0) -- (0.8,0.1) -- (1,1.2) -- (0.2,1.1) -- cycle;
\end{tikzpicture}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\begin{tikzpicture}[scale=0.85]
% Axes
\draw[->] (0,0,0) -- (3,0,0) node[right] {$x_1$};
\draw[->] (0,0,0) -- (0,2,0) node[above] {$x_3$};
\draw[->] (0,0,0) -- (0,0,3) node[above] {$x_2$};

% Projection onto x1-x2 plane
\fill[cyan!50,opacity=0.3] (0,0,0) -- (3,0,0) -- (3,0,3) -- (0,0,3) -- cycle;

% Point in space
\fill[] (2,2,1) circle (2pt) node[above right] {$\vec{x}$};
\fill[] (1,-1,2.5) circle (2pt) node[right] {$\vec{v}$};

% Projection line
\draw[dashed] (2,2,1) -- (2,0,1);
\draw[dashed] (1,-1,2.5) -- (1,0,2.5);

% Projection point
\fill[orange] (2,0,1) circle (2pt) node[below right] {$T(\vec{x})$};
\fill[orange] (1,0,2.5) circle (2pt) node[above right] {$T(\vec{v})$};
\end{tikzpicture}
\end{subfigure}
% \caption{XXX} % \label{fig:XXX}
\end{figure}

\end{document}

几何图像

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (4,2);
\coordinate (D) at (1,2);
\draw[thick] (A) -- (B) -- (C) -- (D) -- cycle;
\draw[->, thick, red] (A) -- (B) node[midway, below]{\(\vec{u}\)};
\draw[->, thick, blue] (A) -- (D) node[midway, left]{\(\vec{v}\)};
\foreach \p/\n in {A/A, B/B, C/C, D/D} {
\filldraw (\p) circle (2pt) node[above right]{\n};
}
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (4,0);
\coordinate (C) at (2,3);
\draw[thick] (A) -- (B) -- (C) -- cycle;
\draw[dashed, red] (C) -- ($(A)!(C)!(B)$) coordinate (H);
\filldraw[black] (A) circle (2pt) node[below left]{A};
\filldraw[black] (B) circle (2pt) node[below right]{B};
\filldraw[black] (C) circle (2pt) node[above,yshift=2pt]{C};
\filldraw[red] (H) circle (2pt) node[below,yshift=-2pt]{H};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tkz-euclide}

\begin{document}

\begin{tikzpicture}[scale=1.5]
\tkzDefPoints{0/0/A,5/0/B,5/5/F,0/5/E}
\tkzDefPoints{2/2/D,7/2/C,7/7/G,2/7/H}
\tkzDrawPolygon(A,B,F,E)
\tkzDrawPolygon(G,C)
\tkzDrawPolygon(G,H)
\tkzDrawPolygon[dashed](A,D)
\tkzDrawPolygon(H,E)
\tkzDrawPolygon(G,F)
\tkzDrawPolygon(B,C)
\tkzDefMidPoint(A,C)
\tkzDrawPolygon[dashed](D,C)
\tkzDrawPolygon[dashed](D,H)
\tkzGetPoint{I}
\tkzDrawPoint(I)

\tkzDefMidPoint(A,C)
\tkzGetPoint{I}
\tkzDrawPoint(I)

\tkzDefMidPoint(A,H)
\tkzGetPoint{N}
\tkzDrawPoint(N)
\tkzDefMidPoint(B,G)
\tkzGetPoint{L}
\tkzDrawPoint(L)

\tkzDefMidPoint(H,F)
\tkzGetPoint{J}
\tkzDrawPoint(J)

\tkzDefMidPoint(H,C)
\tkzGetPoint{M}
\tkzDrawPoint(M)

\tkzDefMidPoint(A,F)
\tkzGetPoint{K}
\tkzDrawPoint(K)

\tkzDrawPolygon(N,K,I,L,J,N,I)
\tkzDrawPolygon(J,K,L)
\tkzDrawPolygon[dashed](N,M)
\tkzDrawPolygon[dashed](L,M)
\tkzDrawPolygon[dashed](I,M)
\tkzDrawPolygon[dashed](J,M)

\tkzLabelPoints(A)
\tkzLabelPoints(B)
\tkzLabelPoints[below](I)
\tkzLabelPoints[right](C,G,F)
\tkzLabelPoints[left](D,H,E)

\tkzLabelPoints[right](L)
\tkzLabelPoints[left](N)
\tkzLabelPoints[below](I)
\tkzLabelPoints[above](J)
\tkzLabelPoint[above left,xshift=5pt,yshift=3pt](K){$K$}
\tkzLabelPoint[left,xshift=-1pt,yshift=3pt](M){$M$}
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tkz-euclide}

\begin{document}

\begin{tikzpicture}[scale=1.7]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (4,1);
\coordinate (D) at (1,1);
\coordinate (E) at (0,3);
\coordinate (F) at (3,3);
\coordinate (G) at (4,4);
\coordinate (H) at (1,4);
\coordinate (S) at (2,6);
\coordinate (O) at (2,0.5);

\draw (B) -- (C) -- (G) -- (F) -- (B) -- cycle;
\draw[dashed] (G) -- (H) -- (E);
\draw (E) -- (A) -- (B);
\draw[dashed] (H) -- (D) -- (A);
\draw[dashed] (D) -- (C);
\draw (E) -- (S);
\draw[dashed] (H) -- (S);
\draw (G) -- (S);
\draw (F) -- (S);
\draw (E) -- (F);
\draw[dashed] (A) -- (C);
\draw[dashed] (B) -- (D);

\node[below left] at (A) {A};
\node[below right] at (B) {B};
\node[right] at (C) {C};
\node[above left,xshift=-2pt,yshift=-7pt] at (D) {D};
\node[left,yshift=-3pt] at (E) {E};
\node[above right,yshift=-11pt] at (F) {F};
\node[right] at (G) {G};
\node[left,xshift=15pt,yshift=-8pt] at (H) {H};
\node[above right,xshift=-3pt] at (S) {S};
\node[below left] at (O) {O};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{tkz-euclide}

\begin{document}

\begin{tikzpicture}[scale=1.7]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (1,2);
\coordinate (D) at (0,4);
\coordinate (E) at (3,4);
\coordinate (F) at (1,6);
\coordinate (S) at (7,3);
\draw (A) -- (B);
\draw (D) -- (E) -- (F) -- cycle;
\draw (A) -- (D);
\draw (B) -- (E);
\draw[dashed] (F) -- (C) -- (A);
\draw[dashed] (C) -- (B);
\draw (F) -- (S);
\draw (E) -- (S);
\draw[dashed] (C) -- (S);
\draw (B) -- (S);

\node[xshift=-4pt,yshift=-7pt] at (A) {A};
\node[xshift=4pt,yshift=-7pt] at (B) {B};
\node[yshift=0pt,xshift=-8pt] at (C) {C};
\node[xshift=-6pt] at (D) {D};
\node[xshift=6pt,yshift=5pt] at (E) {E};
\node[yshift=5pt] at (F) {F};
\node[xshift=5pt] at (S) {S};
\end{tikzpicture}

\end{document}

一维空间离散网格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[>=stealth, thick]
\def\N{6}
\def\L{8}
\def\H{0.15}

\pgfmathsetmacro{\dx}{\L/\N}
\pgfmathsetmacro{\halfdx}{0.5*\dx}

% Axes
\draw (0,0) -- (\L,0);

% Points
\foreach \i in {0,...,\N} {
\pgfmathsetmacro{\x}{\i*\dx}
\draw (\x,0) -- (\x,\H);
\fill (\x,0) circle (0.4pt);
}

% Labels
\draw[red] (0,0) -- (0,-\H);
\node[below,red] at (0,-2*\H) {$a$};
\draw[red] (\L,0) -- (\L,-\H);
\node[below,red] at (\L,-2*\H) {$b$};

\node[above] at (0,\H) {$x_{0}$};
\node[above] at (\dx,\H) {$x_{1}$};
\node[above] at (\L-\dx,\H) {$x_{N-1}$};
\node[above] at (\L,\H) {$x_{N}$};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[>=stealth, thick]
\def\N{6}
\def\L{8}
\def\H{0.15}

\pgfmathsetmacro{\dx}{\L/\N}
\pgfmathsetmacro{\halfdx}{0.5*\dx}

% Axes
\draw[dashed,Green] (-\halfdx,0) -- (0,0);
\draw[dashed,Green] (\L,0) -- (\L+\halfdx,0);
\draw (0,0) -- (\L,0);

% Points
\foreach \i in {0,...,\N} {
\pgfmathsetmacro{\x}{\i*\dx}
\draw (\x,0) -- (\x,\H);
\fill (\x,0) circle (0.4pt);
}

\pgfmathsetmacro{\BN}{\N + 1}
\foreach \i in {0,...,\BN} {
\pgfmathsetmacro{\x}{\i*\dx - 0.5*\dx}
\draw[Green] (\x,0) -- (\x,-\H);
\fill[Green] (\x,0) circle (0.4pt);
}

% Labels
\draw[red] (0,0) -- (0,-\H);
\node[below,red] at (0,-2*\H) {$a$};
\draw[red] (\L,0) -- (\L,-\H);
\node[below,red] at (\L,-2*\H) {$b$};

\node[above] at (0,\H) {$x_{0}$};
\node[above] at (\dx,\H) {$x_{1}$};
\node[above] at (\L-\dx,\H) {$x_{N-1}$};
\node[above] at (\L,\H) {$x_{N}$};

\node[below,Green] at (-\halfdx,-\H) {$x_{-\frac{1}{2}}$};
\node[below,Green] at (\halfdx,-\H) {$x_{\frac{1}{2}}$};
\node[below,Green] at (\L-\halfdx,-\H) {$x_{N-\frac{1}{2}}$};
\node[below,Green] at (\L+\halfdx,-\H) {$x_{N+\frac{1}{2}}$};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[>=stealth, thick]
\def\N{6}
\def\L{8}
\def\H{0.15}

\pgfmathsetmacro{\dx}{\L/\N}
\pgfmathsetmacro{\halfdx}{0.5*\dx}

% Axes
\draw[dashed,Green] (-\halfdx,0) -- (0,0);
\draw[dashed,Green] (\L,0) -- (\L+\halfdx,0);
\draw (0,0) -- (\L,0);

% Points
\foreach \i in {0,...,\N} {
\pgfmathsetmacro{\x}{\i*\dx}
\draw (\x,0) -- (\x,\H);
\fill (\x,0) circle (0.4pt);
}

\pgfmathsetmacro{\BN}{\N + 1}
\foreach \i in {0,...,\BN} {
\pgfmathsetmacro{\x}{\i*\dx - 0.5*\dx}
\draw[Green] (\x,0) -- (\x,-\H);
\fill[Green] (\x,0) circle (0.4pt);
}

% Labels
\draw[red] (0,0) -- (0,-\H);
\node[below,red] at (0,-2*\H) {$a$};
\draw[red] (\L,0) -- (\L,-\H);
\node[below,red] at (\L,-2*\H) {$b$};

\node[above] at (0,\H) {$x_{\frac12}$};
\node[above] at (\dx,\H) {$x_{\frac32}$};
\node[above] at (\L-\dx,\H) {$x_{N-\frac12}$};
\node[above] at (\L,\H) {$x_{N+\frac12}$};

\node[below,Green] at (-\halfdx,-\H) {$x_{0}$};
\node[below,Green] at (\halfdx,-\H) {$x_1$};
\node[below,Green] at (\L-\halfdx,-\H) {$x_{N}$};
\node[below,Green] at (\L+\halfdx,-\H) {$x_{N+1}$};
\end{tikzpicture}

\end{document}

二维空间离散网格

下图应该是用其它专业软件制作后转换为 tikz 的,代码参考 https://arxiv.org/abs/2502.20883。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
%uncomment if require: \path (0,300);
%set diagram left start at 0, and has height of 300

%Shape: Grid [id:dp6086037867382692]
\draw [draw opacity=0][line width=1.5] (286.78,55.22) -- (440.67,55.22) -- (440.67,198.45) -- (286.78,198.45) -- cycle ; \draw [line width=1.5] (304.51,55.22) -- (304.51,198.45)(360.51,55.22) -- (360.51,198.45)(416.51,55.22) -- (416.51,198.45) ; \draw [line width=1.5] (286.78,72.95) -- (440.67,72.95)(286.78,128.95) -- (440.67,128.95)(286.78,184.95) -- (440.67,184.95) ; \draw [line width=1.5] ;
%Shape: Diamond [id:dp2704383770206539]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (304.51,151.7) -- (309.17,156.45) -- (304.51,161.2) -- (299.84,156.45) -- cycle ;
%Shape: Diamond [id:dp05191167319843715]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (332.51,180.2) -- (337.17,184.95) -- (332.51,189.7) -- (327.84,184.95) -- cycle ;
%Shape: Diamond [id:dp8396711776809587]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (360.51,152.2) -- (365.17,156.95) -- (360.51,161.7) -- (355.84,156.95) -- cycle ;
%Shape: Diamond [id:dp43560726895372204]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (332.89,123.94) -- (337.55,128.69) -- (332.89,133.44) -- (328.22,128.69) -- cycle ;
%Shape: Diamond [id:dp49146238603682535]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (388.51,180.2) -- (393.17,184.95) -- (388.51,189.7) -- (383.84,184.95) -- cycle ;
%Shape: Diamond [id:dp625980383948383]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (416.51,152.2) -- (421.17,156.95) -- (416.51,161.7) -- (411.84,156.95) -- cycle ;
%Shape: Diamond [id:dp6603613912995167]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (304.51,96.2) -- (309.17,100.95) -- (304.51,105.7) -- (299.84,100.95) -- cycle ;
%Shape: Diamond [id:dp7532338499105224]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (360.51,96.86) -- (365.17,101.61) -- (360.51,106.36) -- (355.84,101.61) -- cycle ;
%Shape: Diamond [id:dp08242433686903328]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (416.51,96.2) -- (421.17,100.95) -- (416.51,105.7) -- (411.84,100.95) -- cycle ;
%Shape: Diamond [id:dp18820567957368406]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (332.51,68.2) -- (337.17,72.95) -- (332.51,77.7) -- (327.84,72.95) -- cycle ;
%Shape: Diamond [id:dp7617641125065957]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (388.51,68.2) -- (393.17,72.95) -- (388.51,77.7) -- (383.84,72.95) -- cycle ;
%Shape: Ellipse [id:dp12162460285712395]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (299.6,185) .. controls (299.6,182.23) and (301.8,180) .. (304.51,180) .. controls (307.22,180) and (309.42,182.23) .. (309.42,185) .. controls (309.42,187.76) and (307.22,190) .. (304.51,190) .. controls (301.8,190) and (299.6,187.76) .. (299.6,185) -- cycle ;
%Shape: Ellipse [id:dp6029546507689866]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (299.6,128.97) .. controls (299.6,126.21) and (301.8,123.97) .. (304.51,123.97) .. controls (307.22,123.97) and (309.42,126.21) .. (309.42,128.97) .. controls (309.42,131.73) and (307.22,133.97) .. (304.51,133.97) .. controls (301.8,133.97) and (299.6,131.73) .. (299.6,128.97) -- cycle ;
%Shape: Ellipse [id:dp8090189307248269]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (299.6,72.95) .. controls (299.6,70.19) and (301.8,67.95) .. (304.51,67.95) .. controls (307.22,67.95) and (309.42,70.19) .. (309.42,72.95) .. controls (309.42,75.71) and (307.22,77.95) .. (304.51,77.95) .. controls (301.8,77.95) and (299.6,75.71) .. (299.6,72.95) -- cycle ;
%Shape: Ellipse [id:dp23527142386059752]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (355.62,72.95) .. controls (355.62,70.19) and (357.82,67.95) .. (360.53,67.95) .. controls (363.24,67.95) and (365.44,70.19) .. (365.44,72.95) .. controls (365.44,75.71) and (363.24,77.95) .. (360.53,77.95) .. controls (357.82,77.95) and (355.62,75.71) .. (355.62,72.95) -- cycle ;
%Shape: Ellipse [id:dp4464329470756502]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (355.62,128.97) .. controls (355.62,126.21) and (357.82,123.97) .. (360.53,123.97) .. controls (363.24,123.97) and (365.44,126.21) .. (365.44,128.97) .. controls (365.44,131.73) and (363.24,133.97) .. (360.53,133.97) .. controls (357.82,133.97) and (355.62,131.73) .. (355.62,128.97) -- cycle ;
%Shape: Ellipse [id:dp4381396312087227]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (355.6,184.95) .. controls (355.6,182.19) and (357.8,179.95) .. (360.51,179.95) .. controls (363.22,179.95) and (365.42,182.19) .. (365.42,184.95) .. controls (365.42,187.71) and (363.22,189.95) .. (360.51,189.95) .. controls (357.8,189.95) and (355.6,187.71) .. (355.6,184.95) -- cycle ;
%Shape: Ellipse [id:dp37631485662632347]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (411.65,185) .. controls (411.65,182.23) and (413.84,180) .. (416.56,180) .. controls (419.27,180) and (421.46,182.23) .. (421.46,185) .. controls (421.46,187.76) and (419.27,190) .. (416.56,190) .. controls (413.84,190) and (411.65,187.76) .. (411.65,185) -- cycle ;
%Shape: Ellipse [id:dp9228054619778103]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (411.6,128.95) .. controls (411.6,126.19) and (413.8,123.95) .. (416.51,123.95) .. controls (419.22,123.95) and (421.42,126.19) .. (421.42,128.95) .. controls (421.42,131.71) and (419.22,133.95) .. (416.51,133.95) .. controls (413.8,133.95) and (411.6,131.71) .. (411.6,128.95) -- cycle ;
%Shape: Ellipse [id:dp9761113886790156]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (411.6,72.95) .. controls (411.6,70.19) and (413.8,67.95) .. (416.51,67.95) .. controls (419.22,67.95) and (421.42,70.19) .. (421.42,72.95) .. controls (421.42,75.71) and (419.22,77.95) .. (416.51,77.95) .. controls (413.8,77.95) and (411.6,75.71) .. (411.6,72.95) -- cycle ;
%Shape: Ellipse [id:dp24235284312952232]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (327.68,101.02) .. controls (327.68,98.26) and (329.88,96.02) .. (332.59,96.02) .. controls (335.3,96.02) and (337.5,98.26) .. (337.5,101.02) .. controls (337.5,103.78) and (335.3,106.02) .. (332.59,106.02) .. controls (329.88,106.02) and (327.68,103.78) .. (327.68,101.02) -- cycle ;
%Shape: Ellipse [id:dp1826735098607173]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (383.6,100.95) .. controls (383.6,98.19) and (385.8,95.95) .. (388.51,95.95) .. controls (391.22,95.95) and (393.42,98.19) .. (393.42,100.95) .. controls (393.42,103.71) and (391.22,105.95) .. (388.51,105.95) .. controls (385.8,105.95) and (383.6,103.71) .. (383.6,100.95) -- cycle ;
%Shape: Ellipse [id:dp255823116982711]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (327.6,156.95) .. controls (327.6,154.19) and (329.8,151.95) .. (332.51,151.95) .. controls (335.22,151.95) and (337.42,154.19) .. (337.42,156.95) .. controls (337.42,159.71) and (335.22,161.95) .. (332.51,161.95) .. controls (329.8,161.95) and (327.6,159.71) .. (327.6,156.95) -- cycle ;
%Shape: Ellipse [id:dp9494151404914138]
\draw [draw opacity=0][fill={rgb, 255:red, 242; green, 7; blue, 37 } ,fill opacity=1 ] (383.6,156.95) .. controls (383.6,154.19) and (385.8,151.95) .. (388.51,151.95) .. controls (391.22,151.95) and (393.42,154.19) .. (393.42,156.95) .. controls (393.42,159.71) and (391.22,161.95) .. (388.51,161.95) .. controls (385.8,161.95) and (383.6,159.71) .. (383.6,156.95) -- cycle ;
%Shape: Diamond [id:dp9243702003505755]
\draw [draw opacity=0][fill={rgb, 255:red, 10; green, 69; blue, 199 } ,fill opacity=1 ] (388.51,124.2) -- (393.17,128.95) -- (388.51,133.7) -- (383.84,128.95) -- cycle ;

% Text Node
\draw (326.16,191) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$x_{i}$};
% Text Node
\draw (377.4,191) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$x_{i+1}$};
% Text Node
\draw (285,152) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$y_{j}$};
% Text Node
\draw (272,96) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$y_{j+1}$};
% Text Node
\draw (290,199) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$x_{i-\frac12}$};
% Text Node
\draw (348,199) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$x_{i+\frac12}$};
% Text Node
\draw (403,199) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$x_{i+\frac32}$};
% Text Node
\draw (250,180) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$y_{j-\frac12}$};
% Text Node
\draw (250,124) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$y_{j+\frac12}$};
% Text Node
\draw (250,68) node [anchor=north west][inner sep=0.75pt] [font=\footnotesize] {$y_{j+\frac32}$};
\end{tikzpicture}
\end{document}

tikz 批注公式

可以利用 tikz 宏包在给数学公式加上背景颜色以及标注。(受到 synercys/annotated_latex_equations 的启发)

实现原理比较复杂:

  • 在公式环境中通过 \tikzmarknode 命令留下绘图锚点;
  • tikzpicture 环境中绘制标注,需要利用前面留下的绘图锚点;
  • 使用 figure 环境包裹公式和标注作为浮动体(否则标注可能会与其他段落混杂在一起,难以保持合适间距)。

完整源码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
\documentclass{article}
\usepackage{amsmath}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\pagestyle{empty}

\begin{document}


\begin{figure}[htbp]
\centering
\vspace{2\baselineskip}

\begin{equation*}
\rho
\left(
\frac{\partial \mathbf{u}}{\partial t}
+
\tikzmarknode{uconv}{\colorbox{Bittersweet!20}{$\mathbf{u}\cdot\nabla \mathbf{u}$}}
\right)
=
-\tikzmarknode{gradp}{\colorbox{OliveGreen!20}{$\nabla p$}}
+
\tikzmarknode{visc}{\colorbox{Orange!40}{$\mu \nabla^2 \mathbf{u}$}}
+
\tikzmarknode{f}{\colorbox{RoyalBlue!20}{$\mathbf{f}$}}
\end{equation*}

\begin{tikzpicture}[overlay,remember picture,>=stealth,
nodes={align=left,inner ysep=1pt},<-]
% Convective term
\path (uconv.south) ++ (0,-1.0em)
node[anchor=north east,color=Bittersweet!85] (uconv_text)
{\scriptsize convective acceleration};
\draw[color=Bittersweet] (uconv.south) |- (uconv_text.north west);

% Pressure gradient
\path (gradp.north) ++ (0,1.0em)
node[anchor=south east,color=OliveGreen!85] (gradp_text)
{\scriptsize pressure gradient force};
\draw[color=OliveGreen] (gradp.north) |- (gradp_text.south west);

% Viscous diffusion
\path (visc.south) ++ (0,-1.0em)
node[anchor=north west,color=Orange!85] (visc_text)
{\scriptsize viscous diffusion term};
\draw[color=Orange] (visc.south) |- (visc_text.north east);

% Body force
\path (f.north) ++ (0,1.0em)
node[anchor=south west,color=RoyalBlue!85] (f_text)
{\scriptsize body force};
\draw[color=RoyalBlue] (f.north) |- (f_text.south east);
\end{tikzpicture}

\vspace{1.5\baselineskip}
\caption{Annotated Navier–Stokes momentum equation.}\label{fig:ns_annotated}
\end{figure}

\begin{figure}[htbp]
\centering
\vspace{2\baselineskip}

\begin{equation*}
\partial_t f + \tikzmarknode{transport}{\colorbox{Bittersweet!20}{$v \cdot \nabla_x f$}}
+ \tikzmarknode{acceleration}{\colorbox{OliveGreen!20}{$\frac{F}{m} \cdot \nabla_v f$}}
=
\tikzmarknode{collision}{\colorbox{RoyalBlue!20}{$C(f)$}}.
\end{equation*}

\begin{tikzpicture}[overlay,remember picture,>=stealth,
nodes={align=left,inner ysep=1pt},<-]
\path (transport.south) ++ (0,-1.0em)
node[anchor=north east,color=Bittersweet!85] (transport_text)
{\scriptsize transport};
\draw[color=Bittersweet] (transport.south) |- (transport_text.north west);

\path (acceleration.south) ++ (0,-1.0em)
node[anchor=north west,color=OliveGreen!85] (acceleration_text)
{\scriptsize acceleration};
\draw[color=OliveGreen] (acceleration.south) |- (acceleration_text.north east);

\path (collision.north) ++ (0,1.0em)
node[anchor=south west,color=RoyalBlue!85] (collision_text)
{\scriptsize collision};
\draw[color=RoyalBlue] (collision.north) |- (collision_text.south east);
\end{tikzpicture}

\vspace{1.5\baselineskip}
\caption{Annotated Boltzmann equation.}\label{fig:boltzmann_annotated}
\end{figure}

\begin{figure}[htbp]
\centering
\vspace{2\baselineskip}

\begin{align*}
& \partial_t f
+
\tikzmarknode{vp_transport}{\colorbox{Bittersweet!20}{$v\cdot\nabla_x f$}}
+
\tikzmarknode{vp_force}{\colorbox{OliveGreen!20}{$E\cdot\nabla_v f$}}
=
0,
\\
& E = -\nabla_x \phi,
\quad
-\Delta_x \phi = \int f\,dv - \rho_0.
\end{align*}

\begin{tikzpicture}[overlay,remember picture,>=stealth,
nodes={align=left,inner ysep=1pt},<-]
% Transport
\path (vp_transport.north) ++ (0,1.0em)
node[anchor=south east,color=Bittersweet!85] (vp_transport_text)
{\scriptsize transport};
\draw[color=Bittersweet] (vp_transport.north) |- (vp_transport_text.south west);

% Force term
\path (vp_force.north) ++ (0,1.0em)
node[anchor=south west,color=OliveGreen!85] (vp_force_text)
{\scriptsize acceleration};
\draw[color=OliveGreen] (vp_force.north) |- (vp_force_text.south east);

\end{tikzpicture}

\vspace{1.5\baselineskip}
\caption{Annotated Vlasov–Poisson equation.}
\end{figure}

\begin{figure}[htbp]
\centering
\vspace{2\baselineskip}

\begin{equation*}
\varepsilon\,
\partial_t I
+
\tikzmarknode{rte_transport}{\colorbox{OliveGreen!20}{$\Omega\, \partial_x I$}}
=
\tikzmarknode{rte_relax}{\colorbox{RoyalBlue!20}{$\frac{\sigma^s}{\varepsilon}(\langle I\rangle - I)$}}
-
\tikzmarknode{rte_absorb}{\colorbox{Orange!40}{$\varepsilon\,\sigma^a I$}}
+
\tikzmarknode{rte_source}{\colorbox{YellowGreen!35}{$\varepsilon\,Q$}}
\, .
\end{equation*}

\begin{tikzpicture}[overlay,remember picture,>=stealth,
nodes={align=left,inner ysep=1pt},<-]
% Transport
\path (rte_transport.south) ++ (0,-1.0em)
node[anchor=north east,color=OliveGreen!85] (rte_transport_text)
{\scriptsize transport};
\draw[color=OliveGreen] (rte_transport.south) |- (rte_transport_text.north west);

% Collision relaxation
\path (rte_relax.north) ++ (0,1.0em)
node[anchor=south east,color=RoyalBlue!85] (rte_relax_text)
{\scriptsize scattering};
\draw[color=RoyalBlue] (rte_relax.north) |- (rte_relax_text.south west);

% Absorption term
\path (rte_absorb.south) ++ (0,-1.0em)
node[anchor=north west,color=Orange!85] (rte_absorb_text)
{\scriptsize absorption};
\draw[color=Orange] (rte_absorb.south) |- (rte_absorb_text.north east);

% Source term
\path (rte_source.north) ++ (0,1.0em)
node[anchor=south west,color=YellowGreen!95] (rte_source_text)
{\scriptsize source term};
\draw[color=YellowGreen] (rte_source.north) |- (rte_source_text.south east);

\end{tikzpicture}

\vspace{1.4\baselineskip}
\caption{Annotated one-dimensional radiative transfer equation in diffusive scaling.}
\end{figure}


\begin{figure}[htbp]
\centering
\vspace{2\baselineskip}

% Scaled TRT equation
\begin{align*}
\frac{\varepsilon}{c}\partial_t I
+
\tikzmarknode{transport}{\colorbox{OliveGreen!20}{$\Omega\cdot\nabla_x I$}}
={} &
\tikzmarknode{relax}{\colorbox{RoyalBlue!20}{$\frac{\sigma^s}{\varepsilon} \left(\frac{\phi}{4\pi}-I\right)$}}
-
\tikzmarknode{abs}{\colorbox{Orange!40}{$\varepsilon\,\sigma^a I$}}
+
\tikzmarknode{emit}{\colorbox{YellowGreen!35}{$\varepsilon\,\sigma^a B(T)$}} .
\\
C_v\,\partial_t T
={} &
\tikzmarknode{couple}{\colorbox{Plum!25}{$\sigma^a(\phi-4\pi B(T))$}} .
\end{align*}

\begin{tikzpicture}[overlay,remember picture,>=stealth,
nodes={align=left,inner ysep=1pt},<-]
% Transport
\path (transport.north) ++ (0,1.0em)
node[anchor=south east,color=Bittersweet!85] (transport_text)
{\scriptsize transport};
\draw[color=Bittersweet] (transport.north) |- (transport_text.south west);
% relaxation
\path (relax.north) ++ (0,1.0em)
node[anchor=south west,color=RoyalBlue!85] (relax_text)
{\scriptsize scattering};
\draw[color=RoyalBlue] (relax.north) |- (relax_text.south east);

% absorption
\path (abs.north) ++ (0,1.0em)
node[anchor=south west,color=Orange!85] (abs_text)
{\scriptsize absorption};
\draw[color=Orange] (abs.north) |- (abs_text.south east);

% emission
\path (emit.north) ++ (0,1.0em)
node[anchor=south west,color=YellowGreen!85] (emit_text)
{\scriptsize material thermal emission};
\draw[color=YellowGreen] (emit.north) |- (emit_text.south east);

% coupling
\path (couple.south) ++ (0,-1.0em)
node[anchor=north west,color=Plum!85] (couple_text)
{\scriptsize radiation--material coupling};
\draw[color=Plum] (couple.south) |- (couple_text.north east);
\end{tikzpicture}

\vspace{1.5\baselineskip}
\caption{Scaled thermal radiative transfer equations in diffusive scaling.}
\end{figure}

\end{document}

tikz-cd 交换图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
T
\arrow[drr, bend left, "x"]
\arrow[ddr, bend right, "y"]
\arrow[dr, dotted, "{(x,y)}" description] & & \\
& X \times_Z Y \arrow[r, "p"] \arrow[d, "q"]
& X \arrow[d, "f"] \\
& Y \arrow[r, "g"]
& Z
\end{tikzcd}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}[row sep=huge, column sep=huge,
every label/.append style={font=\normalsize}]
X_{11} \arrow[d, dashed] \arrow[rr,"{\textsf{ABC}}"] & & X_{21} \arrow[d, dashed] \\
X_{21} \arrow[d,"{\textsf{UVW}}", dashed] \arrow[rr, "{\textsf{DEF}}"] & & X_{22}\arrow[d, dashed] \\
X_{31} \arrow[rr, "{\textsf{XYZ}}", red] & & X_{32}
\end{tikzcd}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}[row sep=huge, column sep=huge,
every label/.append style={font=\normalsize}]
\mathcal{P}{}_h^\varepsilon \arrow[d,"{\scriptstyle\textsf{$h \to 0$}}" swap, dashed] \arrow[r, "{\scriptstyle\textsf{$\varepsilon \to 0$}}"] & \mathcal{P}{}_h^0 \arrow[d,"{\scriptstyle\textsf{$h \to 0$}}", dashed]
\\
\mathcal{P}{}^\varepsilon \arrow[r, "{\scriptstyle\textsf{$\varepsilon \to 0$}}" swap] & \mathcal{P}{}^0
\end{tikzcd}

\end{document}

数据结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
% Nodes
\node[circle, draw] (A) at (0, 0) {A};
\node[circle, draw] (B) at (2, 2) {B};
\node[circle, draw] (C) at (2.3, 0) {C};
\node[circle, draw] (D) at (2, -2) {D};
\node[circle, draw] (F) at (4, 1) {F};
\node[circle, draw] (E) at (4, -1) {E};

% Edges with weights
\draw (A) -- (B) node[midway, above] {9};
\draw (A) -- (C) node[midway, above] {9};
\draw (A) -- (D) node[midway, below left] {7};
\draw (B) -- (C) node[midway, right] {2};
\draw (C) -- (D) node[midway, left] {1};
\draw (B) -- (F) node[midway, above] {9};
\draw (C) -- (E) node[midway, below left] {11};
\draw (D) -- (E) node[midway, below right] {15};
\draw (E) -- (F) node[midway, right] {6};

% Highlight the shortest path
\draw[orange, thick] (A) -- (D);
\draw[orange, thick] (D) -- (C);
\draw[orange, thick] (C) -- (B);
\draw[orange, thick] (B) -- (F);
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1.2]
\node[] (root) at (0,0) {$\{x_1,v_1,x_2,v_2,x_3,v_3\}$};
\node (x1v1x2v2) at (-2,-1) {$\{x_1,v_1,x_2,v_2\}$};
\node (x3v3) at (1.5,-1) {$\{x_3,v_3\}$};

\node (x1v1) at (-3,-2) {$\{x_1,v_1\}$};
\node (x2v2) at (-1,-2) {$\{x_2,v_2\}$};

\node[red] (x1) at (-3.5,-3) {$\{x_1\}$};
\node[red] (v1) at (-2.5,-3) {$\{v_1\}$};
\node[red] (x2) at (-1.5,-3) {$\{x_2\}$};
\node[red] (v2) at (-0.5,-3) {$\{v_2\}$};
\node[red] (x3) at (0.75,-2) {$\{x_3\}$};
\node[red] (v3) at (2.25,-2) {$\{v_3\}$};

\draw[->] (root) -- (x1v1x2v2);
\draw[->] (root) -- (x3v3);
\draw[->] (x1v1x2v2) -- (x1v1);
\draw[->] (x1v1x2v2) -- (x2v2);
\draw[->] (x1v1) -- (x1);
\draw[->] (x1v1) -- (v1);
\draw[->] (x2v2) -- (x2);
\draw[->] (x2v2) -- (v2);
\draw[->] (x3v3) -- (x3);
\draw[->] (x3v3) -- (v3);
\end{tikzpicture}

\end{document}

关于树结构,还可以使用专门的宏包 forest

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
\documentclass[border=2mm]{standalone}
\usepackage{amsmath,amssymb,amsfonts,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\draw[] (-4, -2.5) rectangle (4, 2.5) node[below left] {U};
\draw[] (-1,-.3) circle (2) node[right=2cm] {$V$};
\node[] at (-1.3,0.8) {a};
\node[] at (0.1,0.6) {e};
\node[] at (-1.6,-0.5) {i};
\node[] at (0,-1) {o};
\node[] at (-1,-1.6) {u};
\end{tikzpicture}

\medskip
\begin{tikzpicture}
\draw[] (-4, -2.5) rectangle (4, 2.5) node[below left] {U};
\path[opacity=.3, even odd rule]
(-1,-.3) circle (2)
(1,-.3) circle (2);

\begin{scope}
\clip (-1,-.3) circle (2);
\fill[opacity=.3] (1,-.3) circle (2);
\end{scope}

\draw[] (-1,-.3) circle (2) node[above=2cm] {$A$};
\draw[] (1,-.3) circle (2) node[above=2cm] {$B$};
\end{tikzpicture}

\medskip
\begin{tikzpicture}
\draw[] (-4, -2.5) rectangle (4, 2.5) node[below left] {U};

\begin{scope}
\clip (-1,-.3) circle (2);
\fill[opacity=.3] (1,-.3) circle (2);
\end{scope}

\draw[] (-1,-.3) circle (2) node[above=2cm] {$A$};
\draw[] (1,-.3) circle (2) node[above=2cm] {$B$};
\end{tikzpicture}

\end{document}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
% This file is from Weihao Xia, Jing-Hao Xue. A Survey on 3D-aware Image Synthesis. https://arxiv.org/abs/2210.14267

\documentclass[letterpaper]{article}
\usepackage{tikz}
\usepackage{longtable}
\usepackage{tikz-qtree}
\usepackage[edges]{forest}
\usetikzlibrary{trees}


\begin{document}


\begin{figure}[t!]
\centering
\tikzset{
my node/.style={
font=\small,
rectangle,
draw=#1!75,
align=justify,
}
}
\forestset{
my tree style/.style={
for tree={grow=east,
parent anchor=east, %
child anchor=west,
where level=0{my node=black,text width=1.5em}{},
where level=1{my node=black,text width=8.5em}{},
where level=2{my node=black,text width=8.0em}{},
where level=3{my node=black,text width=15em}{},
l sep=1.5em,
forked edge, %
fork sep=1em, %
edge={draw=black!50, thick},
if n children=3{for children={
if n=2{calign with current}{}}
}{},
tier/.option=level,
}
}
}
\begin{forest}
my tree style
[All
[3D Generative Models from Single Views
[Conditional 3D GANs
[Semantic Label]
[Image]
]
[Unconditional 3D GANs
[Interactive Editing]
[Efficient and Consistent Rendering
]
[Efficient and Effective Representations]
]
]
[3D Novel View Synthesis from Multiple Views
[Constrained $\rightarrow$ In-the-wild
[Static $\rightarrow$ Dynamic]
[Single $\rightarrow$ Large-scale]
[Calibrated $\rightarrow$ Uncalibrated]
[Dense $\rightarrow$ Sparse]
]
[Speed up]
[Neural Scene Representation]
]
[3D Control of 2D Generative Models
[3D Priors as Constraints
[3D Components into 2D GANs]
[3D Prior Knowledge]
]
[3D Parameters as Controls
[Explicit Control over 3D Parameters]
[Control Factors from Pretrained Models]
]
[3D Control Latent Directions
[Unsupervised]
[Supervised]
]
]
]
\end{forest}
\centering
\caption{A systematic taxonomy.}
\label{fig:phylogenetic_tree}
\end{figure}

\end{document}

补充:PDF 转 PNG

提供一个基于 gs 将 PDF 格式的图片转换为 PNG 的脚本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/bash
# 将当前目录下所有 PDF 转成高分辨率 PNG,每页单独输出,保留原文件名

DPI=600

# 遍历当前目录下所有 PDF 文件
for pdf in *.pdf; do
# 去掉扩展名
filename="${pdf%.pdf}"
# 使用 Ghostscript 转 PNG,每页生成一个文件,带页码
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r$DPI -sOutputFile="${filename}-%d.png" "$pdf"
echo "Converted $pdf -> ${filename}-%d.png"
done

echo "All PDFs converted to high-resolution PNG."