3

I use tkiz to draw a picture in LaTeX. It works with me with \documentclass[border=5pt,tikz]{standalone}. However, when I try to use the same code in my original LaTeX file \documentclass[english]{IEEEtran}, it does not fit in the paper. How can I edit the following code to use it in my LaTeX file?

\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{arrows,positioning}
\newcommand{\parallelsum}{\mathbin{\|}}
\newcommand{\point}{\textbullet\hspace{1em}}
\everymath{\displaystyle}

        \begin{document}

    \begin{tikzpicture}[every node/.style={inner sep=6pt,draw,anchor=east},>=triangle 60]
        \node[xshift=1cm] (a) {\textcolor{red}{$V_1$ generate a temporary key pairs} $[Pk^{1}_{v_{1}}, Pr^{1}_{v_{1}}]$};
            \draw[->,cyan] ([yshift=.3cm,xshift=2cm]a.east) --+ (5,0) node[black,midway,above=.1cm] {$Pk^{1}_{v_{1}}$};
            \draw[<-,cyan] ([yshift=-.3cm,xshift=2cm]a.east) --+ (5,0) node[black,midway,below=.1cm] {$\mathcal{T}_{1}= {M_{1} || Sh_{R_{1}}}$};
        \node[right=9.5 of a,yellow!70!black,fill=yellow] (b) {\Huge\textcolor{white}{$R_1$}};
        \node[right=1 of b] {
            \begin{tabular}{l}
            \point    Generate: $M_1 = \{Pk^{1}_{v_{1}},   \textcolor{red}{\mathrm{tag}_{\mathrm{he}_1,R_1}}\}$ \\
            \point    Calculate: $\mathrm{S}_{R_1}(M_1)$
            \end{tabular}
        };
        \begin{scope}[yshift=-3cm]

            \node (a) {
                \begin{tabular}{p{7cm}}

                \textcolor{blue}{\point Run the PoW algorithm to get $S_{\mathcal{T}_{1}}$} \\
                \point $L_{R_{1}}=({\mathcal{T}_{1}||S_{\mathcal{T}_{1}}|| Pk^{2}_{v_{1}} ) || \sigma_{Pr^{1}_{v_{1}}}(\mathcal{T}_{1}||S_{\mathcal{T}_{1}}|| Pk^{2}_{v_{1}}}) $
                \end{tabular}
            };

            \draw[->,cyan] ([yshift=.3cm,xshift=1cm]a.east) --+ (5,0) node[black,midway,above=.1cm] { $\mathrm{L}_{R_1}$};
            \draw[<-,cyan] ([yshift=-.1cm,xshift=1cm]a.east) --+ (5.8,0) node[text width=5.8cm,black,midway,below=.1cm] { $\mathcal{T}_{2}= \{\mathcal{T}_{1} ||Sh_{R_{2}}(M_{1}) || M_{2} || Sh_{R_{2}}(M_{2} )\}  $};
            \node[right=8.5 of a,yellow!70!black,fill=yellow] (b) {\Huge\textcolor{white}{$R_2$}};
            \node[right=1 of b] (c) {
                \begin{tabular}{l}
                    \point Verify $\mathrm{L}_{R_1}$ and Shares. \\
                    \point Checks if: $(t_r-t_1)<\mathrm{Certain\ target\ value}$ \\

                    \point $M_{2}=\{Pk^{2}_{v_{1}} || (t_{1}, Tag_{R_{1}}) || (t_{2}, Tag_{R_{2}})\}$   \\
                    \point Calculate: $Sh_{R_{3}}(M_{2})$ \\

                    \point Calculate: $Sh_{R_{3}}(M_{3})$\\
                \end{tabular}
            };
        \end{scope}
        \draw[o-o,dashed] ([yshift=1.5cm]a.west) -- ([yshift=1.5cm]c.east);

    \end{tikzpicture}
\end{document}
8
  • 1
    Well, the perhaps simplest option might be to include the pdf of the picture in your document. If this is not an option for you, you may tell us if you set any length parameters in your document different from the defaults of your class since this may help us judging whether or not the picture will fit. Or is your question how to redesign your picture in such a way that it becomes narrower?
    – user121799
    Sep 11, 2018 at 2:26
  • @marmot I am using the standard IEEEtran conferences format: \documentclass[english]{IEEEtran}. I just need to the figure to fit in my paper not include it as a picture. I try many solutions but I got many errors.
    – Mohamed
    Sep 11, 2018 at 2:29
  • 1
    I guess it will be very hard to fix this. You have many large explicit dimensions, explicit shifts and so on. The IMHO most promising way would be a more or less complete redesign.
    – user121799
    Sep 11, 2018 at 2:53
  • @marmot could you help me with that. As I am very new to tkiz. Just fix me a part of the code so I can learn how to fix the remaining by myself.
    – Mohamed
    Sep 11, 2018 at 3:07
  • 1
    This post may help you Scaling different components of tikzpicture together.
    – J Leon V.
    Sep 11, 2018 at 3:07

