沿节点形状放置文本

沿节点形状放置文本

我想沿着节点的形状放置文本。下面的 MWE 生成以下图像。我希望文本“Classic First Program”遵循节点形状的圆圈。

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) node [label=above:Classic First Program, align=center,circle,font=\huge,draw] {Hello\\ World!};
\end{tikzpicture}
\end{document}

在此处输入图片描述

有没有一种自动化的方法可以做到这一点,而无需自行定义与节点形状匹配的另一条路径?我希望能够更改内部文本(以及节点形状),而不必调整标签文本。

答案1

也许有一个简单的方法,但我找不到。

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\node[
circle, 
draw,
align=center,
font=\huge,
decoration={text along path, text align=center, reverse path=true, text={Classic First Program}},
postaction={decorate}, 
rotate=-90,
]  {\rotatebox[origin=c]{90}{Hello}\,\rotatebox[origin=c]{90}{World!}};
\end{tikzpicture}
\end{document}

圆圈内有文字并位于顶部

编辑:另一种方法:

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\node[
circle, 
draw,
align=center,
font=\huge,
text opacity=0,
decoration={text along path, text align=center, reverse path=true, text={Classic First Program}},
postaction={decorate}, 
rotate=-90,
label={[align=center, font=\huge]center:Hello\\World!},
]  {Hello\\World!};
\end{tikzpicture}
\end{document}

圆圈内有文字并位于顶部

编辑:我做到了:o)

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\node[
circle, 
draw,
align=center,
font=\huge,
decoration={text along path, text align=center, reverse path=true, text={Classic First Program}},
postaction={transform canvas={rotate=-90}, postaction={decorate}}, 
]  {Hello\\World!};
\end{tikzpicture}
\end{document}

答案2

根据@hpekristiansen 上面的最后一个回答:

在此处输入图片描述

我添加了一个decoration={raise=3pt}以将文本放置在稍微偏离路径的位置(并改变了其居中的角度)。

\documentclass[tikz, border=1 cm]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\node[
circle, 
draw,
align=center,
font=\huge,
decoration={text along path, text align=center, reverse path=true, text={Classic First Program}},
postaction={transform canvas={rotate=-45}, postaction={decorate,decoration={raise=3pt}}}, 
]  {Hello\\World!};
\end{tikzpicture}
\end{document}

相关内容