我尝试绘制下面的图:
我对应的代码是
\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[={nodes={draw}}]
1\arrow{drr}&& && && &&& & & \\
&&2\arrow{drr}\arrow[dashed]{rrrrrrrr}&& && &&& &5\arrow{ddl}\arrow{ddr}& \\
&& &&3\arrow{drr}&& &&& & & \\
&& && &&4\arrow[dashed]{rrr}&&&6& &7
\end{tikzcd}
\end{document}
我的做法很“暴力”,插入的文件看上去太大,与原图形成鲜明对比,图片上的数字太小,就像这样:
希望您能提供补救措施:)
答案1
删除空单元格并改用键row sep
和column sep
,您可以实现所需的任何纵横比/缩放比例。
调整长度0.25cm
并0.5cm
适应口味。
\documentclass{standalone}
\usepackage{tikz-cd}
\begin{document}
\begin{tikzcd}[row sep=0.25cm,column sep=0.5cm]
1\arrow{dr}& & & & & & \\
&2\arrow{dr}\arrow[dashed]{rrrr}& & & &5\arrow{ddl}\arrow{ddr}& \\
& &3\arrow{dr}& & & & \\
& & &4\arrow[dashed]{r}&6& &7
\end{tikzcd}
\end{document}
答案2
更新:
正确的方法是使用未弃用,below = of
而不是旧的below of =
,将是以下内容(参见为什么“上方”的定位高度与“右上方”的不同?):
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc}
\begin{document}
\begin{tikzpicture}[
thick, on grid]
\node (n1) {1};
\node [below right = of n1] (n2) {2};
\node [below right = of n2] (n3) {3};
\node [below right = of n3] (n4) {4};
\node [right = of n4] (n6) {6};
\node [above right = of n6] (phantom) {};
\node [above = of phantom] (n5) {5};
\node [below right = of phantom] (n7) {7};
\begin{scope}[->]
\draw (n1) -- (n2);
\draw (n2) -- (n3);
\draw (n3) -- (n4);
\draw (n5) -- (n6);
\draw (n5) -- (n7);
\draw[dashed] (n2) -- (n5);
\draw[dashed] (n4) -- (n6);
\end{scope}
\end{tikzpicture}
\end{document}
这导致:
旧答案(暂时留作参考......):
这是有效的,尽管我不知道为什么需要yshift
在节点 5 上...
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc}
\begin{document}
\begin{tikzpicture}[
thick, node distance=1cm]
\node (n1) {1};
\node [below right of=n1] (n2) {2};
\node [below right of=n2] (n3) {3};
\node [below right of=n3] (n4) {4};
\node [right of=n4] (n6) {6};
\node [above right of=n6] (fake) {};
\node [above of=fake, yshift=-0.3cm] (n5) {5}; %% WHY?
\node [below right of=fake] (n7) {7};
\begin{scope}[->]
\draw (n1) -- (n2);
\draw (n2) -- (n3);
\draw (n3) -- (n4);
\draw (n5) -- (n6);
\draw (n5) -- (n7);
\draw[dashed] (n4) -- (n6);
\draw[dashed] (n2) -- (n5);
\end{scope}
\end{tikzpicture}
\end{document}
或者,没有奇怪的yshift
:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning,calc}
\begin{document}
\begin{tikzpicture}[
thick, node distance=1cm]
\node (n1) {1};
\node [below right of=n1] (n2) {2};
\node [below right of=n2] (n3) {3};
\node [below right of=n3] (n4) {4};
\node [right of=n4] (n6) {6};
\node [right = 3cm of n2] (n5) {5};
\node [right = 1.5cm of n6] (n7) {7};
\begin{scope}[->]
\draw (n1) -- (n2);
\draw (n2) -- (n3);
\draw (n3) -- (n4);
\draw (n5) -- (n6);
\draw (n5) -- (n7);
\draw[dashed] (n4) -- (n6);
\draw[dashed] (n2) -- (n5);
\end{scope}
\end{tikzpicture}
\end{document}
...现在 2 和 5 之间的线是完全水平的。