Tikz - 增加模板两个节点之间的间距

Tikz - 增加模板两个节点之间的间距

我想增加模板两个节点之间的间距。模板的原始设计来自此问题

模版

\documentclass[a4paper, 12pt]{book}
\usepackage{pgfplots, tikz}

\newcommand{\stencilptbig}[4][]{\node[circle,draw,inner sep=0.1em, outer sep=0pt, minimum size=0.7cm,font=\normalfont,#1] at (#2) (#3) {#4}}
\begin{document}

\begin{center}
    \begin{tikzpicture}
    \stencilptbig {-1,1}    {i-1}   {$\frac{-1}{h^2_t}$};
    \stencilptbig {0,1}     {i}     {$\frac{-2}{h^2_t}+\frac{2}{h^2_x}$};
    \stencilptbig {0,0}     {ij-1}      {$\frac{1}{h^2_t}$};
    \stencilptbig {0,2}     {ij+1}      {$\frac{1}{h^2_t}$};    
    \stencilptbig {1,1}     {i+1}   {$\frac{-1}{h^2_t}$};
    \draw
    (i-1)   --  (i) 
    (i)     --  (i+1)
    (i)     --  (ij-1)
    (i)     --  (ij+1);
    \end{tikzpicture}
\end{center}
\end{document}

我也尝试\newcommand{\stencilptbig}[4][]{\node[circle,draw,inner sep=0.1em, outer sep=0pt, minimum size=0.7cm,font=\normalfont,#1, node distance=2cm] at (#2) (#3) {#4}}问题但它没有起作用

顺便说一句:如果有更简单的方法来绘制整个东西,请告知。

答案1

与以下评论相同我之前的回答在这里申请。;-)

\documentclass[a4paper, 12pt]{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[stencilptbig/.style={circle,draw,inner sep=0.1em, outer
sep=0pt, minimum size=0.7cm,font=\scriptsize},
node distance=2mm]
\node[stencilptbig] (i) {$\frac{-2}{h^2_t}+\frac{2}{h^2_x}$};
\node[stencilptbig,left=of i] (i-1)  {$\frac{-1}{h^2_t}$};
\node[stencilptbig,right=of i] (i+1)  {$\frac{-1}{h^2_t}$};
\node[stencilptbig,above=of i] (ij+1)  {$\frac{1}{h^2_t}$};
\node[stencilptbig,below=of i] (ij-1)  {$\frac{1}{h^2_t}$};
\draw
    (i-1)   --  (i) 
    (i)     --  (i+1)
    (i)     --  (ij-1)
    (i)     --  (ij+1);
\end{tikzpicture}
\end{document}

在此处输入图片描述

你也可以用

\draw (i) edge   (i-1)  edge  (i+1) edge  (ij-1) edge  (ij+1);

根据你最终真正想要实现的目标,你可能想要使用chains或其他技巧。而且几乎可以肯定有人会想在这里使用矩阵。我想只有在清楚了解全貌后才能决定什么是最优雅的。

相关内容