TikZ - 在基本维恩图中定位标签

TikZ - 在基本维恩图中定位标签

下面给出的代码可以生成下图,但是百分比值的标签定位是手动完成的......可以避免这种人为活动吗?

在此处输入图片描述

平均能量损失

\documentclass[tikz]{standalone}

\usetikzlibrary{positioning,fit,calc}

\begin{document}

\begin{tikzpicture}
    % The circles
    \node (secondcircle)
          [circle, draw=blue, text width=3cm, ultra thick] {};
    \node (firstcircle)
          [circle, left=-1.5cm of secondcircle, text width=3cm, draw=orange, ultra thick] {};

    % The rectangle
    \node (box) [fit=(firstcircle)(secondcircle), inner sep=1cm,draw, ultra thick,rounded corners] {};

    % The labels
    \node(universe) at (box.north east) [anchor=south west,xshift=0.25cm,yshift=0.25cm,draw,rounded corners, ultra thick] {$\Omega$};
    \node(young) at ([xshift=-2.5em]box.west) [anchor=west, draw=orange,text=orange,rounded corners, ultra thick] {$A$};
    \node(competition) at ([xshift=2.5em]box.east) [anchor=east, draw=blue,text=blue,rounded corners, ultra thick] {$B$};

    \node[yshift=-.75cm,xshift=0.75em] at (universe) {$100\,\%$};
    \node[yshift=-.75cm] at (young) {$80\,\%$};
    \node[yshift=-.75cm,xshift=3.85em] at (competition) {$30\,\% = 100\,\% - 70\,\%$};

    \node at ($(firstcircle)!0.5!(secondcircle)$) {$20\,\%$};
    \node [below=.25cm of box.north] {$10\,\%$};
    \node[xshift=-.7cm] at (firstcircle) {$60\,\%$};
    \node[xshift=.7cm] at (secondcircle) {$10\,\%$};

    % The labels
    \path[draw, ultra thick,shorten <=-0.1cm, shorten >=-0.1cm] (box.north east) -- (universe.south west);
    \path[draw=orange, ultra thick] (young) -- (firstcircle.west);
    \path[draw=blue, ultra thick] (competition.west) -- (secondcircle);
\end{tikzpicture}

\end{document}

答案1

您可以使用venndiagram具有以下\setpostvennhook功能的软件包:

\documentclass{article}
\usepackage{venndiagram}
\usetikzlibrary{calc}
\begin{document}
\makeatletter
\begin{venndiagram2sets}[
   overlap=1.5cm,
   radius=1.5cm,
   labelA=,
   labelB=,
   labelOnlyA=60\%,
   labelOnlyB=10\%,
   labelAB=20\%,
   labelNotAB=10\%,
   tikzoptions={rounded corners,ultra thick},
   ]
\setpostvennhook{%
\draw[ultra thick] ($(\@venn@Ax,\@venn@Ay)-(\@venn@radius,0)$) -- ($(\@venn@Ax,\@venn@Ay)-(\@venn@radius,0)-(1cm,0)$);
\node(young) at ($(\@venn@Ax,\@venn@Ay)-(\@venn@radius,0)-(1cm,0)$) [anchor=east, draw,rounded corners, ultra thick] {$A$};
\node[yshift=-.75cm] at (young) {$80\,\%$};
\draw[ultra thick] ($(\@venn@Bx,\@venn@By)+(\@venn@radius,0)$) -- ($(\@venn@Bx,\@venn@By)+(\@venn@radius,0)+(1cm,0)$);
\node(competition) at ($(\@venn@Bx,\@venn@By)+(\@venn@radius,0)+(1cm,0)$) [anchor=west, draw,rounded corners, ultra thick] {$B$};
\node[yshift=-.75cm,anchor=west] at (competition.west) {$30\,\% = 100\,\% - 70\,\%$};
\draw[ultra thick] ($(venn top right)-(0.5mm,0.5mm)$) -- ($(venn top right)+(5mm,5mm)$);
\node(universe) at ($(venn top right)+(4.5mm,4.5mm)$) [anchor=south west, draw,rounded corners, ultra thick] {$\Omega$};
\node[yshift=-.75cm,xshift=0.75em] at (universe) {$100\,\%$};
}
\end{venndiagram2sets}
\makeatother
\end{document}

在此处输入图片描述

这将自动计算标签位置。但没有颜色。

相关内容