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

3
  • Welcome to TeX SX! Could you post a full compilable code? – Bernard Nov 10 '18 at 20:18
  • Hi Bernard, the code is now complete :) – jonnyx Nov 10 '18 at 20:43
  • I have somehow solved it by inserting \hspace*{1cm} or -1cm after the individual beginnings of the subroutines. It is not a beautiful solution I guess.. – jonnyx Nov 10 '18 at 20:55
2

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

0
1

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

0

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.