2 Answers 2

6

Is this what you are looking for?

\documentclass[conference]{IEEEtran}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\newcommand{\parallelsum}{\mathbin{\|}}
\newcommand{\point}{\textbullet\hspace{1em}}
\everymath{\displaystyle}
\usepackage{lipsum}% MWE only

\begin{document}
\begin{figure*}[tp]
\resizebox{\textwidth}{!}{%
    \begin{tikzpicture}[every node/.style={inner sep=6pt,draw,anchor=east},>=triangle 60]
        \node[xshift=1cm] (a) {\textcolor{red}{$V_1$ generate a temporary key pairs} $[Pk^{1}_{v_{1}}, Pr^{1}_{v_{1}}]$};
            \draw[->,cyan] ([yshift=.3cm,xshift=2cm]a.east) --+ (5,0) node[black,midway,above=.1cm] {$Pk^{1}_{v_{1}}$};
            \draw[<-,cyan] ([yshift=-.3cm,xshift=2cm]a.east) --+ (5,0) node[black,midway,below=.1cm] {$\mathcal{T}_{1}= {M_{1} || Sh_{R_{1}}}$};
        \node[right=9.5 of a,yellow!70!black,fill=yellow] (b) {\Huge\textcolor{white}{$R_1$}};
        \node[right=1 of b] {
            \begin{tabular}{l}
            \point  Generate: $M_1 = \{Pk^{1}_{v_{1}},   \textcolor{red}{\mathrm{tag}_{\mathrm{he}_1,R_1}}\}$ \\
            \point  Calculate: $\mathrm{S}_{R_1}(M_1)$
            \end{tabular}
        };
        \begin{scope}[yshift=-3cm]


            \node (a) {
                \begin{tabular}{p{7cm}}

                \textcolor{blue}{\point Run the PoW algorithm to get $S_{\mathcal{T}_{1}}$} \\
                \point $L_{R_{1}}=({\mathcal{T}_{1}||S_{\mathcal{T}_{1}}|| Pk^{2}_{v_{1}} ) || \sigma_{Pr^{1}_{v_{1}}}(\mathcal{T}_{1}||S_{\mathcal{T}_{1}}|| Pk^{2}_{v_{1}}}) $
                \end{tabular}

            };




            \draw[->,cyan] ([yshift=.3cm,xshift=1cm]a.east) --+ (5,0) node[black,midway,above=.1cm] { $\mathrm{L}_{R_1}$};
            \draw[<-,cyan] ([yshift=-.1cm,xshift=1cm]a.east) --+ (5.8,0) node[text width=5.8cm,black,midway,below=.1cm] { $\mathcal{T}_{2}= \{\mathcal{T}_{1} ||Sh_{R_{2}}(M_{1}) || M_{2} || Sh_{R_{2}}(M_{2} )\}  $};
            \node[right=8.5 of a,yellow!70!black,fill=yellow] (b) {\Huge\textcolor{white}{$R_2$}};
            \node[right=1 of b] (c) {
                \begin{tabular}{l}
                    \point Verify $\mathrm{L}_{R_1}$ and Shares. \\
                    \point Checks if: $(t_r-t_1)<\mathrm{Certain\ target\ value}$ \\

                    \point $M_{2}=\{Pk^{2}_{v_{1}} || (t_{1}, Tag_{R_{1}}) || (t_{2}, Tag_{R_{2}})\}$   \\
                    \point Calculate: $Sh_{R_{3}}(M_{2})$ \\

                    \point Calculate: $Sh_{R_{3}}(M_{3})$\\
                \end{tabular}
            };
        \end{scope}
        \draw[o-o,dashed] ([yshift=1.5cm]a.west) -- ([yshift=1.5cm]c.east);

    \end{tikzpicture}
}
\caption{Sort of obligatory}
\end{figure*}

\lipsum[1-16]
\end{document}

demo

1
  • I try to run your code on my latex but it is talking too much time with no output.
    – Mohamed
    Sep 11, 2018 at 3:51
6

I tried to redesign your picture and apologize in advance for all the mistakes I made, e.g. by breaking your formulae incorrectly.

