
昨晚我製作了這一部分LaTeX
,使用相對坐標用箭頭連接節點:
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning} %for [above], [below] and shit.
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\begin{document}
\begin{figure}[generic_scheme]
\tikzstyle{block}=[draw,shape=rectangle, minimum width=2.5cm,
minimum height=1cm]
\tikzstyle{f_arrow}=[->, thick]
\tikzstyle{d_arrow}=[<->, thick]
\begin{tikzpicture}[auto]
\node[block] (nuc) [] {Intel NUC};
\node[block] (power) [above=of nuc, yshift=0.5cm]
{Power\\Circuit};
\node[block] (smps) [left=of nuc, yshift=1.25cm] {SMPS};
\draw[f_arrow] (power.south) -- (nuc.north);
\draw[f_arrow] (power.west)++(0, -0.25) --
(smps.east)++(0, 0.25);
\draw[d_arrow] (nuc.west)++(0, 0.25) --
(smps.east)++(0, -0.25);
\end{tikzpicture}
\end{figure}
\end{document}
今天我嘗試了這種替代方法,使用yshift
而不是相對座標:
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning} %for [above], [below] and shit.
\usetikzlibrary{arrows}
\usetikzlibrary{shapes}
\begin{document}
\begin{figure}[generic_scheme]
\tikzstyle{block}=[draw,shape=rectangle, minimum width=2.5cm,
minimum height=1cm]
\tikzstyle{f_arrow}=[->, thick]
\tikzstyle{d_arrow}=[<->, thick]
\begin{tikzpicture}[auto]
\node[block] (nuc) [] {Intel NUC};
\node[block] (power) [above=of nuc, yshift=0.5cm]
{Power\\Circuit};
\node[block] (smps) [left=of nuc, yshift=1.25cm] {SMPS};
\draw[f_arrow] (power.south) -- (nuc.north);
\draw[f_arrow] ([yshift=-0.25cm]power.west) --
([yshift=0.25cm]smps.east);
\draw[d_arrow] ([yshift=0.25cm]nuc.west) --
([yshift=-0.25cm]smps.east);
\end{tikzpicture}
\end{figure}
\end{document}
所以,我的問題是,這些看似「相同」的部分有什麼不同LaTeX
?當我試圖理解它是如何運作的時,我是否錯過了一些瑣碎的relative coordinate
事情yshift
?或者這只是我的Ubuntu 14.04
pdfTeX 3.1415926-2.5-1.40.14 安裝中的錯誤?
答案1
這裡的問題是使用
\draw[d_arrow] (nuc.west)++(0, 0.25) --
(smps.east)++(0, -0.25);
你是不是從座標中添加/減去 0.25,而不影響路徑。您正在移動鉛筆,如以下簡單範例所示(請參閱兩種情況下線條的結束位置以及箭頭尖端的位置):
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (6,3);
\draw (0,0)++(0.5,0.5) -- (2,2)++(0.5,0.5);
\draw[->] (3,0)++(0.5,0.5) -- (5,2)++(0.5,0.5);
\end{tikzpicture}
\end{document}
序列
\draw[->] (3,0)++(0.5,0.5) -- (5,2)++(0.5,0.5);
可以看作:
- 將鉛筆移至 (3,0)。
- 將其在 x 和 y 座標上額外移動 0.5(但不繪製)。
- 開始繪製到 (5,2)。
- 再次將鉛筆在兩個座標上移動 0.5(但現在沒有繪圖)。
- 放置箭頭。
如果您想添加值,請使用班次或calc
庫(這裡可能有點矯枉過正):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw (0,0) grid (6,3);
\draw[->] ([shift={(0.5,0.5)}]0,0) -- ([shift={(0.5,0.5)}]2,2);
\draw[->] ( $ (3,0) +(0.5,0.5) $ ) -- ( $ (5,2) + (0.5,0.5) $ );
\end{tikzpicture}
\end{document}