4

I want to increase the spacing between 2 nodes of a stencil. The original design of the stencil comes from this question.

stencil

\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}

I also tried \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}} according to that question but it didn't work

By the way: If there is an easier way to draw the whole thing, please let know.

ecjb
  • 883

1 Answers1

9

Same comments as in my previous answer apply here. ;-)

\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}

enter image description here

You may also draw the lines with

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

Depending on what you really want to achieve in the end, you may want to use chains or other tricks. And almost certainly someone will want use a matrix here. I guess that what is most elegant can only decided when it is clear what the full picture is.