修改 TikZ 锯齿形装饰

修改 TikZ 锯齿形装饰

我正在尝试使用 tikz 获得以下方程,

在此处输入图片描述

我使用以下代码

\begin{align*}
e(nm)=&1+f(nm) \\
\begin{tikzpicture}
\node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (0,0) {};
\node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (0.75,0)  {};
\draw[decorate,decoration={zigzag,segment length=1mm, amplitude=.5mm},thick] (A) -- (B);
\end{tikzpicture}=&\begin{tikzpicture}
\node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (0,0) {};
\node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (0.75,0)  {};
\draw[thick,white] (A) -- (B);
\end{tikzpicture} + \begin{tikzpicture}
\node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (0,0) {};
\node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (0.75,0)  {};
\draw[thick] (A) -- (B);
\end{tikzpicture}
\end{align*}

但是,连接圆圈的锯齿形并不像第一张图片中那样相等。我不知道如何修改锯齿形装饰以获得所需的输出

在此处输入图片描述

答案1

您可以使用 TiZ 的\matrix

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{matrix}
\begin{document}
\begin{center}
\begin{tikzpicture}
  \matrix (mymatrix) [matrix of math nodes] {
    e(nm) & = & 1 & + & f(nm)\\
    \node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (-.375,.075) {};
    \node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (.375,.075)  {};
    \draw[decorate,decoration={zigzag,segment length=1mm, amplitude=.5mm},thick] (A) -- (B);
    & = &
    \node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (-.375,.075) {};
    \node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (.375,.075)  {};
    \draw[thick,white] (A) -- (B); 
    & + &
    \node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (-.375,.075) {};
    \node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (.375,.075)  {};
    \draw[thick] (A) -- (B);
    \\
  };
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

使之字形稍微更美好

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{matrix}
\begin{document}
\begin{center}
\begin{tikzpicture}
  \matrix (mymatrix) [matrix of math nodes] {
    e(nm) & = & 1 & + & f(nm)\\
    \node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (-.375,.075) {};
    \node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (.375,.075)  {};
    \draw[decorate,decoration={zigzag,segment length=1mm, amplitude=1mm/(2*sqrt(2))},thick] (A) -- (B);
    & = &
    \node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (-.375,.075) {};
    \node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (.375,.075)  {};
    \draw[thick,white] (A) -- (B); 
    & + &
    \node[circle,fill=black!30!white,draw, minimum size=0.15cm] (A) at  (-.375,.075) {};
    \node[circle,fill=black!30!white, draw, minimum size=0.15cm] (B) at  (.375,.075)  {};
    \draw[thick] (A) -- (B);
    \\
  };
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

答案2

@Fractal 答案的一个小变化(+1):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing,
                matrix}

\begin{document}
\begin{center}
    \begin{tikzpicture}[
  C/.style = {circle, draw, thin, fill=gray, minimum size=4mm, anchor=center,
              inner sep=0pt, outer sep=0pt, node contents={} },
decoration = {zigzag, segment length=2mm, amplitude=1.414mm}
                   ]
\coordinate (s) at (1.5pt,0.5ex); 
\matrix (m) [matrix of math nodes,
             every odd column/.style={nodes={minimum width=14mm, minimum height=5ex}}
             ] 
{
e(nm)   & = & 1 & + &   f(nm)\\
\draw[decorate, thick] (s) node[C,left] -- ++ (0.6,0) node[C,right];
        & = &   \path (s) node[C,left] ++ (0.6,0) node[C,right];
                & + &   \draw[thick] (s) node[C,left] -- ++ (0.6,0) node[C,right];\\
  };
    \end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

相关内容