我正在尝试创建一个相当简单的图表,但我不知道如何让左侧的多个箭头不离开节点的中心。
答案1
两个选项;使用锚点和一些移位,并使用<name>.<angle >
语法:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[draw,minimum size=2cm] (x) {X};
\draw[->] ([yshift=-10pt]x.west) -- node[fill=white] {a} +(-1cm,0pt);
\draw[->] ([yshift=10pt]x.west) -- node[fill=white] {b} +(-1cm,0pt);
\draw[->] (x.120) -- node[fill=white] {c} +(0pt,1cm);
\draw[->] (x.60) -- node[fill=white] {d} +(0pt,1cm);
\end{tikzpicture}
\end{document}
作为克劳迪奥·菲安德里诺提到过他的评论,另一个选择是使用calc
库,因此偏移不是绝对的,但可以根据锚点来计算:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node[draw,minimum size=2cm] (x) {X};
\draw[->] ([yshift=-10pt]x.west) -- node[fill=white] {a} +(-1cm,0pt);
\draw[->] ([yshift=10pt]x.west) -- node[fill=white] {b} +(-1cm,0pt);
\draw[->] (x.120) -- node[fill=white] {c} +(0pt,1cm);
\draw[->] (x.60) -- node[fill=white] {d} +(0pt,1cm);
\draw[->]
( $ (x.north east)!0.5!(x.east) $ ) --
node[fill=white] {e}
+(1cm,0pt);
\draw[->]
( $ (x.east)!0.5!(x.south east) $ ) --
node[fill=white] {f}
+(1cm,0pt);
\end{tikzpicture}
\end{document}
在上面的例子中,表示坐标位于和( $ (x.north east)!0.5!(x.east) $ )
中间的点。x.north east
x.east
答案2
PSTricks 解决方案:
\documentclass{article}
\usepackage{pstricks-add}
\usepackage{xfp}
\newcommand*\Width{\fpeval{2*\arrowLength+\boxLength}}
\newcommand*\Height{\boxLength}
\def\arrowLength{3}
\def\boxLength{3}
\begin{document}
\begin{pspicture}(\Width,\Height)
\psset{arrows = ->}
\psframe(\arrowLength,0)(\fpeval{\arrowLength+\boxLength},\boxLength)
\rput(\fpeval{\arrowLength+0.5*\boxLength},\fpeval{0.5*\boxLength}){X}
\pcline(\arrowLength,\fpeval{\boxLength/3})(0,\fpeval{\boxLength/3})
\ncput*{a}
\pcline(\arrowLength,\fpeval{2/3*\boxLength})(0,\fpeval{2/3*\boxLength})
\ncput*{b}
\pcline(\fpeval{2*\arrowLength+\boxLength},\fpeval{0.5*\boxLength})%
(\fpeval{\arrowLength+\boxLength},\fpeval{0.5*\boxLength})
\ncput*{c}
\end{pspicture}
\end{document}
请注意,绘图是“自动化的”,您所要做的就是选择\arrowLength
和的值\boxLength
。