TikZ를 사용하여 원 노드에 번호를 매겨야 합니다. 그러면 이 숫자가 상단(또는 하단, 왼쪽 또는 오른쪽)의 원과 겹치는 작은 사각형 안에 있도록 됩니다. 나는 이 작업을 별도로 수행하여 내가 원하는 방식으로 겹치도록 먼저 사각형을 그린 다음 원을 그렸습니다. 하지만 이것들을 많이 그려야 한다는 점에서, 상대적인 위치를 고려할 필요 없이 사각형을 함께 사용하여 원을 만들 수 있도록 더 나은 방법으로 할 수 있는 방법이 있는지 궁금합니다. 서로에게. 동그라미 장식의 사각형 부분을 만들어볼까? 어떤 아이디어가 있나요?
제가 염두에 두고 있는 것은 다음과 같습니다.
이를 재현하는 샘플 코드는 다음과 같습니다.
\documentclass[margin=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
C/.style = {circle, draw, fill=white, minimum size=#1, inner sep=0mm},
S/.style = {rectangle, draw, fill=white, minimum size=#1, inner sep=0mm},
]
\node[S=1cm, text depth = 0.5 cm,anchor=north] (a) at (0,0) {1}; % square
\node[C=4cm, below = -0.5cm of a] {label}; % circle
\end{tikzpicture}
\end{document}
답변1
다양한 옵션이 있습니다. 여기 사진을 바탕으로 한 옵션이 있습니다.
(저는 그것을 매우 구성 가능하게 만들고 원 주위에서 작동하도록 만들고 거리 등을 구성하는 데 약간의 재미를 느꼈습니다. 편집: 텍스트를 돌릴 수 있도록 더 많은 구성 옵션도 추가했습니다):
\documentclass[margin=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{backgrounds,matrix}
\begin{document}
\tikzset{
C/.style = {circle, draw, fill=white, minimum size=#1, inner sep=0mm},
apply style/.code={\pgfkeysalso{#1}},
apply style in macro/.style={apply style/.expand once={#1}},
my decorator pic/.pic={
\node[anchor=\myAnchor,rotate=-\myRotationAngleText,apply style in macro=\myExtraStyleText,](labelNode){\myText};
\begin{scope}[on background layer]
\node[
rotate fit={\myAngle},
fit=(labelNode)(\myCurrentNode.center),
rectangle,
fill=\myColor,
minimum size=\myMinimumSize,
inner sep=0mm,
apply style in macro=\myExtraStyle,
]
{};
\end{scope}
},
add deco/.style={
append after command={
\pgfextra{%
\edef\myCurrentNode{\tikzlastnode}%
\def\myAnchor{\myAngle+180}%
\pgfkeysalso{
set text/.store in=\myText,
set color/.store in=\myColor,
set color=pink!50!white,
set position angle/.store in=\myAngle,
set position angle=90,
set minimum size/.store in=\myMinimumSize,
set minimum size=8mm,
set distance/.store in=\myDistance,
set distance=0mm,
set extra style/.store in=\myExtraStyle,
set extra style=,
set extra style text/.store in=\myExtraStyleText,
set extra style text=,
set text depth/.store in=\myTextDepth,
rotate text angle/.store in=\myRotationAngleText,
rotate text angle=0,
rotate text bottom/.style={
rotate text angle=\myAngle-90,
/utils/exec={\def\myAnchor{90}},
},
rotate text top/.style={
rotate text angle=\myAngle+90,
/utils/exec={\def\myAnchor{-90}},
},
set text depth=2mm,
#1,
}}
{($(\myCurrentNode.\myAngle)+(\myAngle:\myDistance)$) pic{my decorator pic}}
}
},
}
\begin{tikzpicture}
\node[C=4cm,
add deco={set text=foo, set extra style={fill=red}},
add deco={set text=foo, set position angle=-90, set extra style={fill=red}},
add deco={set text=foo, set position angle=-90+25, rotate text bottom, set extra style={fill=red}, set extra style text={white}},
add deco={set text=foo, set position angle=-90-25, rotate text top, set extra style={fill=yellow}, set extra style text={orange}},
add deco={set text=foo, set position angle=90+25, rotate text top, set extra style={fill=green}, set extra style text={white}},
add deco={set text=foo, set position angle=90-25, rotate text bottom, set extra style={fill=orange}, set extra style text={white}},
] (expl1) {Top label};
\node[C=4cm, add deco={set text=bar, set position angle=-90}, below=of expl1] (expl2) {Bottom label};
\node[C=4cm, add deco={set text=croco, set distance=10mm, set position angle=-90}, below=of expl2] (expl3) {Bottom label};
\node[C=2cm, add deco={set text=baz, set position angle=0}, below right=of expl1] {Right label};
\node[C=2cm, add deco={set text=bar, set position angle=180+45}, below left=of expl1] {Left label};
\end{tikzpicture}
\end{document}