我必须画很多单独的线,但又不想把\draw[->]
它们都放在前面。我以前也这样做过,所以我不知道为什么它不起作用。它总是把箭头放在最后一行。
一些缩短和简化的代码(但仍然是同样的问题):
\documentclass[11pt]{article}
\usepackage{fp}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}
\newcommand{\inputNode}[3]{\node[shape=rectangle,draw=black,fill=green!25,thin,inner sep=0,minimum size=8mm,label=above:$#3$](In#2)at(#1){In$_#2$};}
\newcommand{\junctionNode}[5]
{
\node[shape=rectangle,draw=black,fill=blue!10,thin,inner sep=0,minimum height=1cm,minimum width=#3cm](Box#2)at(#1){$#5$};
\FPeval\inputs {clip(#3-1)}
\foreach \int in {0,1,...,\inputs}
{ \path let
\p1=(Box#2.north west), \p2=(Box#2.north east), \n1={(\x2-\x1-20)/\inputs}
in
node(Box#2-in\int) at (\x1+10+\n1*\int,\y1){}
;}}
\begin{tikzpicture}
\inputNode{1,8}{1}{Input1}
\inputNode{3.5,8}{2}{Input2}
\inputNode{6,8}{3}{Input3}
\inputNode{8.5,8}{4}{Input4}
\junctionNode{3,4}{1}{4}{2}{Junction1}
\draw [->,>=stealth]
(In1) to [out=270,in=90] (Box1-in0.center)
(In2) to [out=270,in=90] (Box1-in1.center)
(In3) to [out=270,in=90] (Box1-in2.center)
(In4) to [out=270,in=90] (Box1-in3.center);
\end{tikzpicture}
\end{document}
答案1
使用edge
操作符代替to
运算符可以解决问题:
\documentclass[11pt]{article}
\usepackage{fp}
\usepackage{tikz}
\usetikzlibrary{arrows,calc}
\begin{document}
\newcommand{\inputNode}[3]{%
\node[
shape=rectangle,
draw=black,
fill=green!25,
thin,
inner sep=0,
minimum size=8mm,
label=above:{#3},
] (In#2) at (#1) {In$_#2$};%
}
\newcommand{\junctionNode}[5]{
\node[
shape=rectangle,
draw=black,
fill=blue!10,
thin,
inner sep=0,
minimum height=1cm,
minimum width=#3cm,
] (Box#2) at (#1) {#5};%
\FPeval\inputs {clip(#3-1)}
\foreach \int in {0,1,...,\inputs} {
\path let
\p1=(Box#2.north west),
\p2=(Box#2.north east),
\n1={(\x2-\x1-20)/\inputs}
in
node(Box#2-in\int) at (\x1+10+\n1*\int,\y1){}
;%
}%
}
% Spacer %
\begin{tikzpicture}
\inputNode{1,8}{1}{Input1}
\inputNode{3.5,8}{2}{Input2}
\inputNode{6,8}{3}{Input3}
\inputNode{8.5,8}{4}{Input4}
\junctionNode{3,4}{1}{4}{2}{Junction1}
\path [->,>=stealth]
(In1) edge [out=270,in=90] (Box1-in0.center)
(In2) edge [out=270,in=90] (Box1-in1.center)
(In3) edge [out=270,in=90] (Box1-in2.center)
(In4) edge [out=270,in=90] (Box1-in3.center);
\end{tikzpicture}
\end{document}
此外,我还将文本移出了数学模式。像“Input”这样的单词在数学模式中不会被设置为单词,而是被设置为变量的乘积我,n,页,你, 和吨。如果字体应该是斜体,则可以使用\textit{...}
或$\mathit{...}$
。与数字结合,\textit{Input1}
也使用斜体字体表示数字。