5

I want to draw a diagram given below. Till now I am able to this much.

\documentclass{beamer}
\usepackage[most]{tcolorbox}
\usepackage{multirow}
\usetikzlibrary{matrix, arrows.meta, calc, positioning}
\tikzset{myarrow/.style={-Latex, rounded corners},}

\newtcolorbox{mybox}[1][]{%
 colback=bg, 
 colframe=blue!75!black,
 fonttitle=\bfseries,
 coltitle=blue!75!black,
 colbacktitle=bg,
 enhanced,
 attach boxed title to top left={yshift=-1.2mm, xshift=2mm},
 title=#2,
 #1}

\begin{document}

\begin{tikzpicture}    
\node (a) at (0,0) {$a_i$};    
\node (b) at (3,0) {$a_{ij}$};    
\node (c) at (7,0) {$a_{j}$};    
\node  (d) at (3,3) {$a_k$};    
\draw[-latex,bend right]  (a) edge (b);    
\draw[-latex,bend left]  (a) edge (b);
\draw[-latex,left]  (c) edge (b);    
\draw[-latex,left]  (b) edge (d);    
\end{tikzpicture}

\end{document}

I am using code in this frame :

\begin{frame}{GroupIso many-one reduces to DirGI }

\begin{mybox}{GroupIso $\le_m$ DirGI }
\begin{itemize}        
    \item Group table can be seen as a set of equations of the form $a_i \circ a_j =a_k$        
    \item Each such equation will be   translated into several edge connections as follow:       
    \item  \begin{tikzpicture}    
    \matrix[    
        matrix of math nodes,    
        row sep=30pt,    
        column sep=30pt,     
        nodes={circle, draw, text height=1.75ex, text depth=.5ex, 
            text width=width("$a_{ij}$"), text centered}    
        ] (m) {    
        & a_i \\    
        a_{ij} & a_{j} & a_k\\
    };
    \draw[myarrow] (m-2-3) -- (m-2-2);     
    \draw[myarrow] (m-2-2) -- (m-1-2);    
    \draw[myarrow] (m-2-2.135) -- +(-4pt, 4pt) -- ([shift={(4pt, 4pt)}]m-2-1.45) -- (m-2-1.45);    
    \draw[myarrow] (m-2-1.-45) -- +(4pt, -4pt) -- ([shift={(-4pt, -4pt)}]m-2-2.-135) -- (m-2-2.-135);    
    \end{tikzpicture}       
\end{itemize}  
\end{mybox}

\end{frame} 

and output I am getting is

enter image description here

see the compiled output enter image description here

I want to draw:

enter image description here

I want the nodes to look like small circles and, second problem, how to draw multi-edges with a bend?

  • 1
    You can use to paths – percusse Jan 27 '18 at 9:18
  • @percusse Explain your comment little more – new_born Jan 27 '18 at 9:27
  • 1
    \node [circle,draw] .. – Torbjørn T. Jan 27 '18 at 9:28
  • See AboAmmar's answer, he/she found a solution to put the tikzpicture directly in your document. – CarLaTeX Jan 27 '18 at 13:56
10

With a matrix and the anchoring with the degrees, the code could be simplyfied:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix, arrows.meta, calc, positioning}
\tikzset{myarrow/.style={-Latex, rounded corners},}
\begin{document}

    \begin{tikzpicture}
    \matrix[
        matrix of math nodes,
        row sep=30pt,
        column sep=30pt, 
        nodes={circle, draw, text height=1.75ex, text depth=.5ex, 
            text width=width("$a_{ij}$"), text centered}
        ] (m) {
        & a_i \\
        a_{ij} & a_{j} & a_k\\
    };
    \draw[myarrow] (m-2-3) -- (m-2-2); 
    \draw[myarrow] (m-2-2) -- (m-1-2);
    \draw[myarrow] (m-2-2.135) -- +(-4pt, 4pt) -- ([shift={(4pt, 4pt)}]m-2-1.45) -- (m-2-1.45);
    \draw[myarrow] (m-2-1.-45) -- +(4pt, -4pt) -- ([shift={(-4pt, -4pt)}]m-2-2.-135) -- (m-2-2.-135);
    \end{tikzpicture}

\end{document}

enter image description here

