如何在多个圆圈的不同位置添加文字?

如何在多个圆圈的不同位置添加文字?

我使用以下代码在乳胶中绘制了多个圆圈

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tikzpicture}
\draw (0,0) circle (1cm) [radius=0.1] node {$T_1$}
circle (0.6cm) 
circle (0.2cm);
\end{tikzpicture}

\end{document}

但是,我想添加如下图所示的文本圆形文字

请指导我如何按照图像添加文本。提前谢谢。

答案1

更新:您已加载positioning库。为了确保文本合适,您可能需要连续绘制圆圈。此答案带有样式

concentric fit={with center <center node> and nodes {<list of nodes>}}

这样您就可以方便地将所有文本放入一个圆心与 重合的圆节点中center node。如果您还加载backgrounds,则可以为圆添加阴影而不会擦除文本。

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,shadings,backgrounds,calc}
\pgfkeys{tikz/.cd,
maximal concentric radius/.store in=\MaxConcRad,
maximal concentric radius=0,
get maximal distance/.code n args={3}{\foreach \X in {south west,south east,north west,north east}
{\path let \p1=($(#2.center)-(#3.\X)$),\n1={veclen(\x1,\y1)} in 
\pgfextra{\pgfmathsetmacro{#1}{max(#1,abs(\n1))}
\xdef#1{#1}}; }},
center node/.store in=\CenterNode,
get maximal distance from center/.code={\foreach \X in {south west,south east,north west,north east}
{\path let \p1=($(\CenterNode.center)-(#1.\X)$),\n1={veclen(\x1,\y1)} in 
\pgfextra{\pgfmathsetmacro{\MaxConcRad}{max(\MaxConcRad,abs(\n1))}
\xdef\MaxConcRad{\MaxConcRad}}; }
},
concentric fit/.style args={with center #1 and nodes #2}{%
center node=#1,get maximal distance from center/.list=#2,
minimum size=2*\MaxConcRad*1pt,
at={(#1.center)}
}
}

\begin{document}

\begin{tikzpicture}[font=\sffamily]
\node[circle,draw,inner sep=1pt] (T1) at (1,1) {fff};
\node[above=1pt of T1] (eee) {eee};
\node[circle,draw,concentric fit={with center T1 and nodes {eee}}] (bigger circle){};
\node[above=1pt of bigger circle] (aaa) {aaa};
\node[below=1pt of bigger circle] (ccc) {ccc};
\node[left=1pt of bigger circle] (bbb) {bbb};
\node[right=1pt of bigger circle] (ddd) {ddd};
\node[circle,draw,concentric fit={with center T1 and nodes {{aaa,bbb,ccc,ddd}}},
path picture={\begin{scope}[on background layer]
\shade[upper left=blue!20, lower right=blue!40] 
(0,0) circle (\MaxConcRad*1pt);
\end{scope}}] (big circle){};
\end{tikzpicture}
\end{document}

在此处输入图片描述

原始答案

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,shadings,backgrounds,fit,calc}

\begin{document}

\begin{tikzpicture}[font=\sffamily,inner sep=1pt]
\node[circle,draw,inner sep=1pt] (T1) {$T_1$};
\node[above=1pt of T1] (eee) {eee};
\node[below=1pt of T1,opacity=0] (eee-cheat) {eee};
\node[circle,draw,fit=(eee) (eee-cheat)] (bigger circle) {};
\node[above=1pt of bigger circle] (aaa) {aaa};
\node[below=1pt of bigger circle] (ccc) {ccc};
\node[left=1pt of bigger circle] (bbb) {bbb};
\node[right=1pt of bigger circle] (ddd) {ddd};
\node[circle,draw,fit=(aaa) (bbb) (ccc) (ddd)] (big circle) {};
\begin{scope}[on background layer]
\shade[upper left=blue!20, lower right=blue!40]
let \p1=($(big circle.north)-(big circle.center)$) in
(big circle.center) circle (\y1);
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以使用适当的方式放置节点shiftsanchors

在此处输入图片描述

笔记:

  • bbb和文本ddd不太合适(没有缩放,因此font=\tiny)。我修改了inner sep=0pt这两个中的 ,以便将文本与其边界框之间的间隔设置为0pt
  • 和构成圆心,xshift指向文本周围虚拟框的控件位于指定位置。yshiftanchor

代码:

\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tikzpicture}[font=\tiny]
\draw (0,0) [fill=cyan!30]
    circle  (1cm)   
        node {fff}
        node [yshift=1cm, anchor=north] {aaa}
        node [xshift=1cm, anchor=east, inner sep=0pt] {bbb}
        node [xshift=-1cm, anchor=west, inner sep=0pt] {ddd}
        node [yshift=-1cm, anchor=south] {ccc}
    circle (0.6cm) 
        node [yshift=0.6cm, anchor=north] {eee} 
    circle (0.2cm)
    ;
\end{tikzpicture}%
\end{document}

答案3

具有基本 tikz 代码的选项。

结果: 在此处输入图片描述

梅威瑟:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage[scaled]{helvet}
%\renewcommand*\familydefault{\sfdefault} % Set font to serif family | affect entire document.
\begin{document}
    \begin{tikzpicture}[
        %Environment config
        font=\sffamily, %Best way to write in serif, only afects environment. | credit to @marmot's answer.
        %Environment styles
        Circle/.style={
            circle,
            draw,
            minimum width=#1,
            left color=blue!5,
            right color=blue!80!cyan!25,
            shading angle=45
        }
    ]

    \node[Circle=3.8cm](C) at (0,0){};
    \node[
        Circle=2.3cm,
        label=0:bbb,
        label=90:aaa,
        label=180:ddd,
        label=270:ccc
    ](C) at (0,0){};
    \node[
        Circle,%Radious controled by node text width
        label=-30:fff,
        label=90:eee,
        label=-120:ggg,
    ](C) at (0,0){$\mathsf{T_1}$}; %node text in math serif
    \end{tikzpicture}
\end{document}

相关内容