使用\pgfmathsetmacro,定义的实数在tikz的绘图环境中可以很方便的进行四则运算:
看下面的例子:
%传热学图4-3 \begin{tikzpicture}[>=stealth,line width=0.5pt] \useasboundingbox(0,-0.4)rectangle(5.25,5); \coordinate (P)at (2.5,2.5); %%题注 \path (P)+(-0.8,-2.5) coordinate[label=0:{图$4-3$}]; %%画花括号: \draw (P)+(0.5,+2.1) node[yscale=1,xscale=2.6,rotate=-90]{\{} ; \draw (P)+(0.5,+2.1) coordinate[label=above:{\scriptsize $ \Delta x$}] ; \draw (P)+(2.1,-0.5) node[yscale=2.6,xscale=1]{\}} ; \draw (P)+(2.1,-0.5) coordinate[label=right:{\scriptsize $ \Delta y$}] ; % \clip[draw] (P) circle (2.0); \foreach \i in {0.5,1.5,...,4.5}{ \draw(\i,0)--(\i,5); } \foreach \i in {0.5,1.5,...,4.5}{ \draw(0,\i)--(5,\i); } %矩形四个顶点坐标点 %绘制节点 \foreach \i in {0.5,1.5,...,4.5}{ \foreach \j in {0.5,1.5,...,4.5}{ \draw[fill](\i,\j)circle(0.75pt); } } \pgfmathsetmacro{\a}{0.1} \pgfmathsetmacro{\s}{0.5} % \draw[fill=blue] (P) circle (2pt); \draw[fill=red] (P)+(1,0) circle (2pt); \draw[fill=red] (P)+(-1,0) circle (2pt); \draw[fill=red] (P)+(0,1) circle (2pt); \draw[fill=red] (P)+(0,-1) circle (2pt); \path (P)+(0,-0.25 ) node[blue,scale=1](mn){$(m\text{,}n)$}; \path (P)+(-0.65,\a ) node[scale=\s](w){$w$}; \path (P)+(\a,-0.65 ) node[scale=\s](s){$s$}; \path (P)+(+0.65,\a ) node[scale=\s](e){$e$}; \path (P)+(\a,+0.65 ) node[scale=\s](n){$n$}; % \pgfmathsetmacro{\b}{0.5} \pgfmathsetmacro{\c}{0.2} \path (P)+(\b,1+\c ) node[scale=\s](mn1){$(m\text{,}n+1)$}; \path (P)+(\b,-1-\c ) node[scale=\s](mn2){$(m\text{,}n-1)$}; \path (P)+(-1-\b,\c ) node[scale=\s](mn3){$(m-1\text{,}n)$}; \path (P)+(+1+\b,\c ) node[scale=\s](mn4){$(m+1\text{,}n)$}; %xelatex不支持pattern模式 \draw[dashed,pattern=north east lines] (2.0,2.0) rectangle (3.0,3.0); \end{tikzpicture}上面的例子使用pdflatex编译两次即可.图形如下: