我在同一行上有四个维恩图,但由于 setdifference 符号,标题未对齐。有没有办法手动覆盖此问题并强制矩形对齐?
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=1.1in]{geometry}
\def \setA{ (0,0) circle (1cm) node {$A$}}
\def \setB{ (1.5,0) circle (1cm) node {$B$}}
\def \myrectangle{ (-2, -1.5) rectangle (3.5, 1.5) }
\begin{document}
\begin{center}
%Union of A and B
\begin{tikzpicture}[scale=0.7]
\draw \myrectangle node[below left]{$U$};
\fill[gray] (0,0) circle (1cm);
\fill[gray] (1.5,0) circle (1cm);
\draw \setA;
\draw \setB;
\node [below=.1cm] at (.1,-1.5) {$A \cup B$};
\end{tikzpicture} \
%Intersection of A and B
\begin{tikzpicture}[scale=0.7]
\draw \myrectangle node[below left]{$U$};
\begin{scope}
\clip \setA ;
\fill[gray] \setB ;
\end{scope}
\draw \setA;
\draw \setB;
\node [below=.1cm] at (.1,-1.5) {$A \cap B$};
\end{tikzpicture} \
%Difference of A and B
\begin{tikzpicture}[scale=0.7]
\draw \myrectangle node[below left]{$U$};
\fill[gray] (0,0) circle (1cm);
\begin{scope}
\clip \setA ;
\fill[white] \setB ;
\end{scope}
\draw \setA;
\draw \setB;
\node [below=.1cm] at (.1,-1.5) {$A \setminus B$};
\end{tikzpicture} \
%Complement of A
\begin{tikzpicture}[scale=0.7]
\fill[gray] (-1.5,-1.5) rectangle (1.5,1.5);
\fill[white] (0,0) circle (1cm);
\draw (-1.5,-1.5) rectangle (1.5,1.5) node[below left]{$U$};
\draw \setA;
\node [below=.1cm] at (.1,-1.5) {$A^C$};
\end{tikzpicture}
\end{center}
\end{document}
请注意输出中第一个、第二个和最后一个是如何对齐的,但第三个没有对齐。
答案1
我会用
\tikzset{every picture/.append style={scale=0.7,baseline}}
在center
环境中为所有图片设置相同的选项。(然后scale=0.7
必须从每个单张图片的选项中删除。)
代码:
\documentclass{article}
\usepackage{tikz}
\usepackage[margin=1.1in]{geometry}
\def \setA{ (0,0) circle (1cm) node {$A$}}
\def \setB{ (1.5,0) circle (1cm) node {$B$}}
\def \myrectangle{ (-2, -1.5) rectangle (3.5, 1.5) }
\begin{document}
\begin{center}
\tikzset{every picture/.append style={scale=0.7,baseline}}
%Union of A and B
\begin{tikzpicture}
\draw \myrectangle node[below left]{$U$};
\fill[gray] (0,0) circle (1cm);
\fill[gray] (1.5,0) circle (1cm);
\draw \setA;
\draw \setB;
\node [below=.1cm] at (.1,-1.5) {$A \cup B$};
\end{tikzpicture} \
%Intersection of A and B
\begin{tikzpicture}
\draw \myrectangle node[below left]{$U$};
\begin{scope}
\clip \setA ;
\fill[gray] \setB ;
\end{scope}
\draw \setA;
\draw \setB;
\node [below=.1cm] at (.1,-1.5) {$A \cap B$};
\end{tikzpicture} \
%Difference of A and B
\begin{tikzpicture}
\draw \myrectangle node[below left]{$U$};
\fill[gray] (0,0) circle (1cm);
\begin{scope}
\clip \setA ;
\fill[white] \setB ;
\end{scope}
\draw \setA;
\draw \setB;
\node [below=.1cm] at (.1,-1.5) {$A \setminus B$};
\end{tikzpicture} \
%Complement of A
\begin{tikzpicture}
\fill[gray] (-1.5,-1.5) rectangle (1.5,1.5);
\fill[white] (0,0) circle (1cm);
\draw (-1.5,-1.5) rectangle (1.5,1.5) node[below left]{$U$};
\draw \setA;
\node [below=.1cm] at (.1,-1.5) {$A^C$};
\end{tikzpicture}
\end{center}
\end{document}