2

Ciao, I am trying to create a tikz figure as shown in the image. Here is my code

\documentclass[border=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
    \begin{tikzpicture}[
  \node[rectangle] (a1) {box 1};
     \node[rectangle,below right=of a1] (a2) {box 2};
    \node[rectangle,above right=of a1] (a3) {box 3};

    \foreach \i/\j/\txt/\p in {% start node/end node/text/position
      a1/a2/1-2/below,
      a1/a3/1-3/above,
      a2/a3/2-3/below} \draw [myarrow] (\i) -- node[sloped,font=\small,\p] {\txt} (\j);
    \end{tikzpicture}
\end{document}

enter image description here

I am not sure how to add the rectangles; how to connect the arrows to the side edge; and how to make the arrows straight in situations when the box lengths are different--preferably the arrows will touch the center of the edge.

3

Use Tikz shapes library and describe the sides of nodes.

\documentclass[margin=4mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,positioning,shapes}
\begin{document}

 \begin{tikzpicture}[>=latex]
 \tikzstyle{rect}=[ thick, draw=blue, rectangle, minimum width=100pt, 
  minimum height = 50pt, align=center]
  \node[rect] (a1) {box 1};
  \node[rect,below right=of a1] (a3) {box 3};
  \node[rect,above right=of a1] (a2) {box 2};
\draw[->] (a1.north)--(a2.west)node[midway,above,xshift=-2mm]{1-2};
\draw[->] (a1.south)--(a3.west)node[midway,below,xshift=-2mm]{1-3};
\draw[->] (a2.south)--(a3.north)node[midway,xshift=-3mm]{2-3};

    \end{tikzpicture}
\end{document}

enter image description here

  • thanks a bunch. Two final questions; how can i slant 1-3 and 1-2 so they are angled with the arrows lines? Like this: i.stack.imgur.com/Dwv1Y.png – victoria Jan 10 at 13:52
  • @victoria, your welcome. Add sloped option to node, i.e, node[midway,sloped,above,xshift=-2mm]{1-2};Now you can remove the xshift=-2mm. – ferahfeza Jan 10 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.