3

My lines are too long. I want to break them. How should I do this? this is how I am doing it now enter image description here

\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}

this is what I'm trying to get enter image description here

MAS
  • 567

1 Answers1

1

Its just a matter of defining a few more \tikzmark locations:

enter image description here

and

  • computing midpoints using the ($(A)!0.5(B)$) syntax.
  • setting text width so that lines can wrap
  • using anchors to position the text
  • using shorten >= and shorten <= to adjust the ends of the arrows.

Code:

\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,] \drawhelp linesgrid(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}

Peter Grill
  • 223,288