答案1
可以设计出一种更为复杂的方法,但如果没有更多关于你想要的东西的细节,那么就没有太多的动力。
\documentclass[tikz]{standalone}
\newcommand{\stencilpt}[4][]{\node[circle,draw,inner sep=0.1em,minimum size=0.8cm,font=\tiny,#1] at (#2) (#3) {#4}}
\begin{document}
\begin{tikzpicture}
\stencilpt{-2,0}{i-2}{$-1/12$};
\stencilpt{-1,0}{i-1}{$4/3$};
\stencilpt{ 0,0}{i} {$-5$};
\stencilpt{ 1,0}{i+1}{$4/3$};
\stencilpt{ 2,0}{i+2}{$-1/12$};
\stencilpt{0,-2}{j-2}{$-1/12$};
\stencilpt{0,-1}{j-1}{$4/3$};
\stencilpt[blue]{0, 1}{j+1}{$4/3$};
\stencilpt{0, 2}{j+2}{$-1/12$};
\draw (j-2) -- (j-1)
(j-1) -- (i)
(i) -- (j+1)
(j+1) -- (j+2)
(i-2) -- (i-1)
(i-1) -- (i)
(i) -- (i+1)
(i+1) -- (i+2);
\end{tikzpicture}
\end{document}
如蓝色节点所示,每个节点的任何额外样式代码都有一个可选参数。如您所见,带圆圈的数字工作正常,但当我们开始涉及分数时,它们开始变得笨拙(太大)。例如
\documentclass[tikz]{standalone}
\tikzset{every label/.style={font=\footnotesize,inner sep=1pt}}
\newcommand{\stencilpt}[4][]{\node[circle,fill,draw,inner sep=1.5pt,label={above left:#4},#1] at (#2) (#3) {}}
\begin{document}
\begin{tikzpicture}
\stencilpt{-2,0}{i-2}{$-1/12$};
\stencilpt{-1,0}{i-1}{$4/3$};
\stencilpt{ 0,0}{i} {$-5$};
\stencilpt{ 1,0}{i+1}{$4/3$};
\stencilpt{ 2,0}{i+2}{$-1/12$};
\stencilpt{0,-2}{j-2}{$-1/12$};
\stencilpt{0,-1}{j-1}{$4/3$};
\stencilpt[blue]{0, 1}{j+1}{$4/3$};
\stencilpt{0, 2}{j+2}{$-1/12$};
\draw (j-2) -- (j-1)
(j-1) -- (i)
(i) -- (j+1)
(j+1) -- (j+2)
(i-2) -- (i-1)
(i-1) -- (i)
(i) -- (i+1)
(i+1) -- (i+2);
\end{tikzpicture}
\end{document}
(刚刚改变了\newcommand
并添加了\tikzset
行)当涉及分数/较大的数字时可能会产生更好的结果: