如何将标签与 tikz 中图片的中心对齐

如何将标签与 tikz 中图片的中心对齐

我有一个 tikz 代码来绘制四个圆圈,如下所示:

\begin{document}
\pagestyle{empty}   

\tikzstyle{white} = [fill=white,fill opacity=0.4]
\tikzstyle{gray1} = [fill=gray!5,fill opacity=0.7]
\tikzstyle{gray2} = [fill=gray!20,fill opacity=0.7]

\def\firstcircle{(2,0) circle (2.2cm)}
\def\secondcircle{(4,2) circle (2.7cm)}
\def\thirdcircle{(6,0) circle (2.5cm)}
\def\foruthcircle{(5,1) circle (1cm)}

\begin{tikzpicture}
\draw \firstcircle;
\draw \secondcircle; 
\draw \thirdcircle;
\draw \foruthcircle; 
    
\fill[white] \firstcircle;
\fill[white] \secondcircle;
\fill[white] \thirdcircle;
\fill[gray2] \foruthcircle;

\path (2,-0.5) node[below]  {$X_1$};
\path (6.5,-0.5) node[below]  {$X_2$};
\path (4,3) node[below]  {$X_3$};   
\path (5,1.2) node[below]  {$A$};
\path (2,5) node[above] {$\quad\widetilde{S}\left(\phi\right)=\left(A,\mathcal{G}\vert_{r},\subset\right)\quad$  and  $\quad\mathcal{G}\vert_{r}=\{X_1,X_2,X_3\}$};

\end{tikzpicture}   
\end{document}

我想将“\path (2,5) node[above] {$\quad\widetilde{S}...”标签放置在图片的中心。但是当我将 \path (2,5) 更改为 \path (4,5) 时,它也会将标签下方的圆圈向右移动。我需要帮助。谢谢。

答案1

像这样?

在此处输入图片描述

使用 shapec 绘制图像要简单得多circle

\documentclass[tikz, margin=3.141592]{standalone}

\begin{document}
    \begin{tikzpicture}[
C/.style = {circle, draw, minimum size=#1, align=center}
                        ]
\node (n1) [C=44mm]            {\\ $X_1$};
\node (n2) [C=50mm] at (4,0)   {\\ $X_2$};
\node (n3) [C=54mm] at (2,2)   {$X_3$\\ }
    node[above] at (n3.north) {$\widetilde{S}\left(\phi\right)=\left(A,\mathcal{G}\vert_{r},\subset\right)$  
        \quad and \quad
     $\mathcal{G}\vert_{r}=\{X_1,X_2,X_3\}$};;
\node (n4) [C=20mm, fill=gray!30] at (3,1)   {A};
\end{tikzpicture}
\end{document}

答案2

在此处输入图片描述

    \documentclass{article}    
    \usepackage{tikz}
    \usetikzlibrary{shapes,backgrounds}
    \usepackage{verbatim}

    \begin{document}
    \pagestyle{empty}       
    \begin{tikzpicture}
    \draw[fill=gray!10, fill opacity=0.7] (0,0) circle (2.2cm) node[ red] {$X_1$} ;
    \draw [fill=gray!10, fill opacity=0.7] (2,2) circle (2.7cm) node[ red] {$X_2$}; 
    \draw [fill=gray!10, fill opacity=0.7] (4,0) circle (2.5cm) node[red] {$X_3$};
    \draw [fill=white] (3,1) circle (1cm) node[red] {$A$} ;   
    \end{tikzpicture}
\end{document}

相关内容