矩形内嵌矩形

矩形内嵌矩形

我需要得到图片上的内容:

在此处输入图片描述

平均能量损失

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

\newcommand* \mylengthA {3}
\newcommand* \mylengthW {0.5}
\newcommand* \mylengthG {0.5}


\fill [blue] (0,0) rectangle (\mylengthA, \mylengthA);
\fill [white]
  (\mylengthW,\mylengthW) rectangle
  (\mylengthA - \mylengthW,\mylengthA - \mylengthW);
\fill [yellow]
  (0,\mylengthA/2 + \mylengthG/2) rectangle +(\mylengthW,-\mylengthG);
\end{tikzpicture}

\end{document}

答案1

你可以使用情节标记并按照你的喜好将它们分散开来:

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{plotmarks}

\begin{document}
    
\begin{tikzpicture}
    \pgfsetplotmarksize{1.5ex}

    \draw[very thick] (0,0) rectangle (10,10);
    \draw[very thick,dashed] (2,2) rectangle (8,8);
    
    %points
    \node[green] at (1,2) {\pgfuseplotmark{*}};
    \node[green] at (8.5,8.5) {\pgfuseplotmark{*}};
    
    %diamonds
    \node[red] at (3,3) {\pgfuseplotmark{diamond*}};
    \node[red] at (4,5) {\pgfuseplotmark{diamond*}};
    


\end{tikzpicture}
    
\end{document}

在此处输入图片描述

相关内容