方格的 Kasteleyn 取向

方格的 Kasteleyn 取向

我一直在尝试绘制4 by 4方格的 Kasteleyn 方向。我的目标是绘制一个如下图所示的图形(给出6 by 4)。在此处输入图片描述

我编写的代码如下所示。

\documentclass{article}
\usepackage{calligra}
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{marginnote}
\geometry{a4paper,total={170mm,257mm},left=10mm,right=15mm,top=15mm,bottom=15mm}
\usepackage{ulem}
\usepackage{simpler-wick}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{amssymb}
\usepackage{bbold}
\usepackage{empheq}
\usepackage{lscape}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{relsize}
\usepackage{cjhebrew}
\usepackage{amsfonts}
\usepackage{esvect}
\usepackage{esint}
\usepackage{braket}
\usepackage{mathrsfs}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[compat=1.0.0]{tikz-feynman}
\usetikzlibrary{arrows,decorations.markings}
\usepackage[autostyle]{csquotes}
\usepackage{siunitx}
%----------------------------------------Frame--------------
\usepackage{framed} % or, "mdframed"
\usepackage[framed]{ntheorem}
\newframedtheorem{frm-thm}{Theorem}
%----------------------------------------------------------
\usepackage{marvosym}
%--------------------------------------------------------------
\usepackage{scalerel,amssymb}
\def\mcirc{\mathbin{\scalerel*{\circ}{j}}}
\def\msquare{\mathord{\scalerel*{\Box}{gX}}}
%--------------------------------------------------------------

