3

I want to increase the spacing between the nodes in a stencil, linked to each other by a stroke

\documentclass[a4paper, 12pt]{book}
\usepackage{tikz}
\newcommand{\stencilptbig}[4][]{\node[circle,draw,inner sep=0.1em, outer sep=0pt, minimum size=0.7cm,font=\scriptsize,#1] at (#2) (#3) {#4}}
\begin{document}
\begin{tikzpicture}
\stencilptbig{ -1,0}{i-1}  {$\frac{1}{h^2}+\frac{3}{2h}$};
\stencilptbig{ 0,0}{i}  {$\frac{-2}{h^2}$};
\stencilptbig{ 1,0}{i+1}{$\frac{1}{h^2}-\frac{3}{2h}$};
\draw
(i-1)   -- (i)
(i)   -- (i+1);
\end{tikzpicture}
\end{document}

enter image description here

ecjb
  • 883
  • 1
    The first (non optional) argument of \stencilptbig is the node position. Change -1,0 to -2,0 and 1,0 to 2,0. Or you can scale down the nodes (for example with using scale=.5). – Kpym Dec 31 '18 at 14:48

1 Answers1

6

Kpym already gave you a nice solution for your problem. I am writing this answer in order to persuade you to use a different syntax. Rather than defining a new command, you may just define a node style, and use positioning for relative positioning. (If you have many of these nodes, you may want look into chains, but here it would be a bit of an overkill IMHO.)

\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-1)  {$\frac{1}{h^2}+\frac{3}{2h}$};
\node[stencilptbig,right=of i-1] (i) {$\frac{-2}{h^2}$};
\node[stencilptbig,right=of i] (i+1){$\frac{1}{h^2}-\frac{3}{2h}$};
\draw (i-1)   -- (i) (i)   -- (i+1);
\end{tikzpicture}
\end{document}

enter image description here

If you want to change the gaps, just adjust node distance.