1

I wish to use the below code write the context shown as in the following picture. However, the code cannot make the text align, is there a easy way to align the text?

\begin{figure*}[t]
\begin{small}
    \emph{Role Buyer \{var counter  $=$ 0; }\\
    \emph{      Main () $=$ B2S!\{bch\} $\rightarrow$ Session();} \\
    \emph{~~~~~Session() $=$ bch!QuoteRequest $\rightarrow$ $counter++$; bch?QuoteResonse.x $\rightarrow$ }\\
    \emph{~~~~~~~~~~~~~~~if (x $\leq$ 1000) \{ ~ bch!QuoteAccept $\rightarrow$ bch?OrderConfirmation $\rightarrow$ bch?DeliveryDetails.y $\rightarrow$ Stop ~ \}} \\
    \emph{ elseif (counter > 3) \{ bch!QuoteReject $\rightarrow$ Session() \} ~else~ \{ Stop \}; ~\} }\\
     \} \\  
\end{small} 
\end{figure*}

enter image description here

1 Answer 1

2

What wrong with the classic tabular environment? You can put this code also inside of a figure float.

You need only a \begin{tabular}{lll} ... but I left a more complicated example because with @{} you can control easily the padding from the equal sign.

The example is landscape since the table is too wide even with a small font. You can also consider here change the left column from l to something like p{11cm} to have a multi-line cell for the results "Session()", so you can maintain a decent font size in a narrow table without split the results.

BTW, have you heard about the package listings?

\documentclass[10pt,landscape]{article}
\usepackage[margin=1cm]{geometry}
\begin{document}
\em\small
\begin{tabular}{l@{\hspace{.5em}}l@{\hspace{.5em}}l}
Role Buyer \{var counter &$=$& 0;\\
Main () &$=$& B2S!\{bch\} $\rightarrow$ Session();\\  
Session() &$=$& bch!QuoteRequest $\rightarrow$ $counter++$; bch?QuoteResonse.x $\rightarrow$\\
&& if (x $\leq$ 1000) \{ ~ bch!QuoteAccept $\rightarrow$ bch?OrderConfirmation $\rightarrow$ bch?DeliveryDetails.y $\rightarrow$ Stop ~ \} \\
&& elseif (counter > 3) \{ bch!QuoteReject $\rightarrow$ Session() \} ~else~ \{ Stop \}; ~\} \\
\end{tabular}

\vspace{2cm}\large

\begin{tabular}{l@{\hspace{.5em}}l@{\hspace{.5em}}p{13cm}}
Role Buyer \{var counter &$=$& 0;\\
Main () &$=$& B2S!\{bch\} $\rightarrow$ Session();\\  
Session() &$=$& bch!QuoteRequest $\rightarrow$ $counter++$; bch?QuoteResonse.x $\rightarrow$ if (x $\leq$ 1000) \{ ~ bch!QuoteAccept $\rightarrow$ bch?OrderConfirmation $\rightarrow$ bch?DeliveryDetails.y $\rightarrow$ Stop ~ \} elseif (counter > 3) \{ bch!QuoteReject $\rightarrow$ Session() \} ~else~ \{ Stop \}; ~\} \\
\end{tabular}

\end{document}

MWE

You must log in to answer this question.

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