Edit (reply to the OP's edit):

Well, I cannot reproduce your problem because I get some errors if I use your MWE with beamer.

However, putting a tikzpicture inside an itemize, which is inside a tcolorbox, which is in a beamer frame seems quite challenging (but it is possible without using \matrix, like in AboAmmar's answer, or adding ampersand replacement=\& to the matrix options, like in marmot's one).

I suggest to you to create a .pdf of your image with this code, let's call it myimage:

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix, arrows.meta, calc, positioning}
\tikzset{myarrow/.style={-Latex, rounded corners},}
\begin{document}

    \begin{tikzpicture}
    \matrix[
    matrix of math nodes,
    row sep=30pt,
    column sep=30pt, 
    nodes={circle, draw, text height=1.75ex, text depth=.5ex, 
        text width=width("$a_{ij}$"), text centered}
    ] (m) {
        & a_i \\
        a_{ij} & a_{j} & a_k\\
    };
    \draw[myarrow] (m-2-3) -- (m-2-2); 
    \draw[myarrow] (m-2-2) -- (m-1-2);
    \draw[myarrow] (m-2-2.135) -- +(-4pt, 4pt) -- ([shift={(4pt, 4pt)}]m-2-1.45) -- (m-2-1.45);
    \draw[myarrow] (m-2-1.-45) -- +(4pt, -4pt) -- ([shift={(-4pt, -4pt)}]m-2-2.-135) -- (m-2-2.-135);
    \end{tikzpicture}

\end{document}

And then include myimage in your presentation (see the commented code if you want the \item before the image):

\documentclass{beamer}
\usepackage[most]{tcolorbox}
\usepackage{multirow}
%\usepackage[export]{adjustbox} if you want the \item before the image

\newtcolorbox{mybox}[2][]{% I put [2] because with [1] I could not compile
    colback=bg, 
    colframe=blue!75!black,
    fonttitle=\bfseries,
    coltitle=blue!75!black, 
    colbacktitle=bg,
    enhanced,
    attach boxed title to top left={yshift=-1.2mm, xshift=2mm},
    title=#2,
    #1}

\begin{document}
\begin{frame}[fragile]{GroupIso many-one reduces to DirGI }
\begin{mybox}{GroupIso $\le_m$ DirGI}
    \begin{itemize}
        \item Group table can be seen as a set of equations of the form $a_i \circ a_j =a_k$
        \item Each such equation will be   translated into several edge connections as follow:\newline
        %\item \includegraphics[width=.5\linewidth,valign=t]{myimage} %if you want the \item before the image
        \includegraphics[width=.5\linewidth]{myimage}
    \end{itemize}
\end{mybox}
\end{frame}
\end{document}

The result is:

enter image description here

  • I am getting the same image as I have given in my question even with your code – new_born Jan 27 '18 at 10:44
  • In a separate document it is working fine but in my beamer presentation this is getting distorted – new_born Jan 27 '18 at 10:55
  • I have edited the question – new_born Jan 27 '18 at 11:04
  • @new_born See the edit of my answer. – CarLaTeX Jan 27 '18 at 11:59
5

Relative positioning of circular nodes is easier than absolute positioning. The positioning library aids in doing this. The curvature is achieved via rounded corners and the small gap is achieved by shorten <=1pt.

\documentclass[tikz,border=2pt]{standalone}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}[cir/.style={circle,draw,minimum size=2.5em},>=latex,rounded corners]

\node (ij)[cir]{$a_{ij}$};
\node (j) [cir,right=of ij]{$a_{j}$};
\node (k) [cir,right=of  j]{$a_{k}$};
\node (i) [cir,above=of  j]{$a_{i}$};

\path [->] (k) edge (j)  (j) edge (i);

\draw [->,shorten <=1pt] (j.135) --+(-4pt, 4pt) --([shift={( 4pt, 4pt)}] ij.45 )--(ij.45);
\draw [->,shorten <=1pt] (ij.315)--+( 4pt,-4pt) --([shift={(-4pt,-4pt)}]  j.225)--(j.225);

\end{tikzpicture}

\end{document}

enter image description here

And here is a complete code with the picture included into your frame correctly:

\documentclass{beamer}
\usepackage[most]{tcolorbox}
\usepackage{multirow,lmodern}
\usetikzlibrary{matrix, arrows.meta, calc, positioning}
\tikzset{myarrow/.style={-Latex, rounded corners},}

