3

enter image description here

My goal is to make a Tikz picture that looks like the example with the white boxes and letters inside.

This is what I did so far (my example has gray boxes). I am not sure how to stack it evenly as in the picture with the white boxes. My LaTeX code is at the bottom... I would then like to output the figure as an image file like a jpeg or tif or png.

enter image description here

 \begin{tikzpicture}[>=latex]
 \tikzstyle{rect}=[draw=black, 
                   rectangle, 
                   fill=gray,
                   fill opacity = 0.2,
                   text opacity=1,
                   minimum width=100pt, 
                   minimum height = 50pt, 
                   align=center]
  \node[rect] (a1) {A};
  \node[rect,below right=of a1] (a3) {C};
  \node[rect,above right=of a1] (a2) {B};
\draw[->] (a1.north)--(a2.west)node[midway,sloped, above,xshift=-2mm]{1};
\draw[->] (a1.south)--(a3.west)node[midway,sloped, below,xshift=-2mm]{2};
\draw[->] (a2.south)--(a3.north)node[midway, xshift=6mm]{3};
    \end{tikzpicture}
    \end{figure}
3
  • 1
    Hi, please add a full compileable code
    – AndréC
    Sep 12, 2019 at 14:05
  • 1
    I'm a bit confused. Surely you see that the three node commands are putting the rectangles where they end up. Why not monkey around with that to get the arrangement you want? Offhand, it looks like you would want to place C first and then A above left and B above right. Have you not tried that?
    – Teepeemm
    Sep 12, 2019 at 14:21
  • @Teepeemm thanks so much. I tried tons of iterations but have not been able to get 'C' to line up in the middle below 'A' and 'B'. I could only get it to line up directly undernearth 'A' or 'B'
    – bvowe
    Sep 12, 2019 at 14:34

2 Answers 2

5

Here is one out of many ways to arrange the nodes like this. Note also that \tikzstyle is deprecated.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\begin{tikzpicture}[>=latex,rect/.style={draw=black, 
                   rectangle, 
                   fill=gray,
                   fill opacity = 0.2,
                   text opacity=1,
                   minimum width=100pt, 
                   minimum height = 50pt, 
                   align=center}]
  \node[rect] (a1) {A};
  \node[rect,right=100pt of a1] (a2) {B};
  \path (a1) -- (a2) node[midway,below=60pt,rect] (a3) {C};
  \draw[->] (a1)--(a2)node[midway,sloped, above]{1};
  \draw[->] (a1.south)--(a3.west)node[midway,sloped,below]{2};
  \draw[->] (a2.south)--(a3.east)node[midway,sloped,below]{3};
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

4

Another way, with added arrows.meta and quotes TikZ libraries:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning,
                quotes}

\begin{document}
    \begin{figure}
\begin{tikzpicture}[
node distance= 9mm and 0mm,
rect/.style = {draw=black, fill=gray!20, %font=\LARGE,
               minimum width=100pt, minimum height = 50pt},
every edge/.style = {draw, -Latex},
every edge quotes/.style = {sloped, auto=right}
                ]
\node[rect] (a) {A};
\node[rect,below right=of a] (c) {C};
\node[rect,above right=of c] (b) {B};
%
\path   (a) edge["1"  swap] (b)
        (a.south) edge["2"] (c.west)
        (b.south) edge["3"] (c.east);
\end{tikzpicture}
    \end{figure}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .