档案中似乎有很多类似的问题,但似乎没有一个与我的相匹配。
我有一个依赖于的 TikZ 图形\draw
。我知道键脱离了假定的笛卡尔平面,也许这就是定心的问题——如果是这样,我可能会被搞砸。
无论如何,这里是代码:
\documentclass{amsbook}
\usepackage{tikz}
\begin{document}
\def\SetA{(0,0) circle (1.5cm)}
\def\SetB{(1,2) circle (1.5cm)}
\def\SetC{(2,0) circle (1.5cm)}
\begin{center}
\begin{figure}
\begin{tikzpicture}
\draw (-3,-2) rectangle (5,4);
\draw (4.5,3.5) node {$\mathcal{U}$};
\draw (-2,2) node {$A \cap B$};
\draw (4,2) node {$A \cap C$};
\draw \SetA node[below] {$A$};
\draw \SetB node [above] {$B$};
\draw \SetC node [below] {$C$};
\begin{scope}
\clip \SetA;
\fill[red] \SetB;
\end{scope}
\begin{scope}
\clip \SetA;
\clip \SetB;
\fill[green] \SetC;
\end{scope}
\end{tikzpicture}
\caption{Examples of Intersection}
\end{figure}
\end{center}
\end{document}
输出如下:
答案1
不要在环境figure
中使用环境center
,只需figure
使用\centering
。
看何时应使用 \begin{center} 而不是 \centering?。
我还添加了caption
包以实现更好的标题对齐。
\documentclass{amsbook}
\usepackage{caption}
\usepackage{tikz}
\begin{document}
\def\SetA{(0,0) circle (1.5cm)}
\def\SetB{(1,2) circle (1.5cm)}
\def\SetC{(2,0) circle (1.5cm)}
\begin{figure}\centering
\begin{tikzpicture}
\draw (-3,-2) rectangle (5,4);
\draw (4.5,3.5) node {$\mathcal{U}$};
\draw (-2,2) node {$A \cap B$};
\draw (4,2) node {$A \cap C$};
\draw \SetA node[below] {$A$};
\draw \SetB node [above] {$B$};
\draw \SetC node [below] {$C$};
\begin{scope}
\clip \SetA;
\fill[red] \SetB;
\end{scope}
\begin{scope}
\clip \SetA;
\clip \SetB;
\fill[green] \SetC;
\end{scope}
\end{tikzpicture}
\caption{Examples of Intersection}
\end{figure}
\end{document}
或者,您也可以使用center
without figure
,在本例中用 with 添加标题\captionof
:
\documentclass{amsbook}
\usepackage{caption}
\usepackage{tikz}
\begin{document}
\def\SetA{(0,0) circle (1.5cm)}
\def\SetB{(1,2) circle (1.5cm)}
\def\SetC{(2,0) circle (1.5cm)}
\begin{center}
\begin{tikzpicture}
\draw (-3,-2) rectangle (5,4);
\draw (4.5,3.5) node {$\mathcal{U}$};
\draw (-2,2) node {$A \cap B$};
\draw (4,2) node {$A \cap C$};
\draw \SetA node[below] {$A$};
\draw \SetB node [above] {$B$};
\draw \SetC node [below] {$C$};
\begin{scope}
\clip \SetA;
\fill[red] \SetB;
\end{scope}
\begin{scope}
\clip \SetA;
\clip \SetB;
\fill[green] \SetC;
\end{scope}
\end{tikzpicture}
\captionof{figure}{Examples of Intersection}
\end{center}
\end{document}
两者的区别在于figure
浮动(即 LaTeX 把它放在合适的位置),而非center
浮动(它放在合适的位置)。