3

Is it possible to decorate rectangles with arrows? I used:

\node [draw,rectangle,minimum width=4cm,minimum height=4cm](r){};

But then it is really difficult to line up an edge so that it's level with the edge of the rectangle, is there an easier way? I want it to look like:

enter image description here

  • Perhaps you can find some inspiration here http://tex.stackexchange.com/questions/172288/complex-dynamically-sized-tikz-diagram – Fredrik Pihl Apr 21 '15 at 13:54
  • Welcome to TeX.SX!. When asking questions it is better to provide a full minimal working example (MWE) both in order to demonstrate what you are trying to do and to help others help you. The MWE should look like \documentclass...\begin{document}...\end{document}, it should compile and contain close to the minimal amount of code needed to explain/demonstrate what you are asking. This saves everyone time:) –  Apr 21 '15 at 13:56

2 Answers2

4

Your rectangle is a node. Hence you can place an arrow shaped node at its anchors like south and east.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}

\tikzset{
myarrow/.style={
  draw,thick,
  single arrow,
  text width=1cm,
  fill=white
  },
}


\begin{document}
 \begin{tikzpicture}
   \node [draw,rectangle,minimum size=4cm](r){};
   \node[myarrow,rotate=90] at (r.east){};
   \node[myarrow] at (r.south){};
 \end{tikzpicture}%
\end{document}

enter image description here

For modifying the shape of the arrow, you may refer to pgfmanual page 725, section 67.5, under shape single arrow.

3

And here's a simple Metapost approach.

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

ad_phi = 1/2;
ad_rho = 7/8;

% return the path of an arrow scaled to size "s" at time "t" on path "p"
vardef arrow_decor(expr s, t, p) = 
  save a; path a;
  a = ((1,0) -- (0,ad_rho) -- (0,ad_phi) -- (-1,ad_phi) 
      -- (-1,-ad_phi) -- (0,-ad_phi) -- (0,-ad_rho) -- cycle) 
      scaled 1/2 s
      rotated angle direction t of p 
      shifted point t of p;
  unfill a;
  a
  enddef;

beginfig(1);
path R; 
R = unitsquare xscaled 55 yscaled 34;
draw R; 
for t = 1/2 step 1 until 4:
  draw arrow_decor(8, t, R);
endfor
endfig;
end.

Adjust ad_rho and ad_phi to control the shape of the arrow. Or just change the definition of a in the macro to suit.

Thruston
  • 42,268