6

I want to draw the following commutative diagram in latex (tikz).

enter image description here

I have tried the following code:

\begin{tikzcd}
    A \arrow{rr}{f} \arrow[swap]{dr}{g} & & B \arrow{ur}{h} \\[10pt]
    & C  
\end{tikzcd}
\]

But this is not giving expected result. Also how to bring vertical equal symbol and then down D as in the figure.

3 Answers 3

2

For a comparation with TikZ

enter image description here

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\def\a{1.5} \def\b{2}
\path
(-\a,0) node (A) {$A$}      
(\a,0) node (B) {$B$}
(0,-\b) node[align=center] (C) {$C$\\[-1mm]\rotatebox{90}{=}\\[-1mm]$D$};
\begin{scope}[nodes={midway,scale=.75}]
\draw[->] (A)--(B) node[above]{$f$};
\draw[->] (A)--(C.120) node[left]{$g$};
\draw[->] (C.60)--(B) node[right]{$h$};
\end{scope}
\end{tikzpicture}   
\end{document}

... and Asymptote (almost the same figure as above)

real a=1.5cm, b=2cm; // need to specify the unit (cm)
pair A=(-a,0), B=(a,0), C=(0,-b);
object
oA=draw("",ellipse,A,xmargin=3mm,Draw(white)),   /// box or roundbox is ok!
oB=draw("",ellipse,B,xmargin=3mm,Draw(white)),
oC=draw("",ellipse,C,xmargin=3mm,Draw(white));

label("$A$",A); label("$B$",B); label("$C$",C);
label(rotate(90)*"$=$",point(oC,S));
label("$D$",point(oC,S)+(0,-.4cm));

pair
A1=point(oA,E), A2=point(oA,dir(-60)),
B1=point(oB,W), B2=point(oB,dir(-120)),
C1=point(oC,dir(135)), C2=point(oC,dir(45))
;

DefaultHead=TeXHead;
draw(Label(scale(.75)*"$f$",align=N),A1--B1,Arrow());
draw(scale(.75)*"$g$",A2--C1,Arrow());
draw(scale(.75)*"$h$",C2--B2,Arrow());

Update We can control almost anything with plain TikZ. To change arrowhead, length of arrow, distance C,D:

enter image description here

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
[>={Classical TikZ Rightarrow[length=1.2mm]}]
\def\a{1.5} \def\b{2}
\path[nodes={inner sep=1pt}]
(-\a,0) node (A) {$A$}      
(\a,0) node (B) {$B$}
(0,-\b) node[align=center] (C) {$C$\\[-1.3mm]\rotatebox{90}{=}\\[-1.5mm]$D$};
\begin{scope}[nodes={midway,scale=.75}]
\draw[->] (A)--(B) node[above]{$f$};
\draw[->] (A)--(C.120) node[left]{$g$};
\draw[->] (C.60)--(B) node[right]{$h$};
\end{scope}
\end{tikzpicture}   
\end{document}
5
  • Thanks. I have accepted the first one. How to increase the head`of the arrow a little bit bigger as in the above answers ? Also how to increase the length of the arrow ?
    – learner
    Jan 23, 2021 at 8:40
  • @M.A.SARKAR to increase the length of the arrows, change inner sep in \path[nodes={inner sep=1pt}] (-\a,0) node (A) {$A$} (\a,0) node (B) {$B$}
    – Black Mild
    Jan 23, 2021 at 8:49
  • @M.A.SARKAR for bigger arrow head, we can put [>={Classical TikZ Rightarrow[length=1.2mm]}] after \begin{tikzpicture} (the library arrows.meta needed). I updated code according to your request
    – Black Mild
    Jan 23, 2021 at 8:58
  • A final question. Is there any way to decrease the distance between C and D ?
    – learner
    Jan 23, 2021 at 8:59
  • @M.A.SARKAR just update the code, please see [-1.3mm] [-1.5mm]
    – Black Mild
    Jan 23, 2021 at 9:06
8

Use the correct syntax for the arrows. I propose this code:

\documentclass{article}
\usepackage{amsmath} 
\usepackage{tikz-cd} 

\begin{document}

\begin{tikzcd}[row sep=4em, column sep=2em]
    A \arrow[rr, "f"] \arrow[swap, dr, "g"] & & B \arrow[dl, "h"] \\
    & C \\[-4.6em]
 & \overset{ \rotatebox{90}{=}}{D}
\end{tikzcd}

\end{document} 

enter image description here

2
  • Thanks. How to reverse the arrow h ?
    – learner
    Jan 23, 2021 at 8:24
  • Move it next to B and replace rr with ll.
    – Bernard
    Jan 23, 2021 at 9:28
7

I add also my proposal:

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}
\usepackage{tikz-cd}


\begin{document}
\begin{tikzcd}[row sep= 1cm, column sep=.6cm]
A \arrow[rd, "g"'] \arrow[rr, "f"] & & B \arrow[ld, "h"] \\
& \underset{\textstyle{D}}{\overset{\textstyle{C}}{\shortparallel}} &                  
\end{tikzcd}

\end{document}

enter image description here

You must log in to answer this question.

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