我已经花了几个小时寻找解决问题的方法,但我不得不承认我真的不知道如何解决它。我画了一个带有垂直文本的节点,并有一条线从该节点延伸到一个框。但是当我尝试添加一条从第一个框延伸到另一个框的线时,它没有到达该线。
\documentclass{article}
\usepackage{tikz}
\makeatletter
\protected\def\vvv#1{\leavevmode\bgroup\vbox\bgroup\xvvv#1\relax}
\def\xvvv{\afterassignment\xxvvv\let\tmp= }
\def\xxvvv{%
\ifx\tmp\@sptoken\egroup\ \vbox\bgroup\let\next\xvvv
\else\ifx\tmp\relax\egroup\egroup\let\next\relax
\else
%\hbox{\tmp}%original
\hbox to 1.1em{\hfill\tmp\hfill}% centred
\let\next\xvvv\fi\fi
\next}
\makeatother
\begin{document}
\begin{center}
\begin{tikzpicture}
\tikzset{
rect/.style={
draw,
rectangle,
minimum height=2em,
minimum width=4em,
text width={width("Transformations")+2pt},
text centered
}
}
\node (app) at (0,0) {\vvv{APPLICATION}};
\node [rect] (trans) at (8,0) {Transformations};
\draw[->] (app) -- (trans);
\node [rect] (dp_list) at (3.5,1.5) {display list};
\node (in) at (1.8,0) {};
\draw[->] (in) |- (dp_list);
\end{tikzpicture}
\end{center}
\end{document}
此代码在我的电脑上产生以下结果。我希望两条线在点 (1.8,0) 处相切。
提前感谢您的回答,Jean。
答案1
节点周围有一些默认填充(我认为)。
您可以直接使用坐标:
\documentclass{article}
\usepackage{tikz}
\makeatletter
\protected\def\vvv#1{\leavevmode\bgroup\vbox\bgroup\xvvv#1\relax}
\def\xvvv{\afterassignment\xxvvv\let\tmp= }
\def\xxvvv{%
\ifx\tmp\@sptoken\egroup\ \vbox\bgroup\let\next\xvvv
\else\ifx\tmp\relax\egroup\egroup\let\next\relax
\else
%\hbox{\tmp}%original![enter image description here][1]
\hbox to 1.1em{\hfill\tmp\hfill}% centred
\let\next\xvvv\fi\fi
\next}
\makeatother
\begin{document}
\begin{center}
\begin{tikzpicture}
\tikzset{
rect/.style={
draw,
rectangle,
minimum height=2em,
minimum width=4em,
text width={width("Transformations")+2pt},
text centered
}
}
\node (app) at (0,0) {\vvv{APPLICATION}};
\node [rect] (trans) at (8,0) {Transformations};
\draw[->] (app) -- (trans);
\node [rect] (dp_list) at (3.5,1.5) {display list};
\draw[->] (1.8,0) |- (dp_list);
\end{tikzpicture}
\end{center}
\end{document}
答案2
正如 David 和 Pier 所指出的,空节点自动具有内部和外部分离距离,即inner sep
和outer sep
。要查看它,请将draw
选项添加到临时节点(in)
,您就会看到。
有一种特殊的节点形状没有框,因此没有安装任何分隔符,即coordinate
。它只有一个锚点center
,当您通过别名引用坐标时,它是唯一假定的坐标。
此外,您可以通过间隔开来简化垂直文本输入。
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node[text width=1em,draw,align=center] (app) at (0,0) {A P P L I C A T I O N};
\node[draw] (disp) at (3,1) {display};
\node[draw] (t) at (4,-1) {trafo};
\draw[->] (app) -- (2,0) coordinate (a) (a) |- (disp);
\draw[->] (a) |- (t);
\end{tikzpicture}
\end{document}
答案3
无论您是否在节点中写入内容,节点都具有一些“内部空间”。
就您而言,只需从节点的中心画一条线:in.center
。
\documentclass{article}
\usepackage{tikz}
\makeatletter
\protected\def\vvv#1{\leavevmode\bgroup\vbox\bgroup\xvvv#1\relax}
\def\xvvv{\afterassignment\xxvvv\let\tmp= }
\def\xxvvv{%
\ifx\tmp\@sptoken\egroup\ \vbox\bgroup\let\next\xvvv
\else\ifx\tmp\relax\egroup\egroup\let\next\relax
\else
%\hbox{\tmp}%original
\hbox to 1.1em{\hfill\tmp\hfill}% centred
\let\next\xvvv\fi\fi
\next}
\makeatother
\begin{document}
\begin{center}
\begin{tikzpicture}
\tikzset{
rect/.style={
draw,
rectangle,
minimum height=2em,
minimum width=4em,
text width={width("Transformations")+2pt},
text centered
}
}
\node (app) at (0,0) {\vvv{APPLICATION}};
\node [rect] (trans) at (8,0) {Transformations};
\draw[->] (app) -- (trans);
\node [rect] (dp_list) at (3.5,1.5) {display list};
\node (in) at (1.8,0) {};
\draw[->] (in.center) |- (dp_list);
\end{tikzpicture}
\end{center}
\end{document}
或者您可以通过更改节点的选项来消除节点中的空白inner sep
。
\node [inner sep=0pt] (in) at (1.8,0) {};
然后使用您的代码:
\draw[->] (in) |- (dp_list);