我如何才能得到这样的图表,但在网格中间没有 H 和 O?

我如何才能得到这样的图表,但在网格中间没有 H 和 O?

这是我想要得到的图片,

下面的代码

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[inner sep = 1pt, outer sep = 3pt,
  help grid/.style={blue!30},
  bond/.style={thick, black},
  hbond/.style={thick, red, decorate, decoration = {snake, amplitude = 1pt, segment length = 5pt}}]

  % Atoms
  \foreach \y in {1, 3, ..., 9} {
    \foreach \x in {1, 3, ..., 11} {
      \node (Hodd\x-\y) at (\x, \y){$H$};
    }
    \foreach \x in {2, 4, ..., 10} {
      \node (O\x-\y) at (\x, \y){$O$};
    }
  }

  \foreach \y in {2, 4, ..., 8} {
    \foreach \x in {2, 4, ..., 10} {
      \node (Heven\x-\y) at (\x, \y){$H$};
    }
  }

  % Frame + grid
  \foreach \x in {0.5, ..., 11.5}  \draw[help grid] (\x, 0.5) -- (\x, 9.5);
  \foreach \y in {0.5, ..., 9.5}  \draw[help grid] (0.5, \y) -- (11.5, \y);

  % bonds
  \draw[bond] (Hodd1-9) -- (O2-9);
  \draw[bond] (Hodd3-9) -- (O4-9);
  \draw[bond] (Hodd5-9) -- (O4-9);
  \draw[bond] (Hodd7-9) -- (O6-9);
  \draw[bond] (Hodd9-9) -- (O8-9);
  \draw[bond] (Hodd11-9) -- (O10-9);
  \draw[bond] (Hodd1-7) -- (O2-7);
  \draw[bond] (Heven2-8) -- (O2-9);
  \draw[bond] (Hodd3-7) -- (O2-7);
  \draw[bond] (Heven4-8) -- (O4-7);
  \draw[bond] (Heven4-6) -- (O4-7);
  \draw[bond] (Heven6-8) -- (O6-9);
  \draw[bond] (Heven8-8) -- (O8-9);
  \draw[bond] (Heven10-8) -- (O10-9);
  \draw[bond] (Hodd5-7) -- (O6-7);
  \draw[bond] (Hodd7-7) -- (O6-7);
  \draw[bond] (Hodd9-7) -- (O8-7);
  \draw[bond] (Heven8-6) -- (O8-7);
  \draw[bond] (Hodd11-7) -- (O10-7);
  \draw[bond] (Heven10-6) -- (O10-7);

  \draw[bond] (Heven10-4) -- (O10-5);
  \draw[bond] (Hodd11-5) -- (O10-5);
  \draw[bond] (Hodd9-5) -- (O8-5);
  \draw[bond] (Hodd7-5) -- (O8-5);
  \draw[bond] (Heven6-6) -- (O6-5);
  \draw[bond] (Hodd5-5) -- (O6-5);
  \draw[bond] (Heven4-4) -- (O4-5);
  \draw[bond] (Hodd3-5) -- (O4-5);
  \draw[bond] (Heven2-6) -- (O2-5);
  \draw[bond] (Hodd1-5) -- (O2-5);
  \draw[bond] (Hodd11-3) -- (O10-3);
  \draw[bond] (Hodd9-3) -- (O10-3);
  \draw[bond] (Heven8-4) -- (O8-3);
  \draw[bond] (Hodd7-3) -- (O8-3);
  \draw[bond] (Heven6-4) -- (O6-3);
  \draw[bond] (Heven6-2) -- (O6-3);
  \draw[bond] (Hodd5-3) -- (O4-3);
  \draw[bond] (Hodd3-3) -- (O4-3);
  \draw[bond] (Hodd1-3) -- (O2-3);
  \draw[bond] (Heven2-4) -- (O2-3);
  \draw[bond] (Heven10-2) -- (O10-1);
  \draw[bond] (Heven8-2) -- (O8-1);
  \draw[bond] (Heven2-2) -- (O2-1);
  \draw[bond] (Heven4-2) -- (O4-1);
  \draw[bond] (Heven2-2) -- (O2-1);
  \draw[bond] (Hodd11-1) -- (O10-1);
  \draw[bond] (Hodd9-1) -- (O8-1);
  \draw[bond] (Hodd7-1) -- (O6-1);
  \draw[bond] (Hodd5-1) -- (O6-1);
  \draw[bond] (Hodd3-1) -- (O4-1);
  \draw[bond] (Hodd1-1) -- (O2-1);
\end{tikzpicture}

\end{document}

生产

在此处输入图片描述

答案1

