我在用 TikZ 绘制几张图片时遇到了一些麻烦。它对两张相邻的图片进行了不同的对齐,如下所示:
另外,我怎样才能使“and”垂直居中?
如果这是重复的问题,我深表歉意。它以前肯定出现过,但我没有看到。这是代码。任何其他评论和建议都值得赞赏,因为我刚刚学习 TikZ。
编辑:我推测对齐方式不同是因为右侧底部包含标签。但我仍然想知道如何让“and”垂直居中。
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\usepackage{mathrsfs}
\begin{document}
\begin{center}
\begin{tikzpicture}
\coordinate
(a0) at (0,0);
\coordinate
(a1) at (5,5);
\coordinate[label=left:$g$] (a2) at (2.5,3.5);
\fill (a2) circle (2pt);
\coordinate[label=above:$X$] (a3) at (2.5,5);
\coordinate[label=left:$f$] (a4) at (2.5,2.25);
\fill (a4) circle (2pt);
\coordinate[label=above:$\varepsilon$] (a5) at (3.5,1.5);
\fill (a5) circle (2pt);
\coordinate[label=below:$Y$] (a6) at (1.5,0);
\coordinate
(a8) at (4.35,2.5);
\coordinate[label=above:$L$] (a9) at (4.5,5);
\draw (a0) rectangle (a1);
\draw plot [smooth] coordinates {(a4) (a5) (a8) (a9)};
\draw (a3) -- (a2) -- (a4) -- (a6);
\coordinate[label=$\mathbf{1}$] (1) at (1,3);
\coordinate[label=$\mathscr{D}$] (D) at (3.4,3.4);
\coordinate[label=$\mathscr{C}$] (C) at (3.78,.5);
\end{tikzpicture}
$\qquad$and$\qquad$
\begin{tikzpicture}
\draw (0,0) rectangle (5,3);
\draw (0,3.5) rectangle (5,5);
\draw (2.5, 5) -- (2.5, 3.5);
\draw (4, 5) -- (4, 3.5);
\coordinate[label=above:$X$] (X) at (2.5, 5);
\coordinate[label=above:$L$] (X) at (4, 5);
\draw (2.5, 3) -- (2.5, 1.8) -- (1,0);
\draw plot [smooth] coordinates {(2.5, 1.8) (3.4, 1) (4, 1.8) (4, 3)};
\coordinate[label=below:$\varepsilon$] (epsilon) at (3.4, 1);
\fill (epsilon) circle (2pt);
\coordinate[label=left:$g$] (g) at (2.5, 4);
\fill (g) circle (2pt);
\coordinate[label=left:$f$] (f) at (2.5, 1.8);
\fill (f) circle (2pt);
\end{tikzpicture}
\end{center}
\end{document}
答案1
一个简单的解决方案是使用baseline=25mm
选项:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\usepackage{mathrsfs}
\begin{document}
\begin{center}
\begin{tikzpicture}[baseline=25mm]
\coordinate (a0) at (0,0);
\coordinate (a1) at (5,5);
\coordinate[label=left:$g$] (a2) at (2.5,3.5);
\fill (a2) circle (2pt);
\coordinate[label=above:$X$](a3) at (2.5,5);
\coordinate[label=left:$f$] (a4) at (2.5,2.25);
\fill (a4) circle (2pt);
\coordinate[label=above:$\varepsilon$] (a5) at (3.5,1.5);
\fill (a5) circle (2pt);
\coordinate[label=below:$Y$](a6) at (1.5,0);
\coordinate (a8) at (4.35,2.5);
\coordinate[label=above:$L$](a9) at (4.5,5);
\draw (a0) rectangle (a1);
\draw plot [smooth] coordinates {(a4) (a5) (a8) (a9)};
\draw (a3) -- (a2) -- (a4) -- (a6);
\coordinate[label=$\mathbf{1}$] (1) at (1,3);
\coordinate[label=$\mathscr{D}$] (D) at (3.4,3.4);
\coordinate[label=$\mathscr{C}$] (C) at (3.78,.5);
\end{tikzpicture}
\hfil and\hfil
\begin{tikzpicture}[baseline=25mm]
\draw (0,0) rectangle (5,3);
\draw (0,3.5) rectangle (5,5);
\draw (2.5, 5) -- (2.5, 3.5);
\draw (4, 5) -- (4, 3.5);
\coordinate[label=above:$X$] (X) at (2.5,5);
\coordinate[label=above:$L$] (L) at (4.0,5);
\draw (2.5, 3) -- (2.5, 1.8) -- (1,0);
\draw plot [smooth] coordinates {(2.5, 1.8) (3.4, 1) (4, 1.8) (4, 3)};
\coordinate[label=below:$\varepsilon$] (epsilon) at (3.4, 1);
\fill (epsilon) circle (2pt);
\coordinate[label=left:$g$] (g) at (2.5, 4);
\fill (g) circle (2pt);
\coordinate[label=left:$f$] (f) at (2.5, 1.8);
\fill (f) circle (2pt);
\end{tikzpicture}
\end{center}
\end{document}
在代码中,我还修复了一些小问题,正如 Alenanno 在他的评论中提到的那样,纠正了坐标名称的重复。通过这个修正,我得到了:
这就是你要找的吗?