\newtcolorbox{mybox}[2][]{%
 colback=bg, 
 colframe=blue!75!black,
 fonttitle=\bfseries,
 coltitle=blue!75!black,
 colbacktitle=bg,
 enhanced,
 attach boxed title to top left={yshift=-1.2mm, xshift=2mm},
 title=#2,#1}

\begin{document}

\begin{frame}{GroupIso many-one reduces to DirGI }

\begin{mybox}{GroupIso $\le_m$ DirGI }
\begin{itemize}        
  \item Group table can be seen as a set of equations of the form $a_i \circ a_j =a_k$        
  \item Each such equation will be   translated into several edge connections as follow:\\[.5em]       
  \begin{tikzpicture}[cir/.style={circle,draw,minimum size=2.5em},>=latex,rounded corners]
    \node (ij)[cir]{$a_{ij}$};
    \node (j) [cir,right=of ij]{$a_{j}$};
    \node (k) [cir,right=of  j]{$a_{k}$};
    \node (i) [cir,above=of  j]{$a_{i}$};
    \path [->] (k) edge (j)  (j) edge (i);
    \draw [->,shorten <=1pt] (j.135) --+(-4pt, 4pt) --([shift={( 4pt, 4pt)}] ij.45 )--(ij.45);
    \draw [->,shorten <=1pt] (ij.315)--+( 4pt,-4pt) --([shift={(-4pt,-4pt)}]  j.225)--(j.225);
  \end{tikzpicture}      
\end{itemize}  
\end{mybox}

\end{frame} 

\end{document}

enter image description here

  • AboAmmar, is there a way to put the \item before the picture? – CarLaTeX Jan 27 '18 at 12:18
  • Sure, it is possible, put \item ~\\ before the picture and remove the previous \\[.5em]. I didn't do it though because I thought it won't be elegant to have an item of the picture only. If you have special requirements you can add them to the question and I'll update my answer accordingly. – AboAmmar Jan 27 '18 at 12:50
  • Thank you! It was only a curiosity because the OP did it in his/her MWE. However, I agree it is awful. BTW, +1 – CarLaTeX Jan 27 '18 at 12:57
  • Thanks @CarLaTeX, in the previous comment I didn't actually notice the name and replied as if the OP was asking. – AboAmmar Jan 27 '18 at 13:10
4

Just combining CarLaTeX's very nice answer with the information that tikz matrices in a beamer document require ampersand replacements, one arrives at:

\documentclass{beamer}
\usepackage[most]{tcolorbox}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{matrix, arrows.meta, calc, positioning}
\tikzset{myarrow/.style={-Latex, rounded corners},}

\newtcolorbox{mybox}[2][]{% I put [2] because with [1] I could not compile
    colback=bg, 
    colframe=blue!75!black,
    fonttitle=\bfseries,
    coltitle=blue!75!black, 
    colbacktitle=bg,
    enhanced,
    attach boxed title to top left={yshift=-1.2mm, xshift=2mm},
    title=#2,
    #1}

\begin{document}
\begin{frame}[fragile]{GroupIso many-one reduces to DirGI }
\begin{mybox}{GroupIso $\le_m$ DirGI}
    \begin{itemize}
        \item Group table can be seen as a set of equations of the form $a_i \circ a_j =a_k$
        \item Each such equation will be   translated into several edge connections as follow:\newline
        \begin{tikzpicture}[ampersand replacement=\&]%\pgfinterruptpicture
    \matrix[
    matrix of math nodes,
    row sep=30pt,
    column sep=30pt, 
    nodes={circle, draw, text height=1.75ex, text depth=.5ex, 
        text width=width("$a_{ij}$"), text centered}
    ] (m) {
        \& a_i  \\
        a_{ij} \& a_{j} \& a_k\\
    };
    \draw[myarrow] (m-2-3) -- (m-2-2); 
    \draw[myarrow] (m-2-2) -- (m-1-2);
    \draw[myarrow] (m-2-2.135) -- +(-4pt, 4pt) -- ([shift={(4pt, 4pt)}]m-2-1.45) -- (m-2-1.45);
    \draw[myarrow] (m-2-1.-45) -- +(4pt, -4pt) -- ([shift={(-4pt, -4pt)}]m-2-2.-135) -- (m-2-2.-135);
    \end{tikzpicture}
    \end{itemize}
\end{mybox}
\end{frame}
\end{document}

enter image description here

3

Not elegant at all due to various manual adjustments of positions and lengths, but maybe a point to start from:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows}

\begin{document}

\begin{tikzpicture}
\draw (0,0) circle [radius=0.25] node (a) {$a_i$};
\draw (3,0) circle [radius=0.25] node (b) {$a_{ij}$};
\draw (7,0) circle [radius=0.25] node (c) {$a_{j}$};
\draw (3,3) circle [radius=0.25] node (d) {$a_k$};


\draw [-latex,rounded corners=10pt,shorten >=0.025cm,,shorten <=0.025cm]  (a.north) {-- ++(0.2cm,0.5cm) -- ++(2.6cm,0cm) -- ++(0.2cm,-0.5cm) } (b);
\draw [-latex,rounded corners=10pt]  (b.south) {-- ++(-0.2cm,-0.5cm) -- ++(-2.6cm,0cm) -- ++(-0.2cm,0.5cm) } (a);
\draw[-latex,rounded corners=10pt,shorten >=-0.05cm] (c.north) |- (d.east);
\draw[-latex,left,shorten >=-0.1cm,shorten <= -0.05cm]  (c) -- (b);
\draw[-latex,left]  (b) -- (d);
\end{tikzpicture}

\end{document}

enter image description here

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.