使用 LaTeX 绘制格子图

使用 LaTeX 绘制格子图

我怎样才能用 LaTeX 绘制这两种方案?

答案1

作为其他图像的起点:

在此处输入图片描述

\documentclass[border=3mm,tikz]{standalone}
    \usetikzlibrary{arrows.meta,
                    bending,
                    calc,chains,
                    shapes.misc,
% added for compatibility with babel ...
                    babel
                    }
    \usepackage{mathtools}

\begin{document}
    \begin{tikzpicture}[
    node distance = 0pt,
shorten <>/.style = {shorten <=#1, shorten >=#1},
start chain = going right,
  box/.style = {shape=rectangle, draw, fill=#1,
                minimum width=6mm, minimum height=9mm, outer sep=0pt,
                node contents={},
                on chain},
box/.default = none,
arrow/.style = {draw=blue!60!black, thick, shorten <>=1mm, 
                out=90, in=90, looseness=3,
                -{Straight Barb[bend]}},
arbox/.style = {inner sep=0pt, minimum size=5pt},
crbox/.style = {inner sep=0pt,
                node contents={\scriptsize\color{red}$\boldsymbol{\times}$}
                },
    label distance = -3pt,
   sx/.style = {xshift=#1pt}
                        ]
\node (n0) [box,dashed];
\foreach \i in {1,2,...,13}
    \ifnum\i<6
        \node (n\i) [box]
    \else
        \node (n\i) [box=gray!25]
    \fi;
\node (n14) [box,dashed];
    \draw[very thick,shorten <>=-2mm]  (n5.north east)  --  (n5.south east);
    \draw[ultra thick,dotted,shorten <=1mm]  (n0)  -- + (-9mm,0mm);
    \draw[ultra thick,dotted,shorten <=1mm]  (n14) -- + (+9mm,0mm);
\fill[black!75]  (n1)  circle (1mm)  (n2)  circle (1mm)   (n6) circle (1mm)
                (n10) circle (1mm)  (n12) circle (1mm)
                ($(n13)+(0,1.3)$)  circle (1mm);
% arrows
\draw[arrow]    ([sx=-1] n1.north) to node[arbox,label=above:$\delta$] {} (n0.north);
\draw[arrow]    ([sx= 1] n1.north) to node[crbox,label=above:$\delta$] {} (n2.north);
%
\draw[arrow]    ([sx=-1] n6.north) to node[crbox] {} (n5.north);
\draw[arrow]    ([sx= 1] n6.north) to node[arbox] {} (n7.north);
%
\draw[arrow]    ([sx=-1] n10.north) to node[arbox,label=above:$\delta$] {} (n9.north);
\draw[arrow]    ([sx= 1] n10.north) to node[arbox] {} (n11.north);
%
\draw[->]    (n12.north) -- + (0,0.7) node[ left] {$\omega_{\mathrm{off}}$};
\draw[<-]    (n13.north) -- + (0,0.7) node[right] {$\omega_{\mathrm{on}}$};
% x axe
\draw[->]    ($(n1.south west)+(0,-1)$) coordinate (a) 
                        -- (a -| n13.east) node[right] {$x$};
\draw   ($(a -| n5)+(0,1mm)$) node[above] {$s-1$} -- + (0,-2mm) node[below] {$-\varepsilon$}
        ($(a -| n6)+(0,1mm)$) node[above] {$s$}   -- + (0,-2mm) node[below] {$0$}
        ($(a -| n7)+(0,1mm)$) node[above] {$s+1$} -- + (0,-2mm) node[below] {$\varepsilon$};
    \end{tikzpicture}
\end{document}

答案2

这是第一个问题的开头。如果你什么都没有,就从这里开始,然后如果你遇到困难,就发布一个更具体的问题。

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{matrix}
\tikzset{
  my tape/.style={
    matrix of nodes, nodes={minimum height=3ex, font=\sffamily, inner sep=0pt, anchor=center, minimum width=3ex, text centered, #1}, nodes in empty cells
  },
  my tape end/.style={
    draw=none, inner xsep=2.5pt
  }
}
\begin{document}
\begin{tikzpicture}
  \matrix (tape 1) [my tape={draw=gray, very thin}]
  {
    |[my tape end]|\dots&\textbullet&\textbullet&&&\textbullet&&\textbullet&|[my tape end]|\dots\\
  };
  \draw [thick] ([xshift=-2.5pt]tape 1-1-2.north west) -- ([xshift=2.5pt]tape 1-1-8.north east);
  \draw [thick] ([xshift=-2.5pt]tape 1-1-2.south west) -- ([xshift=2.5pt]tape 1-1-8.south east);
\end{tikzpicture}
\end{document}

行情纸带

在矩阵中,我们可以使用 来启动一个单元格|...|,并将...添加到创建节点的命令中。例如,添加|[fill=gray]|到单元格会产生

填充细胞

在矩阵之后,我们可以通过节点名称来引用矩阵中的单元。这些节点名称由

<name of matrix>-<row>-<column>

因此,由于矩阵tape 1在上面的例子中被命名,

  • tape 1-1-1指的是第一个单元格(带有点);
  • tape 1-1-2指的是第二个单元格;

    ...

  • tape 1-1-9指的是最后一个单元格(与其他点一起)。

与往常一样,这些节点有锚点,这些锚点在上面的代码中用于绘制行情纸带上方和下方的粗线。

这也可用于添加所需的注释和箭头。例如,

  \draw [<-] ([yshift=2.5pt]tape 1-1-8.north)  -- ++(0,10pt) node [pos=.75, right, text=blue!25!gray] {$w_{on}$} node [yshift=2.5pt] {\textbullet} ;

注释单元格

可以以相同的方式添加箭头等,使用 TikZ 提供的常用路径规范选项。

相关内容