这是我的代码:
\usemodule[tikz]
\usetikzlibrary{positioning,shapes}
\starttext
\tikzset{
cflow/.style={draw=black, ellipse, text centered, minimum width=1cm},
arr/.style = {->,>=stealth},
}
\startfloatcombination[distance=10pt]
\startplacetable[force,title={My Table}]
\starttable[|l|l|l|l|l|l|l|l|l|l]
\NC P \VL f1 \NC f2 \NC f3 \NC f4 \NC f5 \NC f6 \NC f7 \NC f8 \NC f9 \AR
\HL \NC A \VL c \NC b \NC c \NC - \NC - \NC - \NC - \NC a \NC - \AR
\stoptable
\stopplacetable
\startplacefigure[force,title={My Graph}]
\starttikzpicture
\node[cflow] (f1) {f1};
\node[cflow,right=of f1] (f8) {f8};
\node[cflow,right=of f8] (f2) {f2};
\node[cflow,below=of f1] (f4) {f4};
\node[cflow,below=of f8] (f6) {f6};
\node[cflow,below=of f2] (f5) {f5};
\node[cflow,below=of f4] (f9) {f9};
\node[cflow,below=of f6] (f7) {f7};
\node[cflow,below=of f5] (f3) {f3};
\draw[arr] (f1) -- (f4);
\draw[arr] (f1) -- (f6);
\draw[arr] (f2) -- (f5);
\draw[arr] (f3) -- (f7);
\draw[arr] (f4) -- (f9);
\draw[arr] (f6) to[bend left] (f7);
\draw[arr] (f7) to[bend left] (f6);
\draw[arr] (f8) -- (f2);
\stoptikzpicture
\stopplacefigure
\stopfloatcombination
\stoptext
其结果是:
为什么第二个标题放错了位置?我该如何修复?
答案1
我不太清楚内部发生了什么,但你必须用 包裹住tikzpicture
里面的内容framed
。实际上,这样\hbox
就足够了,但framed
语义上更好。我猜这与 TeX 此时处于 vmode 状态有关,它只是将 包裹tikzpicture
到宽度为 的 vbox 中\textwidth
。
此外,的语法force
是错误的,应该是location={force}
。但是,在此设置下它不起作用,因此我将其删除。
\usemodule[tikz]
\usetikzlibrary{positioning,shapes}
\starttext
\tikzset{
cflow/.style={draw=black, ellipse, text centered, minimum width=1cm},
arr/.style = {->,>=stealth},
}
\startfloatcombination[distance=10pt]
\startplacetable[title={My Table}]
\starttable[|l|l|l|l|l|l|l|l|l|l]
\NC P \VL f1 \NC f2 \NC f3 \NC f4 \NC f5 \NC f6 \NC f7 \NC f8 \NC f9 \AR
\HL \NC A \VL c \NC b \NC c \NC - \NC - \NC - \NC - \NC a \NC - \AR
\stoptable
\stopplacetable
\startplacefigure[title={My Graph}]
\startframed[frame=off,offset=none]
\starttikzpicture
\node[cflow] (f1) {f1};
\node[cflow,right=of f1] (f8) {f8};
\node[cflow,right=of f8] (f2) {f2};
\node[cflow,below=of f1] (f4) {f4};
\node[cflow,below=of f8] (f6) {f6};
\node[cflow,below=of f2] (f5) {f5};
\node[cflow,below=of f4] (f9) {f9};
\node[cflow,below=of f6] (f7) {f7};
\node[cflow,below=of f5] (f3) {f3};
\draw[arr] (f1) -- (f4);
\draw[arr] (f1) -- (f6);
\draw[arr] (f2) -- (f5);
\draw[arr] (f3) -- (f7);
\draw[arr] (f4) -- (f9);
\draw[arr] (f6) to[bend left] (f7);
\draw[arr] (f7) to[bend left] (f6);
\draw[arr] (f8) -- (f2);
\stoptikzpicture
\stopframed
\stopplacefigure
\stopfloatcombination
\stoptext
如果你不想每次处于 vmode 时都小心地将 包装tikzpicture
进去,你也可以调整 的定义。framed
\start...\stoptikzpicture
\unprotect
\let\old_start_tikz_picture=\starttikzpicture
\let\old_stop_tikz_picture =\stoptikzpicture
\newconditional\tikz_picture_started_in_vmode
\starttexdefinition unexpanded starttikzpicture
\setfalse\tikz_picture_started_in_vmode
\ifvmode
\startframed[frame=off,offset=none]
\settrue\tikz_picture_started_in_vmode
\fi
\old_start_tikz_picture
\stoptexdefinition
\starttexdefinition unexpanded stoptikzpicture
\old_stop_tikz_picture
\ifconditional\tikz_picture_started_in_vmode
\stopframed
\fi
\stoptexdefinition
\protect