\documentclass[convert = false, tikz]{standalone}
\usepackage{float}
\begin{document}
\begin{tikzpicture}[every node/.style={midway}]
\matrix[column sep={4em,between origins}, row sep={2em}] at (0,0) {
\node(A) {$A$} ; & \node(B) {$B$}; \\
\node(C) {$C$} ; & \node (D) {$D$};\\
};
\draw[<-] (C) -- (D) node[anchor=east]{};
\draw[->] (A) -- (B) node[anchor=south] {};
\draw[->] (B) -- (D) node[anchor=west] {};
\draw[->] (C) -- (D) node[anchor=north] {};
\end{tikzpicture}
\end{document}
这里,我尝试替换$A$
by$A(X)$
和$B$
by $B(Y)$
,但不起作用。您能建议我一些方法来实现这一点吗?
答案1
对于交换图,我建议你使用功能强大且用途广泛的tikz-cd
包裹:
\documentclass[convert = false, tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}
A(x)\ar{r} & B(y)\ar{d} \\
C\ar{r} & D
\end{tikzcd}
\end{document}
答案2
使用以下解决方案array
:
\documentclass{article}
\begin{document}
\begin{equation}
\setlength\arraycolsep{3pt}
\renewcommand\arraystretch{1.3}
\begin{array}{ccc}
A(x) & \rightarrow & B(y) \\
& & \downarrow \\
C & \rightarrow & D
\end{array}
\end{equation}
\end{document}
注意:如果图中的元素具有大致相同的宽度,那么看起来当然最好。
答案3
使用 tkz-graph :
\documentclass[11pt]{article}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
% Verices
\SetGraphUnit{4} % 4 cm between each nodes except local changes
\GraphInit[vstyle=Empty] % only label and no drawing around nodes
\SetVertexMath % all the labels are in math mode
\Vertex[L=A(x)]{a} \EA[L=B(y)](a){b}
\SO[L=C,,unit=2](a){c} \SO[L=D,unit=2](b){d} % unit = 2 change the distance
% Edges
\tikzset{EdgeStyle/.style = {->}} % style of edges
\Edges (a,b,d) \Edges (c,d)
\end{tikzpicture}
\end{document}