以下示例修改了 Zarko 的第一个答案版本使其在化学上更加合理(第二个版本修复了这些问题):

  • 水分子 H 2 O 由两个氢原子和一个氧原子组成。氢不能同时与两个氧原子真正结合。但是,氢可以形成氢结合例如,水中部分带正电的氢与部分带负电的氧之间存在静电吸引力。这些吸引力以虚线标记。

  • 最后一列被移除,以使电荷平衡。否则,顶行和底行将各带有正电荷。

  • 水分子中两个键之间的角度是 104.5°,而不是 90°。但是,由于“网格布局”,我保留了它不变。

完整示例:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
  \begin{tikzpicture}[
    L/.style={% L as link between atoms ?
      shorten <=2mm,
      shorten >=2mm,
      semithick,
    },
    HydrogenBond/.style={
      L,
      densely dashed,
    },
  ]
    \matrix (m) [
      matrix of nodes,
      nodes in empty cells,
      nodes={draw=blue!30, thin, minimum size=7mm, anchor=south},
      column sep=-\pgflinewidth,
      row sep=-\pgflinewidth,
    ]
    {
        & H &   & H &   & H &   & H &   & H \\
      H & O & H & O & H & O & H & O & H & O \\
        &   &   &   &   &   &   &   &   &   \\
        &   &   &   &   &   &   &   &   &   \\
        &   &   &   &   &   &   &   &   &   \\
        &   &   &   &   &   &   &   &   &   \\
        &   &   &   &   &   &   &   &   &   \\
        &   &   &   &   &   &   &   &   &   \\
        &   &   &   &   &   &   &   &   &   \\
      H & O & H & O & H & O & H & O & H & O \\
        & H &   & H &   & H &   & H &   & H \\
    };
    \foreach \i in {2,4,...,10}
    {
      \draw[L] (m-1-\i.center)  -- (m-2-\i.center);
      \draw[L] (m-10-\i.center) -- (m-11-\i.center);
    }
    \foreach \i in {2,4,...,10}
    {
      \pgfmathsetmacro{\ii}{int(\i-1)}
      \draw[L] (m-2-\ii.center)  -- (m-2-\i.center);
      \draw[L] (m-10-\ii.center) -- (m-10-\i.center);
    }
    \foreach \i in {3,5,...,9}
    {
      \pgfmathsetmacro{\ii}{int(\i-1)}
      \draw[HydrogenBond] (m-2-\ii.center)  -- (m-2-\i.center);
      \draw[HydrogenBond] (m-10-\ii.center) -- (m-10-\i.center);
    }
  \end{tikzpicture}
\end{document}

结果

答案2

像这样?

在此处输入图片描述

(我不确定前两列和后两列是否也具有原子模式,如果有,那么如何组织)。

使用tikzmatrix代码相对简单:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}
    \begin{tikzpicture}[
L/.style = {% L as link between atoms ?
    shorten <=2mm, shorten >=2mm, semithick}
                        ]
\matrix (m) [matrix of nodes,
             nodes in empty cells,
             nodes={draw=blue!30, thin, minimum size=7mm, anchor=south},
             column sep=-\pgflinewidth,
             row sep=-\pgflinewidth
             ]
{
    &   H   &       &   H   &       &   H   &       &   H   &       &   H   &       \\
H   &   O   &   H   &   O   &   H   &   O   &   H   &   O   &   H   &   O   &   H   \\
    &       &       &       &       &       &       &       &       &       &       \\
    &       &       &       &       &       &       &       &       &       &       \\
    &       &       &       &       &       &       &       &       &       &       \\
    &       &       &       &       &       &       &       &       &       &       \\
    &       &       &       &       &       &       &       &       &       &       \\
    &       &       &       &       &       &       &       &       &       &       \\
    &       &       &       &       &       &       &       &       &       &       \\
H   &   O   &   H   &   O   &   H   &   O   &   H   &   O   &   H   &   O   &   H   \\
    &   H   &       &   H   &       &   H   &       &   H   &       &   H   &       \\
};
\foreach \i in {2,4,...,8}
{
\draw[L] (m-1-\i.center)  -- (m-2-\i.center);
\draw[L] (m-10-\i.center) -- (m-11-\i.center);
\pgfmathsetmacro{\ii}{int(\i-1)}
\draw[L] (m-2-\ii.center)  -- (m-2-\i.center);
\draw[L] (m-10-\ii.center) -- (m-10-\i.center);
}
\draw[L] (m-1-9.center)  -- (m-2-9.center);
\draw[L] (m-2-9.center)  -- (m-3-9.center);
\draw[L] (m-1-10.center) -- (m-2-10.center);
\draw[L] (m-2-10.center) -- (m-2-11.center);
%
\draw[L] (m-9-9.center)  -- (m-10-9.center);
\draw[L] (m-10-9.center) -- (m-11-9.center);
\draw[L] (m-10-10.center) -- (m-11-10.center);
\draw[L] (m-10-10.center) -- (m-10-11.center);
    \end{tikzpicture}
\end{document}

对于第一列和最后两列的原子模式来说,这个代码的扩展并不困难。

相关内容