4

I have been trying to draw the Kasteleyn orientation for a 4 by 4 square lattice. I aim to draw a figure like the one (given for 6 by 4) below.enter image description here

The code I have written is given below.

\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}

There are a few issues with the code:

  1. I used the for loop to generate the coordinates of the vertices. These coordinates need to be translated to a certain amount to get one similar to the picture. How can this be done?
  2. The arrows are double periodic in the horizontal direction. Given I have drawn the arrows by brute force, is there any way to generate the arrows by for loop? The same question goes for the vertical arrows.

The general rule for drawing the Kasteleyn orientation for a square lattice is to draw arrows for each square such that they are clockwise odd. For larger lattices, my method of drawing arrows is very cumbersome. Is there any way we can generate it with a minimal amount codes? I hope people in our community can resolve this problem. Thanks in advance.

felix
  • 463
  • 2
    This seems like a job for a TikZ matrix or even TikZ-CD. All I see are circular nodes, labels and edges between the nodes. Though, the matrix isn't really necessary at all. With the chains library this can be very short code as well. – Qrrbrbirlbel Aug 07 '23 at 02:11
  • @ Qrrbrbirlbel, If possible, can you please post your answer? It will be easier for someone to learn from your answer then. – felix Aug 07 '23 at 02:13

2 Answers2

7

Code

\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}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
  • With an uptodate tikz-ext installation one can load the ext.arrows library and use > = Centered Stealth and doesn't need to guesstimate pos = .55. – Qrrbrbirlbel Aug 07 '23 at 09:21
  • Great +1 // For those, like me, wondering about some commands and the tikzlibrary, find everything here: https://ctan.org/pkg/tikz-ext – MS-SPO Aug 07 '23 at 14:26
5

Off-topic:

  • Please provide really MWE, so far most of loaded packages and definitions in preamble are not relevant to your problem.
  • Anyway, clean-up your document preamble. Some of packages are loaded twice ...

On-topic:

  • if you replace drawn circles with circled nodes, your picture can be simple drawn in two loops:
    • one double loop for placement of nodes (here is handy to use Werner answer on this question), and
    • one double loop for drawn all edges between nodes
  • MWE, with simple and easy understandable code, is:
\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}

enter image description here

Zarko
  • 296,517