我正在嘗試創建一個相當簡單的圖表,但我不知道如何讓左側的多個箭頭不離開節點的中心。
答案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
。