绘制类似张量的网络

绘制类似张量的网络

有哪些 TeX(TexShop) 方法可以绘制出这个看似精致的图形?

在此处输入图片描述

答案1

有很多方法可以做到这一点。有些人希望定义pics 以避免一些重复。

\documentclass{article}
\usepackage[margin=1in]{geometry} 
\usepackage{amsmath}
\usepackage{subcaption}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,fit}
\tikzset{pics/grid/.style={code={\tikzset{wonderich/.cd,#1}
    \def\pv##1{\pgfkeysvalueof{/tikz/wonderich/##1}}%
    \draw[thick] (0.1,0.1) grid (\pv{nx}+0.9,\pv{ny}+0.9);}},
pics/nodes/.style={code={\tikzset{wonderich/.cd,#1}
    \def\pv##1{\pgfkeysvalueof{/tikz/wonderich/##1}}%   
    \path  foreach \X in {1,...,\pv{nx}} {
      foreach \Y in {1,...,\pv{ny}} { 
      (\X,\Y)node[minimum size=\pv{r},style/.expanded=\pv{style},inner sep=0pt]{}} };
}},
wonderich/.cd,nx/.initial=4,ny/.initial=4,r/.initial=4pt,
    style/.initial={circle,fill}}
\begin{document}
\begin{figure}
\centering
\begin{subfigure}{.32\textwidth}
\centering
    \begin{tikzpicture}
     \path pic{grid} pic[red]{nodes}
      (0.3,4.7) node{$\mathbf{T}$};     
    \end{tikzpicture}
    \caption{}
\end{subfigure}\hfill
\begin{subfigure}{.32\textwidth}
\centering
    \begin{tikzpicture}
     \draw[dashed]  pic{grid}
     (0.3,4.7) node{$\mathbf{S}$};
     \clip (0.7,0.7) rectangle (4.3,4.3);
     \path[rotate around={45:(45:2.5)},scale={sqrt(2)},
        shift={(0,-0.75)},transform shape]  pic{grid}
        pic{nodes={style={rectangle,draw,fill=white,rotate=45},r=7pt}};
    \end{tikzpicture}
    \caption{}
\end{subfigure}\hfill
\begin{subfigure}{.32\textwidth}
\centering
    \begin{tikzpicture}
     \draw[dashed]  pic{grid}
     (0.3,4.7) node{$\mathbf{S}\boldsymbol{'}$};
     \clip (0.35,0.35) rectangle (4.65,4.65);
     \path[rotate around={45:(45:2.5)},scale={sqrt(2)},
        shift={(0,-0.75)},transform shape]  pic{grid={nx=3,ny=3}}
        pic[red]{nodes={r=4pt,nx=3,ny=3}};
    \end{tikzpicture}
    \caption{}
\end{subfigure}
\end{figure}
\end{document}

在此处输入图片描述

相关内容