我希望数字像路径一样对齐(并且位于中间)。
但这只适用于这里的数字“1”...
有什么技巧吗?还是我必须计算角度?
\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\pgfmathtruncatemacro\s{10}%
\pgfmathsetmacro\R{1.7}
\pgfmathsetmacro\r{1.4}
\pgfmathsetmacro\Rout{\R/cos(180/\s)}%
\begin{tikzpicture}[font=\footnotesize]
\node[shape=regular polygon, regular polygon sides=\s,
inner sep=0pt, minimum size=2cm*\r, draw,
align=center,
] (rad) {good at 1; \\ at 2,3,4,5 bad};
\node[shape=regular polygon, regular polygon sides=\s,
inner sep=0pt, minimum size=2cm*\Rout, draw,
] (Rad) {};
\foreach \No in {1,...,5}{%%
\path[draw=red, ->] (rad.side \No) -- (Rad.side \No) node[inner sep=0pt, midway]{\No};
}%%
\end{tikzpicture}
\end{document}
答案1
您可以计算角度,这并不困难:
rotate={360*(\No-1)/\s)}
完整示例:
\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\pgfmathtruncatemacro\s{10}%
\pgfmathsetmacro\R{1.7}
\pgfmathsetmacro\r{1.4}
\pgfmathsetmacro\Rout{\R/cos(180/\s)}%
\begin{tikzpicture}[font=\footnotesize]
\node[shape=regular polygon, regular polygon sides=\s,
inner sep=0pt, minimum size=2cm*\r, draw,
align=center,
] (rad) {good at 1; \\ at 2,3,4,5 bad?};
\node[shape=regular polygon, regular polygon sides=\s,
inner sep=0pt, minimum size=2cm*\Rout, draw,
] (Rad) {};
\foreach \No in {1,...,8}{%%
\path[draw=red, ->] (rad.side \No) -- (Rad.side \No) node[inner sep=0pt, midway, rotate={360*(\No-1)/\s)}]{\No};
}%%
\end{tikzpicture}
\end{document}
答案2
像这样?
编辑(1):现在箭头和数字已经形成了完整的形状。
编辑(2):通过定义图像元素样式并稍微重新组织代码,原始代码可以以更简洁的方式编写。
\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\pgfmathtruncatemacro\s{10}%
\pgfmathsetmacro\R{1.7}
\pgfmathsetmacro\r{1.4}
\pgfmathsetmacro\Rout{\R/cos(180/\s)}%
\begin{tikzpicture}[
EL/.style = {% Edge Labels
font=\small, sloped, rotate=#1},
RP/.style = {% Regular Poligon
shape=regular polygon, regular polygon sides=\s, draw,
minimum size=2cm*#1, inner sep=0pt,
align=center}
]
\node[RP=\r] (rad) {good at 1; \\ at 2, 3, \dots 11 bad};
\node[RP=\R] (Rad) {};
\foreach \No in {2,...,5}
\path[draw=red, ->] (rad.side \No) -- node[EL=+90] {\No} (Rad.side \No);
\foreach \No in {1,6,7,...,10}
\path[draw=red, ->] (rad.side \No) -- node[EL=-90] {\No} (Rad.side \No);
\end{tikzpicture}
\end{document}