TransWikia.com

How to plot the commutative triangle diagram in Tikz?

TeX - LaTeX Asked on March 7, 2021

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

For a comparation with TikZ

enter image description here

documentclass[tikz]{standalone}
begin{document}
begin{tikzpicture}
defa{1.5} defb{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]}]
defa{1.5} defb{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}

Correct answer by Black Mild on March 7, 2021

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

Answered by Bernard on March 7, 2021

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

Answered by Sebastiano on March 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP