0

How can I make this with LaTeX in beamer (I have problems with the arrows) ?

enter image description here

I only have this

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,arrows}
\begin{document}
\begin{frame}
\begin{tikzpicture}[ node distance = 8.1 mm and 6 mm, > = stealth', every node/.style = {circle, draw=pink!30!black, fill=pink!30, minimum size=8mm} ]
\node (b) {\tiny A};
\node (a) [below right=of b] {{\tiny C}};
\node (c) [above right=of a] {{\tiny B}};
\node (d) [below right=of c] {{\tiny D}}
\end{tikzpicture}
\end{frame}
\end{document}
Torbjørn T.
  • 206,688
tarl
  • 147

2 Answers2

6

Two versions with help of library automata:

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

\begin{document}
    \centering
\begin{tikzpicture}[
    shorten < =  1mm, shorten > = 1mm,
node distance = 33mm, on grid, auto,
every path/.style = {bend left, -Latex}
                    ]
\node[state] (A) {A};
\node[state] (B) [right=of A] {B};
\node[state] (C) [below=of A] {C};
\node[state] (D) [right=of C] {D};
%
\path[->]   (A) edge ["e"] (B)
            (B) edge        (D)
            (D) edge        (C)
            (C) edge ["h"] (A)
%
            (A) edge        (C)
            (C) edge        (D)
            (D) edge ["g"] (B)
            (B) edge ["f"] (A);
\end{tikzpicture}

\begin{tikzpicture}[
    shorten < =  1mm, shorten > = 1mm,
node distance = 33mm, on grid, auto,
every path/.style = {-Latex},
sx+/.style = {xshift=1 mm},
sy+/.style = {yshift=1 mm},
sx-/.style = {xshift=-1 mm},
sy-/.style = {yshift=-1 mm},
                    ]
\node[state] (A) {A};
\node[state] (B) [right=of A] {B};
\node[state] (C) [below=of A] {C};
\node[state] (D) [right=of C] {D};
%
\path[->]   ([sy+] A.east)  edge ["e"] ([sy+] B.west)
            ([sx+] B.south) edge       ([sx+] D.north)
            ([sy-] D.west)  edge       ([sy-] C.east)
            ([sx-] C.north) edge ["h"] ([sx-] A.south)
%
            ([sx+] A.south)  edge       ([sx+] C.north)
            ([sy+] C.east)   edge       ([sy+] D.west)
            ([sx-] D.north) edge ["g"]  ([sx-] B.south)
            ([sy-] B.west)  edge ["f"]  ([sy-] A.east);

\end{tikzpicture}
\end{document}

enter image description here

Edit: Added nicer arrows positions in second image

Addendum: Version which doesn't follow to image shown in question but to code:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, automata, calc, positioning, quotes}
\begin{document}
    \centering
\begin{tikzpicture}[
    shorten < =  1mm, shorten > = 1mm,
node distance = 22mm, on grid, auto,
every path/.style = {-Latex},
state/.append style = {draw=pink!30!black, fill=pink!30, minimum size=8mm},
sx+/.style = {xshift=1 mm},
sy+/.style = {yshift=1 mm},
sx-/.style = {xshift=-1 mm},
sy-/.style = {yshift=-1 mm},
                    ]
\node[state] (A) {A};
\node[state] (B) [right=of A] {B};
\node[state] (C) [below right=of A] {C};
\node[state] (D) [right=of C] {D};
%
\path[->]   ([sy+] A.east)  edge ["e"] ([sy+] B.west)
            ([sx+] B.south east) edge       ([sx+] D.north west)
            ([sy-] D.west)  edge       ([sy-] C.east)
            ([sx-] C.north west) edge ["h"] ([sx-] A.south east)
%
            ([sx+] A.south east)  edge       ([sx+] C.north west)
            ([sy+] C.east)   edge       ([sy+] D.west)
            ([sx-] D.north west) edge ["g"]  ([sx-] B.south east)
            ([sy-] B.west)  edge ["f"]  ([sy-] A.east);
\end{tikzpicture}
\end{document}

enter image description here

Zarko
  • 296,517
  • This is the right answer. It utilizes beamer not other kind of styles such article or standalone. – CroCo Nov 11 '16 at 01:13
5

Something like this?

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{quotes,positioning,arrows}

\begin{document}
    \newcommand*{\arrowsep}{0.2cm}
    \begin{tikzpicture}[my arrow/.style={-latex, shorten >=2pt, shorten <=2pt},
                        shift left/.style={transform canvas={xshift = -\arrowsep/2}},
                        shift right/.style={transform canvas={xshift = \arrowsep/2}},
                        shift up/.style={transform canvas={yshift = \arrowsep/2}},
                        shift down/.style={transform canvas={yshift = -\arrowsep/2}},
                        node distance = 8.1 mm and 6 mm, > = stealth', my node/.style = {circle, draw=pink!30!black, fill=pink!30, minimum size=8mm}]
        \node[my node] (A) {\tiny A};
        \node[my node] (C) [below right=of A] {{\tiny C}};
        \node[my node] (B) [above right=of C] {{\tiny B}};
        \node[my node] (D) [below right=of B] {{\tiny D}};
        \draw (A) edge[my arrow, shift up,"e"]   (B) edge[my arrow, shift right] (C)
        (B) edge[my arrow, shift down,"f"] (A) edge[my arrow, shift left]  (D)
        (D) edge[my arrow, shift down] (C) edge[my arrow, shift right,"g",auto=right] (B)
        (C) edge[my arrow, shift up]   (D) edge[my arrow, shift left,"h"] (A);
    \end{tikzpicture}
\end{document}

Note the transform canvas for shifting the edges, normal shifting does not work in this situations: see TikZ: xshift not shifting

A \arrowsep command is defined to hold the value of the styles shift up, down, left and right.

The keys shorten >=<dim> and shorten <=<dim> shortens the first and last bits of the path by <dim>, distancing the arrow from the nodes.

enter image description here

  • Where is beamer in the answer?! Yes you did generate the picture but you didn't show how to run it in or upload it in beamer. – CroCo Nov 11 '16 at 01:14
  • "but isn't it just change the class?" Have you tried that? You will see that the code need to be modified properly to fit in beamer. The answer is then No it is not merely changing the class. – CroCo Nov 11 '16 at 14:12
  • You need to modify your answer to reflect this change. – CroCo Nov 11 '16 at 14:22
  • 2
    @CroCo It's trivial to export it as pdf and include it in beamer. The problem lies in the OP. – c.p. Nov 11 '16 at 14:51
  • @c.p., Export to PDF?? As simple as that may be there's no need for it, it works with beamer just fine. The exceptional change needed was just to load tikz... – Guilherme Zanotelli Nov 11 '16 at 15:09
  • 2
    @CroCo, the TikZ picture is independent from document class. With other words, image is the same in beamer, article, ... standalone. Specific to used document class is only a size of the paper on which the images is drawn. – Zarko Nov 11 '16 at 15:10
  • @GuilhermeZ.Santos Well, I'm actually defending your point by telling what I would do (and what I actually do by producing figures for papers and then loading them for talks). Sure, it's not the shortest and optimal way, but I rather wanted to show that it is irrelevant whether beamer is loaded. – c.p. Nov 11 '16 at 15:32
  • @c.p., I know, and good point, a simple workaround that works for many problems. I just don't want anyone getting the idea that the code does not work on beamer :), @Zarko's point closes the deal on that one. – Guilherme Zanotelli Nov 11 '16 at 15:47
  • 1
    @CroCo As we are all here on a purely voluntarily basis, I don't think you are in a position to order someone to do something. – samcarter_is_at_topanswers.xyz Nov 11 '16 at 16:37
  • @samcarter, I'm not ordering anyone to do anything. I'm suggesting to address the problem which has been stated clearly in the title. – CroCo Nov 12 '16 at 00:11
  • Some people state "It's trivial". This is true for people who have experience with Latex but we should not generalize this assumption. – CroCo Nov 12 '16 at 00:13