我尝试在矩形节点形状的基础上进行构建,但我得到的结果是旋转效果不佳(散列图案,第二个矩形)。如您所见,我尝试添加尽可能多的变换形状选项,但都没有成功。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\tikzset{%
miroir/.style = {%
minimum width = 1cm,
minimum height = .4cm,
rectangle,
transform shape,
fill = gray!10,
pattern = north east lines,
append after command = {%
\pgfextra{%
\begin{pgfinterruptpath}[transform shape]
\draw[transform shape,
very thin, fill=gray!10,shorten >=0.2bp, shorten <=0.2bp
]
(\tikzlastnode.north west)
-- ++(0,.2)
-- ($(\tikzlastnode.north east)+(0,.2)$)
-- (\tikzlastnode.north east)
--cycle;
\end{pgfinterruptpath}
}
}
}
}
\node [miroir,transform shape,rotate=0] at (0,0) {};
\end{tikzpicture}
\end{document}
使用 rotate=0 后,它看起来就像我想要的那样
但如果我使用 rotate=45,它就搞乱了:
我怎样才能解决这个问题 ?
答案1
这是我的手动解决方案因为我的\pgfmath
几乎是0
。由于我们无法旋转预定义的图案,所以我手动绘制图案。在中for-loop
,我使用一个大数字来填充矩形。我不知道如何根据框大小和两条连续线之间的距离计算循环数。我的“解决方案”的另一个缺点是您还必须rotation angle
为样式输入 as 参数memoir
。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[tightpage,active]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}
\tikzset{%
miroir/.style = {%
minimum width = 1cm,
minimum height = .4cm,
%pattern = north east lines,
append after command = {%
\pgfextra{%
\begin{pgfinterruptpath}
\fill[gray!10,rotate=#1] ($(\tikzlastnode.north west)$) rectangle
($(\tikzlastnode.south east)$);
\draw[very thin, fill=gray!10,shorten >=0.2bp,
shorten <=0.2bp,
rotate={#1},
]
(\tikzlastnode.north west)
-- ++(0,.2)
-- ($(\tikzlastnode.north east)+(0,.2)$)
-- (\tikzlastnode.north east)
--cycle;
\clip[rotate=#1] ($(\tikzlastnode.north west)$) rectangle
($(\tikzlastnode.south east)$);
\foreach\i in {0,...,20}{
\draw[rotate=#1] ($(\tikzlastnode.south east) -
\i*(2pt,0) - (.4pt,0)$) -- ++(1cm,1cm);
}
\end{pgfinterruptpath}
}
}
}
}
\node [rotate=45,miroir=45] at (0,0) {};
\end{tikzpicture}
\end{document}