我的线条太长了。我想把它们分开。我该怎么做?这就是我现在的做法。
\tikzset{block/.style={draw,fill=blue!60,minimum width=1.1 em, minimum height= 1em, rounded corners= 4pt}}
%\centering
\begin{figure}[h]
\fcolorbox{blue}{white}{
%\centering
\begin{tikzpicture}[remember picture]
\draw[help lines](-2,-1)grid(4,2); % shows background
\coordinate (origin) at (0,0);
\coordinate (text1) at (1,1);
\node at (origin) {*};
\node at (text1) {\mytikzmark{block5}{\textcolor{blue}{function}} \mytikzmark{block6}{[x,y,z]} = \mytikzmark{block7}{\textcolor{red}{funName}}( \mytikzmark{block9}{\textcolor{green}{in1},\textcolor{green}{in2})}};
\node at (-1.5, 0) (block2) {\textcolor{blue}{Must have the reserved word function}};
\draw[blue,->] (block2) -- (block5);
\node at (0, -1) (block3) {If more than one output, must be in brackets};
\draw[black,->] (block3) -- (block6);
\node at (3, -0.5) (block4) {\textcolor{red}{Function name should match MATLAB file name}};
\draw[red,->] (block4) -- (block7);
\node at (3.5, 1.5) (block8) {\textcolor{green}{Inputs must be specified}};
\draw[green,->] (block8) -- (block9);
\end{tikzpicture}
}
\end{figure}
这就是我想要得到的
答案1
这仅是定义更多\tikzmark
位置的问题:
和
- 使用语法计算中点
($(A)!0.5(B)$)
。 - 设置
text width
以便行可以换行 - 用于
anchors
定位文本 - 使用
shorten >=
和shorten <=
调整箭头的末端。
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\mytikzmark}[1]{\tikz[overlay,remember picture] \node[baseline] (#1) {};}
\begin{document}
\tikzset{block/.style={draw,fill=blue!60,minimum width=1.1 em, minimum height= 1em, rounded corners= 4pt}}
%\centering
\begin{figure}[h]
\fcolorbox{blue}{white}{
%\centering
\begin{tikzpicture}[remember picture,]
\draw[help lines](-2,-1)grid(4,2); % shows background
\coordinate (origin) at (0,0);
\coordinate (text1) at (1,1);
%\node at (origin) {*};
\node at (text1) {\mytikzmark{block5}{\textcolor{blue}{function}} \mytikzmark{block6}{[x,y,z]}\mytikzmark{block6b} = \mytikzmark{block7}{\textcolor{red}{funName}}( \mytikzmark{block9}{\textcolor{green}{in1}\mytikzmark{block10}, \textcolor{green}{in2})}};
\node [text width=4.0cm, anchor=east] at (0, 0) (block2) {\textcolor{blue}{Must have the reserved word function}};
\draw[blue,-stealth, thick, shorten >= 0.5ex, shorten <= -0.5ex] (block2) -- ($(block5)!0.5!(block6)$);
\node [text width=4.0cm, anchor=north] at (0, -1) (block3) {If more than one output, must be in brackets};
\draw[black,-stealth, thick, shorten >= 0.7ex, shorten <= -0.5ex]
(block3) -- ($(block6)!0.5!(block6b)$);
\node [text width=5.0cm, anchor=north] at (3, 0) (block4) {\textcolor{red}{Function name should match MATLAB file name}};
\draw[red,-stealth, thick, shorten >= 0.7ex, shorten <= -0.5ex]
(block4) -- ($(block7)!0.5!(block9)$);
\node [text width=4.0cm, anchor=south] at (3.5, 1.5) (block8) {\textcolor{green}{Inputs must be specified}};
\draw[green,-stealth, thick, shorten >= 1.3ex, shorten <= -0.5ex]
(block8) -- (block10);
\end{tikzpicture}
}
\end{figure}
\end{document}