TikZ:内部分离环绕模式

TikZ:内部分离环绕模式

在此处输入图片描述

我怎样才能inner sep在图案周围有一个(小)?

\documentclass[]{article}
\usepackage{tikz}
 \usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[
mypattern/.style={%
fill=violet!22, 
postaction={
pattern=crosshatch, 
%pattern=north east lines, % alternativ
pattern color=violet,  draw,
},   },%
]
\node[minimum size=4cm, rounded corners, mypattern]{};
\end{tikzpicture}
\end{document}

答案1

以下操作将在rectangle节点上运行:

在此处输入图片描述

\documentclass[]{article}
\usepackage{tikz}
 \usetikzlibrary{patterns}
\begin{document}

\pgfmathsetmacro\roottwo{sqrt(2)}
\begin{tikzpicture}[
mypattern/.style={%
fill=violet!22, 
postaction={
pattern=crosshatch, 
%pattern=north east lines, % alternativ
pattern color=violet,  draw=none,
},   },%
%
Mypattern/.style={
path picture={ 
\path (path picture bounding box.north west) 
      -- +(-45:\roottwo*\pgfkeysvalueof{/pgf/inner xsep}) coordinate(ppUL); 
\path (path picture bounding box.south east) 
      -- +(135:\roottwo*\pgfkeysvalueof{/pgf/inner xsep}) coordinate(ppLR); 
\path[mypattern] (ppUL) rectangle (ppLR);
},
},%
]


\node[minimum size=5cm, draw, rounded corners, 
inner sep=3.456mm, Mypattern,
label={pattern with inner sep}] (N) {inner sep = \pgfkeysvalueof{/pgf/inner xsep}};

\draw[red] (N.south) -- +(0,3.456mm) node[midway, right]{3.456 mm};
\draw[red] (N.east) -- +(-3.456mm,0);
\end{tikzpicture}
\end{document}

相关内容