Tikz、维恩图和格式

Tikz、维恩图和格式

回到我通常的问题,我希望从这个问题中获得乐趣,并寻求如何为下面的 tikz 图(维恩图)编写更好的程序的想法。 Marmot 告诉我不要嵌套 tikzpictures,所以这是一个解决方案。我对其他想法很感兴趣。随意修改!

\documentclass{article}
%\usepackage{geometry}
\usepackage{tikz}

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\newcommand{\A}{\mathbf{A}}
\newcommand{\B}{\mathbf{B}}
\newcommand{\C}{\mathbf{C}}
\newcommand{\x}{\mathbf{x}}

\begin{document}

\def\thirdcircle{(0,0) ellipse (1.5cm and .5cm)}     %%%%%% A
\def\secondcircle{(0,0) ellipse (2.25cm and .75cm)}  %%%%%% B
\def\firstcircle{(0,0) ellipse (3cm and 1cm)}        %%%%%% C
\def\Extracircle{(2,0) ellipse (1.1cm and 2cm)}      %%%%%% Extra Set 
                                                        C in part(c)

\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}

\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
 outline/.style={draw=circle edge, thick}}


\begin{center}
\begin{minipage}{.45\textwidth}
\begin{tikzpicture}
  \begin{scope} 
        \clip \Extracircle;
            \fill[filled] \thirdcircle;
        \end{scope} 
 \draw[outline] \firstcircle node[right=2.25cm] {$\A$};
     \draw[outline] \thirdcircle node [] {$\B$};
   \draw[fill] (0:1) circle (1pt) node[right=1pt] {\scriptsize $\x$};   
 \draw[outline] \Extracircle node[above=1cm] {$\C$};
    \node at (0,-2) [below] {$\mathbf{B \cap C}$};
    \node at (4,-2) [below] {$\mathbf{\subset}$};
 \end{tikzpicture}
\end{minipage}
\begin{minipage}{.45\textwidth}
\begin{tikzpicture}
\begin{scope} 
        \clip \Extracircle;
            \fill[filled] \firstcircle;
        \end{scope} 
 \draw[outline] \firstcircle node[right=2.25cm] {$\A$};
     \draw[outline] \thirdcircle node [] {$\B$};
   \draw[fill] (0:1) circle (1pt) node[right=1pt] {\scriptsize $\x$};   
 \draw[outline] \Extracircle node[above=1cm] {$\C$};
\node at (0,-2) [below] {$\mathbf{A \cap C}$};
\end{tikzpicture}
\end{minipage}
\end{center}

\end{document}

输出:

在此处输入图片描述

答案1

首先,如果你对结果很满意,并且没有任何问题,你可以保持原样,不要试图“改进”它。既然你在这里问,这里有一些建议(重点是 TiZ 部分并忽略页面几何问题,可以通过真正使用geometry包来更优雅地解决这些问题。)

这是一些已发生改变的代码。

  1. 这里没有使用 minipages,而是将两个部分放在了范围内(使用local bounding boxes)。这在调整距离时会有所帮助,特别是现在图形确实居中了。在您的示例中,minipages 居中,但图形不一定居中。(我个人可能会\centering在这里使用。)
  2. 各种省略号不再存储在宏中,而是存储在 Ti 中Z 样式。(这不一定是“更好”,但可以被认为是 Ti子儿。 ;-)
  3. 我还添加了一些应用程序even odd rule,Dave 同时提到了这一点。

\documentclass{article}
%\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{patterns}
\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\newcommand{\A}{\mathbf{A}}
\newcommand{\B}{\mathbf{B}}
\newcommand{\C}{\mathbf{C}}
\newcommand{\x}{\mathbf{x}}

\begin{document}

C in part(c)

\colorlet{circle edge}{blue!50}
\colorlet{circle area}{blue!20}

\tikzset{filled/.style={fill=circle area, draw=circle edge, thick},
 outline/.style={draw=circle edge, thick}}


\begin{center}
\begin{tikzpicture}[standard ellipse/.style={insert path={(0,0) ellipse (#1*1.5cm and #1*.5cm)}},
standard ellipse/.default=1,
extra circle/.style={insert path={(2,0) ellipse (1.1cm and 2cm)}}]
 \begin{scope}[local bounding box=left]
  \coordinate (O) at (0,0);
  \begin{scope} 
   \clip[extra circle];
   \fill[filled,standard ellipse];
  \end{scope} 
  \draw[outline,standard ellipse=2] node[right=2.25cm] {$\A$};
  \draw[outline,standard ellipse] node [] {$\B$};
  \draw[fill] (0:1) circle (1pt) node[right=1pt,font=\scriptsize] {$\x$};   
  \draw[outline,extra circle] node[above=1cm] {$\C$};
  \node at (0,-2) [below] {$\mathbf{B \cap C}$};
  \node at (4,-2) [below] {$\mathbf{\subset}$};
 \end{scope}
 \begin{scope}[local bounding box=right,shift={([xshift=3cm]left.east|-O)}]
  \begin{scope} 
   \clip[extra circle];
   \fill[filled,standard ellipse=2];
   \path[pattern=north east lines,even odd rule,standard ellipse=2,standard
   ellipse=1];
  \end{scope} 
  \draw[outline,standard ellipse=2] node[right=2.25cm] {$\A$};
  \draw[outline,standard ellipse] node [] {$\B$};
  \draw[fill] (0:1) circle (1pt) node[right=1pt,font=\scriptsize] {$\x$};   
  \draw[outline,extra circle] node[above=1cm] {$\C$};
  \node at (0,-2) [below] {$\mathbf{A \cap C}$};
 \end{scope} 
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

相关内容