我画了一个图,其中顶点位于网格上。我在一些相邻顶点之间有水平和垂直弧,我希望这些弧是水平的或垂直的。此外,弧应该具有相同的大小。下面是一个例子,其中一些弧不是完全水平的(并且大小也不相同)。
\documentclass[a4paper]{article}
\usepackage{tikz}
\newcommand{\fff}{\mathrm{f}}
\newcommand{\iii}{\mathrm{i}}
\newcommand{\ooo}{\mathrm{o}}
\newcommand{\sss}{\mathrm{s}}
\newcommand{\ppp}{\mathrm{p}}
\begin{document}
\begin{tikzpicture}
\begin{scope}[every node/.style={font=\scriptsize,anchor=base}]
\node (ooi) at (0,0) {$\ooo\ooo\iii$};
\node (oos) at (1,0) {$\ooo\ooo\sss$};
\node (oof) at (1,-1) {$\ooo\ooo\fff$};
\node (oop) at (0,-1) {$\ooo\ooo\ppp$};
\draw[->] (ooi) -- (oos);
\draw[->] (oop) -- (oof);
\draw[->] (ooi) -- (oop);
\draw[->] (oos) -- (oof);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
尝试一下这个方法:
\documentclass[a4paper]{article}
\usepackage{tikz}
\newcommand{\fff}{\mathrm{f}}
\newcommand{\iii}{\mathrm{i}}
\newcommand{\ooo}{\mathrm{o}}
\newcommand{\sss}{\mathrm{s}}
\newcommand{\ppp}{\mathrm{p}}
\begin{document}
\begin{tikzpicture}
\begin{scope}[every node/.style={minimum width=.65cm,minimum height=0.65cm,font=\scriptsize}]
\node (ooi) at (0,0) {\vphantom{/fp}$\ooo\ooo\iii$};
\node (oos) at (1,0) {\vphantom{/fp}$\ooo\ooo\sss$};
\node (oof) at (1,-1) {\vphantom{/fp}$\ooo\ooo\fff$};
\node (oop) at (0,-1) {\vphantom{/fp}$\ooo\ooo\ppp$};
\draw[->] (ooi) -- (oos);
\draw[->] (oop) -- (oof);
\draw[->] (ooi) -- (oop);
\draw[->] (oos) -- (oof);
\end{scope}
\end{tikzpicture}
\end{document}
答案2
我认为,绘制此图的规范方法是使用tikz-cd
。
\documentclass[a4paper]{article}
\usepackage{tikz-cd}
\newcommand{\fff}{\mathrm{f}}
\newcommand{\iii}{\mathrm{i}}
\newcommand{\ooo}{\mathrm{o}}
\newcommand{\sss}{\mathrm{s}}
\newcommand{\ppp}{\mathrm{p}}
\begin{document}
\begin{tikzcd}[cells={nodes={font=\scriptsize}}]
\ooo\ooo\iii \arrow[r] \arrow[d]& \ooo\ooo\sss \arrow[d]\\
\ooo\ooo\ppp \arrow[r]& \ooo\ooo\fff\\
\end{tikzcd}
\end{document}
答案3
使用相对的另一种解决方案positioning
:
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\newcommand{\fff}{\mathrm{f}}
\newcommand{\iii}{\mathrm{i}}
\newcommand{\ooo}{\mathrm{o}}
\newcommand{\sss}{\mathrm{s}}
\newcommand{\ppp}{\mathrm{p}}
\begin{document}
\begin{tikzpicture}
\begin{scope}[every node/.style={font=\scriptsize,anchor=base}]
\node (ooi) at (0,0) [minimum height=1.5em] {$\ooo\ooo\iii$};
\node (oos) [right=1.5em of ooi, minimum height=1.5em] {$\ooo\ooo\sss$};
\node (oof) [below=1.5em of oos, minimum height=1.5em] {$\ooo\ooo\fff$};
\node (oop) [below=1.5em of ooi, minimum height=1.5em] {$\ooo\ooo\ppp$};
\draw[->] (ooi) -- (oos);
\draw[->] (oop) -- (oof);
\draw[->] (ooi) -- (oop);
\draw[->] (oos) -- (oof);
\end{scope}
\end{tikzpicture}
\end{document}