我正在尝试使用 tikzpicture 在 latex 中创建此图形:
这是我目前的代码:
\usepackage{tikz}
\begin{tikzpicture}[node distance={15mm}, thick, main/.style = {draw, circle}]
\node[main] (1) {$_{1,1}$ };
\node[main] (2) [below right of=1] {$_{2,1}$ };
\node[main] (3) [above right of=2] {$_{1,2}$ };
\node[main] (4) [below right of=3] {$_{2,2}$ };
\draw (1) to [out=45, in=135] (3);
\draw (1) to [out=135,in=45] (3);
\draw (1) to (2);
\draw (1) to [out=193,in=59,looseness=4] (4);
\draw (2) to (3);
\draw (2) to [out=180+45, in=135+180] (4);
\draw (2) to [out=180+135,in=180+45] (4);
\draw (3) to (4);
\end{tikzpicture}
我如何添加不与任何现有边交叉的边,或者如何调整曲线的方向或以其他方式创建第一个图形?
注意:应该保留边缘的初始位置,从左下方开始的边缘 1,1 通向右上角的 2,2。
答案1
我认为你的问题应该通过操作来处理controls
。
这是一个解决方案:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[node distance={15mm}, thick, main/.style = {draw, circle}]
\node[main] (1) {$_{1,1}$ };
\node[main] (2) [below right of=1] {$_{2,1}$ };
\node[main] (3) [above right of=2] {$_{1,2}$ };
\node[main] (4) [below right of=3] {$_{2,2}$ };
\draw (1) to [out=45, in=135] (3);
\draw (1) to [out=135,in=45] (3);
\draw (1) to (2);
\draw (-.32,-.2) .. controls(-2.1,1.5) and (5.4,2) .. (3.45,-.8);
\draw (2) to (3);
\draw (2) to [out=180+45, in=135+180] (4);
\draw (2) to [out=180+135,in=180+45] (4);
\draw (3) to (4);
\end{tikzpicture}
\end{document}
输出:
您可以根据需要轻松地在线上移动点。\draw (-.32,-.2) .. controls(-2.1,1.5) and (5.4,2) .. (3.45,-.8);
起点是(-.32,-.2)
,终点是(3.45,-.8)
。这些点(-2.1,1.5) and (5.4,2)
控制曲线的形状。
答案2
无需controls
在此处调用(但这是一个很好的解决方案)。只需从边缘开始的角度进行操作即可。在这里,我只是使用\draw (1.-160) to...
并玩弄了out
值。此外,我还添加了outer sep=0 pt
节点定义。
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[node distance={15mm}, thick, main/.style = {draw, circle,outer sep=0pt}]
\node[main] (1) {$_{1,1}$ };
\node[main] (2) [below right of=1] {$_{2,1}$ };
\node[main] (3) [above right of=2] {$_{1,2}$ };
\node[main] (4) [below right of=3] {$_{2,2}$ };
\draw (1) to [out=45, in=135] (3);
\draw (1) to [out=135,in=45] (3);
\draw (1) to (2);
\draw (1.-160) to [out=140,in=59,looseness=2] (4); % <------ HERE
\draw (2) to (3);
\draw (2) to [out=180+45, in=135+180] (4);
\draw (2) to [out=180+135,in=180+45] (4);
\draw (3) to (4);
\end{tikzpicture}
\end{document}