我testbox
使用node
tikz 创建了一个,如下所示:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[draw, regular polygon, regular polygon sides = 6] (testbox) {};
% \fill [red] (testbox.south east) rectangle (testbox.north west);
% Thanks @Symbol1 for providing this method, but I didn't make my question clear.
% Actually I want to fill a 6-side regular polygon
\end{tikzpicture}
\end{document}
如果testbox
我node
由于某些原因必须先(我知道我可以使用\node[fill = red]
)?
答案1
您可以保存节点路径以供日后使用。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,backgrounds}
\begin{document}
\begin{tikzpicture}
\node[draw, regular polygon, regular polygon sides = 6,
save path=\bestpath] (best) {bestagon};
\scoped[on background layer]% this line not needed if no text to show
\fill[red, use path=\bestpath];
\end{tikzpicture}
\end{document}
答案2
这是一个解决方案:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[draw, regular polygon, regular polygon sides = 6] (testbox) {};
\path[fill=red,draw] (testbox.corner 1)
foreach \cornernum in {2,...,6} {-- (testbox.corner \cornernum)} -- cycle;
\end{tikzpicture}
\end{document}