I'm trying to draw a diagram of a function that is Injective but not Surjective. I'm using standalone, and want the end result to look like the this image:
My code is modified from https://tex.stackexchange.com/a/167913/197489 without much luck. Here is my LaTeX
\documentclass[crop,tikz]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
\newcommand{\DrawBox}[3][]{%
\tikz[overlay,remember picture]{
\draw[black,#1]
($(#2)+(-0.5em,2.0ex)$) rectangle
($(#3)+(0.75em,-0.75ex)$);}
}
%Draw an arrow diagram that represents a function that is an injection but is not a surjection.
\begin{document}
\begin{tikzcd}[scale=.1]
\tikzmark{Atop} a \arrow[r] & \tikzmark{Btop}x \\
b \arrow[r] & y \\
\tikzmark{Abottom}& z\tikzmark{Bbottom} \\
\DrawBox[thick, red]{Atop}{Abottom}
\DrawBox[thick, blue]{Btop}{Bbottom}
\end{tikzcd}
\end{document}
Which results in
Any suggestions?
I'm using MiKTeX in TeXStudio if that helps.
tikzpicture
s, which causes the problems.\tikzmark
command starts with\tikz
which means that it creates atikzpicture
.