使用 TikZ 将文本添加到旋转链

使用 TikZ 将文本添加到旋转链

我想将文本添加到旋转链中。

这是我做的:

\begin{tikzpicture}
    \draw[-] (5,0) -- (0,0) node[left]{$a)$};
    % \draw[-stealth] (0,-.25) -- (0,.25);
    \draw[](.5, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (.5,-.25) -- (.5,.25);
    \draw[](1, 0) circle(.08);
    \draw[-stealth, red, line width= 0.5mm] (1,.25) -- (1,-.25);
    \draw[](1.5, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (1.5,-.25) -- (1.5,.25);
    \draw[](2, 0) circle(.08);
    \draw[-stealth, red, line width= 0.5mm] (2,.25) -- (2,-.25);
    \draw[](2.5, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (2.5,-.25) -- (2.5,.25);
    \draw[](3, 0) circle(.08);
    % \draw[-stealth, red, line width= 0.5mm] (3,.25) -- (3,-.25);
    \draw[](3.5, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (3.5,-.25) -- (3.5,.25);
    \draw[](4, 0) circle(.08);
    \draw[-stealth, red, line width= 0.5mm] (4,.25) -- (4,-.25);
    \draw[](4.5, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (4.5,-.25) -- (4.5,.25);
    
    \begin{scope}[yshift = -1cm]
    \draw[-] (5,0) -- (0,0) node[left]{$b)$};
    
    \draw[](.5, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (.5,-.25) -- (.5,.25);
    
    \draw[](1, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (1,-.25) -- (1,.25);
    
    \draw[](1.5, 0) circle(.08);
    \draw[-stealth, red, line width= 0.5mm] (1.5,.25) -- (1.5,-.25);
    
    \draw[](2, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (2,-.25) -- (2,.25);
    
    \draw[](2.5, 0) circle(.08);
    \draw[-stealth, red, line width= 0.5mm] (2.5,.25) -- (2.5,-.25);
    
    \draw[](3, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (3,-.25) -- (3,.25);
    
    \draw[](3.5, 0) circle(.08);
    \draw[-stealth, red, line width= 0.5mm] (3.5,.25) -- (3.5,-.25);
    
    \draw[](4, 0) circle(.08);
    \draw[-stealth, blue, line width= 0.5mm] (4,-.25) -- (4,.25);
    
    \draw[](4.5, 0) circle(.08);
    % \draw[-stealth, blue, line width= 0.5mm] (4.5,-.25) -- (4.5,.25);
    \end{scope}
    
\end{tikzpicture}

我想要添加的文本如下: 在此处输入图片描述

我该怎么做?谢谢!

答案1

为什么要受苦呢?我建议你使用 LaTeX 使用宏的主要功能。我定义了三个宏,分别用于向上、向下和绿色圆圈的箭头。这些宏被认为是以相同的路径向右逐步绘制元素。

然后我在行上标记“有趣”的点,并用coordinates 命名它们,并添加相关文本。我对代码进行了大量注释以解释它。

\documentclass[border=3.14]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\newcommand{\arrUP}{%
    % continue the line moving 0.5 right.
    -- ++(0.5,0) circle[radius=0.05]
    % using an edge here, because you can't change color or arrow
    % only in parts of a path. The edges are drawn  last, so they
    % will overwrite the circles
    ++(0,-0.5) edge[red, -Stealth, line width=0.5mm] ++(0,1)
    % edges do not move to the final point, so go back to the main line
    ++(0,0.5)
}
\newcommand{\arrDN}{%
    -- ++(0.5,0) circle[radius=0.05]
    ++(0,-0.5) edge[blue, Stealth-, line width=0.5mm] ++(0,1)
    ++(0,0.5)
}
\newcommand{\holo}{%
    % nodes are drawn after the path, but before edges. So this will
    % overwrite the main line (try removing the fill!)
    -- ++(0.5,0) node[circle, draw=green, thick, inner sep=1mm, fill=white]{}
}
\begin{document}
\begin{tikzpicture}[]
    \draw (0,0) \arrUP \arrDN \arrUP \holo coordinate(holo1)
        \arrUP \arrDN \arrUP \arrDN \arrUP \arrDN \arrUP \arrDN
        \arrUP coordinate(sp1) \arrUP coordinate(sp2)
        ;
    \draw [thin] (holo1) ++(0,-0.4) to[bend right] ++(0.5,-0.3) 
        node[right]{electron removed};
    \draw [thin] ([yshift=-0.6cm]sp1) to[bend right]
        node[midway, below]{spinon} ([yshift=-0.6cm]sp2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

正如 Rmano 所建议的,最好使用宏来完成。这是另一种方法,使用绘制链条的宏。

\documentclass[border=2mm]{standalone}
\usepackage    {tikz}
\usetikzlibrary{calc}

\newcommand{\spinchain}[3]% position, label, electrons
{%
  \begin{scope}[shift={#1},scale=0.5]
    \node at (0,0) {#2)};
    \foreach[count=\j]\i in {#3}
    {% counting the number of electrons
      \global\let\jj=\j % remember the last \j 
    }
    \draw (0.5,0) -- (\jj+0.5,0);
    \foreach[count=\j]\i in {#3}
    {%
      \coordinate (#2\j) at (\j,-1);
      \ifnum\i = 1
        \fill (\j,0) circle (0.12);
        \draw[-stealth,red,line width= 0.5mm] (\j,-0.5) --++ (0,1);
      \else\ifnum\i = -1
        \fill (\j,0) circle (0.12);
        \draw[-stealth,blue,line width= 0.5mm] (\j,0.5) --++ (0,-1);
      \else
        \draw[thick,green,fill=white] (\j,0) circle (0.16);
     \fi\fi
    }
  \end{scope}
}

\begin{document}
\begin{tikzpicture}
  \spinchain{(0,2)}{a}{1,-1,1,0,1,-1,1,-1,1,-1,1,-1,1,-1}
  \spinchain{(0,0)}{b}{1,-1,1,1,-1,1,-1,1,-1,0,1,-1,1,-1}
  \draw (a4) to [bend right] ($(a6)-(0,0.5)$) node [right] {\strut electron removed};
  \draw (b3) to [bend right] node [midway,below] {\strut spinon} (b4);
  \draw ($(b9)!0.5!(b10)$) to [bend right] node [midway,below] {\strut holon} ($(b10)!0.5!(b11)$) ;
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容