1

I'm having some trouble with drawing a couple of pictures in TikZ. It puts a different alignment on two adjacent pictures, as follows:

enter image description here

Also, how can I get the "and" to be centered vertically?

My apologies if this is a repeat question. It must have shown up before, but I didn't see it. Here is the code. Any other comments and suggestions are appreciated, since I'm just learning TikZ.

Edit: I gather that the different alignment is because of the label that's included on the bottom of the right one. But I'm still wondering how to get the "and" centered vertically.

\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}
2
  • Not on my computer right now, but try adding a % after the first \end{tikzpicture}. Also, why the dollar signs around \qquad?
    – Alenanno
    Commented Jul 24, 2016 at 20:34
  • Hmmm that didn't help. However, I think I figured out one part of it: the misalignment is due to a label that's in one, but not the other. But I still don't know how to get the "and" to align.
    – Eric Auld
    Commented Jul 24, 2016 at 20:50

1 Answer 1

2

A simple solution is use baseline=25mm option:

\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}

In code I also fix some glitches as mentioned Alenanno in his comment as correct duplication of coordinate names. With this correction I got:

enter image description here

Is this what you looking for?

1
  • Yeah, that's great!
    – Eric Auld
    Commented Jul 24, 2016 at 21:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .