2

I have this type of figure containing pseudocode and my result is like shown here: enter image description here

    \documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{cryptocode}
\usepackage{dashbox}

\begin{document}

\begin{figure}[h]
\centering
    \fbox{%
        \pseudocode[]{%
            \textsc{\large Left} \<\< \textsc{\large Right} \\[][\hline]
            \<\< \\[-0.5\baselineskip]
            \begin{subprocedure}%
            \dbox{\procedure{\textsc{Short}}{%
                \text{command} \\
                \text{command}
                }}
            \end{subprocedure}\\[-1.5\baselineskip]
            \< \sendmessageright*{(x,y)} \< 
            \<\<\begin{subprocedure}%
            \dbox{\procedure{\textsc{Long }}{%
                \text{command loooooong}\\
                \text{command loooooong}
                }}
            \end{subprocedure}\\[-1.5\baselineskip]
            \< \sendmessageleft*{(a,b)} \<
            \<\< \\[-1.5\baselineskip]
            \begin{subprocedure}%
            \dbox{\procedure{\textsc{Middle }}{%
                \text{command longer}\\
                \text{command longer}
                }}
            \end{subprocedure}
        }
    }
\end{figure}


\end{document}

How can I achieve that Function "LONG" is aligned at the beginning of the right column? In other words, I want to remove the white-space between "LONG" and the arrows...

Also, is there the possibility to align "SHORT" to the right, next to the arrow? Such that the white-space would be to its left?

Thank your for helping me out, I can't figure out a valid solution

jonnyx
  • 123

2 Answers2

3

For the first problem, you simply had a wrong count for the columns. As to the second problem, as the first column is left aligned, you can add an \hspace{some length} in front of the procedure. The length has to be found by trial and error. Here is a possibility:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{cryptocode}
\usepackage{dashbox}

\begin{document}

\begin{figure}[h]
\centering
    \fbox{%
        \pseudocode[]{%
            \textsc{\large Left} \<\< \textsc{\large Right} \\[][\hline]
            \<\< \\[-0.5\baselineskip]
            \hspace{2.75em} \begin{subprocedure}%
            \dbox{\procedure{\textsc{Short}}{%
                \text{command} \\
                \text{command}
                }}
            \end{subprocedure}\\[-1.5\baselineskip]
            \< \sendmessageright*{(x,y)} \<
            %\< \< delet these column changes
            \begin{subprocedure}%
            \dbox{\procedure{\textsc{Long }}{%
                \text{command loooooong}\\
                \text{command loooooong}
                }}
            \end{subprocedure}\\[-1.5\baselineskip]
            \< \sendmessageleft*{(a,b)} \<
            \<\< \\[-1.5\baselineskip]
            \begin{subprocedure}%
            \dbox{\procedure{\textsc{Middle }}{%
                \text{command longer}\\
                \text{command longer}
                }}
            \end{subprocedure}
        }
    }
\end{figure}

\end{document} 

enter image description here

egreg
  • 1,121,712
Bernard
  • 271,350
2

Within \pseudocode pairs of columns are created; in each pair the first column is left aligned, the second one is right aligned. Thus you need

l1 r1 l2 r2 l3

Thus “SHORT” and “MIDDLE” should go in column r1, ”LONG” in column l3.

How to cope with the “Left” label? Put it in column l1, with zero width.

The command \> is “go to the next column”; \< is “go to the column after the next one”.

\documentclass{article}

\usepackage{cryptocode}
\usepackage{dashbox}

\begin{document}

\begin{figure}[htp]
\centering
\fbox{%
  \pseudocode[]{%
    \makebox[0pt][l]{\textsc{\large Left}} \<\< \textsc{\large Right} \\[][\hline]
    \mbox{} \\[-0.5\baselineskip]
\>  \begin{subprocedure}%
      \dbox{\procedure{\textsc{Short}}{%
        \text{command} \\
        \text{command}
      }}
    \end{subprocedure}\\[-1.5\baselineskip]
    \< \sendmessageright*{(x,y)} \<
    \begin{subprocedure}%
      \dbox{\procedure{\textsc{Long }}{%
        \text{command loooooong}\\
        \text{command loooooong}
      }}
    \end{subprocedure}\\[-1.5\baselineskip]
    \< \sendmessageleft*{(a,b)}
    \\[-1.5\baselineskip]
\>    \begin{subprocedure}%
      \dbox{\procedure{\textsc{Middle }}{%
         \text{command longer}\\
         \text{command longer}
      }}
    \end{subprocedure}
  }
}
\end{figure}


\end{document}

enter image description here

egreg
  • 1,121,712