\documentclass[english]{IEEEtran}
\usepackage{tikz,tikzpagenodes} % tikzpagenodes only for illustration
\usetikzlibrary{arrows.meta,positioning}
\newcommand{\parallelsum}{\mathbin{\|}}
\everymath{\displaystyle}
\begin{document}
  \begin{tikzpicture}[every node/.style={inner sep=2pt,draw,anchor=east},
  >={Triangle},R-block/.style={text width=0.35\textwidth},
  L-block/.style={text width=0.25\textwidth}]
  % start with the R nodes
    \node[yellow!70!black,fill=yellow,text=white,font=\Huge] (b){$R_1$};
    \node[left=4cm of b,L-block] (a) {\textcolor{red}{$V_1$ generate a temporary key pairs} $[Pk^{1}_{v_{1}}, Pr^{1}_{v_{1}}]$};
    \draw[->,cyan] ([yshift=.3cm]a.east) -- ([yshift=.3cm]a.east -|b.west) 
        node[black,midway,above=.1cm] {$Pk^{1}_{v_{1}}$};
    \draw[<-,cyan] ([yshift=-.3cm]a.east) -- ([yshift=-.3cm]a.east -|b.west) 
        node[black,midway,below=.1cm] {$\mathcal{T}_{1}= {M_{1} || Sh_{R_{1}}}$};
    \node[right=2mm of b,R-block] (c) {\vspace{-1ex}\begin{itemize}
     \item   Generate: $M_1 = \{Pk^{1}_{v_{1}},   \textcolor{red}{\mathrm{tag}_{\mathrm{he}_1,R_1}}\}$ \\
     \item  Calculate: $\mathrm{S}_{R_1}(M_1)$
    \end{itemize}
     };
    \node[below=2.5cm of b,text=white,font=\Huge,fill=yellow] (b') {$R_2$};
    \node[left=4cm of b',L-block] (a') {\vspace{-1ex}\begin{itemize}
      \item Run the PoW algorithm to get $S_{\mathcal{T}_{1}}$
      \item $L_{R_{1}}=(\mathcal{T}_{1}||S_{\mathcal{T}_{1}}||Pk^{2}_{v_{1}} )$
      $ ||\sigma_{Pr^{1}_{v_{1}}}(\mathcal{T}_{1}||S_{\mathcal{T}_{1}}|| Pk^{2}_{v_{1}})$
      \end{itemize}
      };
     \draw[->,cyan] ([yshift=.3cm]a'.east) -- ([yshift=.3cm]a'.east -|b'.west)  
     node[black,midway,above=.1cm] { $\mathrm{L}_{R_1}$};
     \draw[<-,cyan] ([yshift=-.3cm]a'.east) -- ([yshift=-.3cm]a'.east -|b'.west)
     node[text width=3cm,black,midway,below=.1cm,align=center] 
     { $\mathcal{T}_{2}= \{\mathcal{T}_{1} |$ $|Sh_{R_{2}}(M_{1}) |$ $| M_{2} || Sh_{R_{2}}(M_{2} )\}  $};

     \node[right=2mm of b',R-block] (c') {\vspace{-1ex}\begin{itemize}
       \item Verify $\mathrm{L}_{R_1}$ and Shares. 
       \item Checks if: $(t_r-t_1)<\mathrm{Certain\ target\ value}$ 
       \item $M_{2}=\{Pk^{2}_{v_{1}} || (t_{1}, Tag_{R_{1}}) || (t_{2}, Tag_{R_{2}})\}$   
       \item Calculate: $Sh_{R_{3}}(M_{2})$ 
       \item Calculate: $Sh_{R_{3}}(M_{3})$
      \end{itemize}
     };
     \path (c'.north east) -- (c.south east) coordinate[midway] (R);
    \draw[{Circle[open]}-{Circle[open]},dashed] (R) -- (R-|a.west);
  \end{tikzpicture}
% only for illustation
\begin{tikzpicture}[overlay,remember picture] 
\draw[red,dashed] (current page text area.south west) rectangle 
(current page text area.north east);
\end{tikzpicture}
\end{document}

enter image description here

5
  • Thanks for your help. I try to copy the code to my TeXstudio program But it keeps trying to run and it is taking so much time without any response.
    – Mohamed
    Sep 11, 2018 at 4:22
  • @Mohamed I have no idea what happens on your machine. All I know that this code runs without problems on my updated TeXLive 2018 distribution. The only thing that I do not get from this contribution is IEEEtran.cls. Where did you get your version from? You seem to also have a problem with John Kormylo's code. Perhaps this suggests that you update your TeX installation.
    – user121799
    Sep 11, 2018 at 4:27
  • it works with me. Thank you very much. Is there is any way to resize the text inside the boxes? As it seems the text is not in a straight line.
    – Mohamed
    Sep 11, 2018 at 4:58
  • If this question worked for you, you should accept the answer with the green check, if you have additional questions you can ask them in another question centered on those issues or on other improvements.
    – J Leon V.
    Sep 11, 2018 at 5:13
  • @Mohamed I think all texts are on straight lines. You can resize texts as is done in the yellow boxes, e.g. with font=\large. You can also say scale=0.8, say, but I would not do either since then the texts are different from what is in the main text.
    – user121799
    Sep 11, 2018 at 11:08

You must log in to answer this question.

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