9

I have created a rectangle and just can't find the solution how to draw a bent arrow from the south side (close to the south east corner) to the east side (also close to the south east corner).

\documentclass[12pt,twoside,a4paper]{report}     
\usepackage{a4} 
\usepackage{tikz} 
\usetikzlibrary{calc,decorations.markings,arrows,backgrounds,calendar,matrix,mindmap,patterns,shadows,trees,positioning}

\begin{document} 

\begin{tikzpicture}[auto, node distance=1cm,
    block_small/.style ={rectangle, draw=black, thick, fill=white, text centered, text width=4em, minimum height=4em}]  

\node [block_small, xshift=-3.3cm] (A) {A} ;
\node [block_small,right of=A, xshift=3.3cm] (B) {B} ; 

\begin{pgfonlayer}{background} 

   % Rectangle             
    \path (A.west |- A.north)+(-0.45,0.45) node (a) {};
    \path (B.south -| B.east)+(0.45,-0.45) node (b) {};
    \path[draw=black!50, dashed] (a) rectangle (b);

\end{pgfonlayer} 

\end{tikzpicture}  
\end{document}

I have spent already too much time on this and hope someone may help!

egreg
  • 1,121,712
Lisa
  • 91

1 Answers1

9
  • You can construct the box easier with the fit library. Just put fit=(a1)(a2)...(an) into the options of a new node, with inner sep=<length> you can control the distance to all the fitted nodes.

  • The calc library lets you do things like ($(a)+(0,1)$) which is the position 1 unit up from node a. With that you can do things like "from the south side (close to the south east corner)"

  • for a bent arrow, you can use the to[out=<deg>,in=<deg>,looseness=<val>] operation. If you dont like this arrow, you can also specify more intermediate points. If the arrow starts and ends at the same distance from the corner, you can also use an arc. Arcs are specified via arc (start angle:end angle:radius)

Code

\documentclass[12pt,twoside,a4paper]{report} 
\usepackage{tikz}
\usetikzlibrary{calc,fit,arrows}

\begin{document} 

\begin{tikzpicture}
[   auto, node distance=1cm,
  block_small/.style ={rectangle, draw=black, thick, fill=white, text centered, text width=4em, minimum height=4em}
]
    \node [block_small, xshift=-3.3cm] (A) {A} ;
    \node [block_small,right of=A, xshift=3.3cm] (B) {B} ; 

    % Rectangle             
    \node[fit=(A)(B),dashed,draw,inner sep=0.45cm] (Box) {};

    \draw[-stealth] ($(Box.south east)+(-0.5,0)$) to[out=270,in=0,looseness=5] node[below right] {$\pi$} ($(Box.south east)+(0,0.5)$);

    \draw[-stealth] ($(Box.south west)+(0.5,0)$) arc (360:90:0.5);
\end{tikzpicture}

\end{document}

Output

enter image description here

Tom Bombadil
  • 40,123
  • [xshift=] and friends makes it easier to arrange shifts etc. without the calc dependence – percusse Nov 07 '13 at 12:51
  • Thank you very much! The left one is exactly what I wanted. I now tried to switch it to the south east side playing around with the parameters such as \draw[-stealth] ($(Box.south east)+(-0.5,0)$) arc (360:90:0.5); However, it does not bend in the right dirextion. I hope you can help again. Thanks in advance! – Lisa Nov 07 '13 at 11:13