\newcommand*\widefbox[1]{\fbox{\hspace{2em}#1\hspace{2em}}}
\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand{\ba}{\begin{eqnarray}}
\newcommand{\ea}{\end{eqnarray}}
\newcommand{\tr}{\mathrm{Tr}}
\newcommand{\D}{\int\mathcal{D}}
\newcommand{\bigzero}{\mbox{\normalfont\Large\bfseries 0}}
\newcommand{\mc}{\mathcal}
\newcommand{\vn}{\beta|\varepsilon_{n_{2}}|^{2/3}}
\newcommand{\vm}{\beta|\varepsilon_{m_{2}}|^{2/3}}
\newcommand{\cl}{\calligra}
\tikzstyle{ks} = [thick,
    postaction={decorate},
    decoration={
      markings,
      mark=at position 0.6 with {\arrow[thick, scale = 2, color = blue]{stealth}
    }}
  ]
\setcounter{MaxMatrixCols}{16}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=2]
\draw [help lines] (1,1) grid (4,4);
%%%%%%%%%%%%%% coordinates %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\foreach \x in {1,2,3,4}
%\foreach \y in {1,...,4}
%{
%\draw (\x,\y) +(1,1);
%\draw (\x,\y) node{(\x,\y)};
%}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\foreach \x in {1,3}
\foreach \y in {1,3}
{
\draw[fill=black] (\x,\y) circle (.3ex) +(1,1);
};
\foreach \x in {2,4}
\foreach \y in {2,4}
{
\draw[fill=black] (\x,\y) circle (.3ex) +(1,1);
};
%%%% draw red  circles
\foreach \x in {1,3}
\foreach \y in {2,4}
{
\draw[fill=red] (\x,\y) circle (.3ex) +(1,1);
};
\foreach \x in {2,4}
\foreach \y in {1,3}
{
\draw[fill=red] (\x,\y) circle (.3ex) +(1,1);
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%% vertical arrows %%%%%%%%%%%%%%%%%%%%%%%
\draw[ks] (1,1) -- (1,2); \draw[ks] (1,2) -- (1,3);\draw[ks] (1,3) -- (1,4);
\draw[ks] (2,1) -- (2,2); \draw[ks] (2,2) -- (2,3);\draw[ks] (2,3) -- (2,4);
\draw[ks] (3,1) -- (3,2); \draw[ks] (3,2) -- (3,3);\draw[ks] (3,3) -- (3,4);
\draw[ks] (4,1) -- (4,2); \draw[ks] (4,2) -- (4,3);\draw[ks] (4,3) -- (4,4);
%%%%%%%%%%%%%%%% horizontal arrows %%%%%%%%%%%%%%%%%%%%%%%
\draw[ks] (4,1) -- (3,1); \draw[ks] (3,1) -- (2,1);\draw[ks] (2,1) -- (1,1);
\draw[ks] (1,2) -- (2,2); \draw[ks] (2,2) -- (3,2);\draw[ks] (3,2) -- (4,2);
\draw[ks] (4,3) -- (3,3); \draw[ks] (3,3) -- (2,3);\draw[ks] (2,3) -- (1,3);
\draw[ks] (1,4) -- (2,4); \draw[ks] (2,4) -- (3,4);\draw[ks] (3,4) -- (4,4);
\end{tikzpicture}
\end{center}
\end{document}

代码存在一些问题:

  1. 我使用 for 循环生成顶点的坐标。这些坐标需要平移一定量才能得到与图片相似的坐标。如何做到这一点?
  2. 箭头在水平方向上是双周期的。既然我已经用蛮力绘制了箭头,那么有没有办法通过 for 循环生成箭头?垂直箭头也一样。

绘制方格的 Kasteleyn 方向的一般规则是为每个方格绘制箭头,使它们顺时针方向为奇数。对于较大的格子,我绘制箭头的方法非常麻烦。我们有什么方法可以用最少的代码来生成它吗?我希望我们社区的人能解决这个问题。提前谢谢。

答案1

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, chains, ext.misc}
\tikzset{
  pics/arrow/.style={/tikz/sloped, /tikz/allow upside down,
    code=\pgfarrowdraw{#1}}, pics/arrow/.default=>}
\begin{document}
\tikz[
  every on chain/.style={circle, draw, inner sep=+0pt, minimum size=+.75ex},
  start chain=rows going above, node distance=4.5em, on grid, >=Stealth,
  label position=above right, every label/.append style={inner sep=+.15em},
  conn/.default=\col, lab/.default=\col, fill on odd/.default=\col,
  conn/.style={pos=.55, edge node={pic{arrow/.pgfmath if={isodd(#1)}{>}{<}}}},
  lab/.style={label={$(#1, \row)$}},
  fill on odd/.style={/utils/if={isodd(\row+#1)}{fill}{}},
]
\foreach[count=\prevRow from -1] \row in {0, ..., 3}
  \node[on chain, fill on odd=0, lab=0, join=by {conn=0}] {}
    [start branch/.expanded=\row\space going right]
    node foreach[count=\chainCol from 2] \col in {1, ..., 5}[
      on chain, fill on odd, lab, join=by {conn=1},
      /utils/TeX/ifnum={\row > 0}{join=with {rows/\prevRow-\chainCol} by conn},
    ] {};
\end{document}

输出

在此处输入图片描述

答案2

无关:

  • 请提供真正的 MWE,到目前为止,序言中大多数加载的包和定义与您的问题无关。
  • 无论如何,请清理一下文档前言。有些包被加载了两次……

主题:

  • 如果用带圆圈的节点替换绘制的圆圈,则图片可以简单地用两个循环绘制:
    • 一个双循环用于放置节点(这里可以方便地使用 Werner 的答案这个问题), 和
    • 一个双循环用于绘制节点之间的所有边
  • MWE 的代码简单易懂,其特点是:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                decorations.markings,
                ext.arrows  % borrowed from @Qrrbrbirlbel answer,
                            % for move of arrowhead anchor to its center
                }

\begin{document}
    \begin{tikzpicture}[scale=2,
 every node/.style = {draw, circle, inner sep=2pt},
every label/.style = {rectangle, draw=none, font=\scriptsize, 
                      anchor=south west, inner sep=1pt},
 every edge/.style = {draw, semithick,
                      decoration={markings,
                                  mark=at position 0.5 with {\arrow[very thick,scale=0.8] {Centered Straight Barb}}
                                 },
                      postaction={decorate},
                     }
                        ]
  \foreach \r in {0,..., 3} 
  {
    \foreach \c in {0,..., 3} 
    {
      \ifodd\inteval{\r+\c} % borrowed from Werner answer, see explanation above
        \node (n\r\c) [fill, label=right:{$(\c,\r)$}] at (\c, \r) {};
      \else
        \node (n\r\c) [label=right:{$(\c,\r)$}] at (\c, \r) {};
      \fi
    }
  }
  \foreach \r [count=\i] in {0,..., 2}
  {
    \foreach \c in {0,..., 3}
    {
    \draw[teal] (n\c\r) edge (n\c\i);       % horizontal lines in each row
                                            % for columns is used \r counter
                                            % for rows is used \c counter
      \ifodd\c
        \draw[red] (n\r\c) edge (n\i\c);    % vertical lines in even columns
      \else
        \draw[blue] (n\i\c) edge (n\r\c);   % vertical lines in even columns
      \fi
     }
  }
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容