1

So just trying to edit a table someone had done in tabularx as I liked the style however I have no idea what I'm doing really and as such I've come up against a problem. There is a big space after the entry 'setup', in the below code and I would like it all to be nice and symmetrical the space makes it very asymmetrical. Is there a way to remove this space?

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}


\begin{document}
    \noindent
    \edef\TabularRowHeight{\the\dimexpr-\arraystretch\baselineskip}

    \begin{tabularx}{\textwidth}{YY}
    \toprule
    Alice  &  Bob \\
    \midrule
    \emph{Setup}\\
    \cmidrule(lr){1-1}
    Alice \& Bob select a prime $p$ and a generator $g$ for the finite field $\mathbb{F}_p$
    &\\

    &\emph{Private Computation}\\
    \cmidrule(lr){2-2}
    &  Bob randomly selects $b \in \mathbb{F}_p$ and then computes the following:

     $B \equiv g^b \mod p$ once computed Bob sends Alice $B$

     \\[\TabularRowHeight] & \\

    & \emph{Key Computation}\\
    \cmidrule(lr){2-2}
    & Bob who now has $A$, calculates the following:$A^b \equiv (g^a)^b \equiv g^{ab} \mod p$

     \\


    \emph{Private Computation}\\ 
    \cmidrule(lr){1-1}
    Alice randomly selects $a \in \mathbb{F}_p$ and then computes the following:

    $A \equiv g^a \mod p$ once computed Alice sends Bob $A$ & \\ \pagebreak

    \emph{Key Computation}\\ 
    \cmidrule(lr){1-1}
    Alice who now has $B$, calculates the  following:$B^a \equiv (g^b)^a \equiv g^{ab} \mod p$ & \\


    \bottomrule


    \end{tabularx}
\end{document}

Picture of current output

Output I'd like to achieve

2
  • Can you post a screenshot of the result? I don't get any unusual space other than the empty cells with are explicitly added in the code. Do you maybe want to remove these? Sep 6, 2019 at 15:39
  • Perhaps I do want to remove these, I am working out what does what of a similar table not familiar with using this package at all. Will add a picture for you !
    – Dead_Ling0
    Sep 6, 2019 at 15:44

1 Answer 1

0

I don't think removing the alternating layout from the table you showed makes a lot of sense, but here is a try

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}


\begin{document}
        \emph{Setup}: Alice \& Bob select a prime $p$ and a generator $g$ for the finite field $\mathbb{F}_p$
    \begin{tabularx}{\textwidth}{@{}YY@{}}
    \toprule
    Alice  &  Bob \\
    \midrule
    \addlinespace[1.2em]
    \emph{Private Computation}:&\\ \addlinespace
%    \cmidrule(r){1-1}\cmidrule(l){2-2}
    Alice randomly selects $a \in \mathbb{F}_p$ and then computes the following:

    $A \equiv g^a \mod p$ once computed Alice sends Bob $A$& Bob randomly selects $b \in \mathbb{F}_p$ and then computes the following:

     $B \equiv g^b \mod p$ once computed Bob sends Alice $B$\\\addlinespace[1.2em]

     \emph{Key Computation}: &\\ \addlinespace
%    \cmidrule(r){1-1}\cmidrule(l){2-2}
    Alice who now has $B$, calculates the  following:$B^a \equiv (g^b)^a \equiv g^{ab} \mod p$  & Bob who now has $A$, calculates the following:$A^b \equiv (g^a)^b \equiv g^{ab} \mod p$
     \\
    \bottomrule


    \end{tabularx}
\end{document}

enter image description here

Instead I would prefer a 3-column layout:

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}


\begin{document}
        \emph{Setup}: Alice \& Bob select a prime $p$ and a generator $g$ for the finite field $\mathbb{F}_p$
    \begin{tabularx}{\textwidth}{@{}>{\RaggedRight\arraybackslash}p{2.2cm}YY@{}}
    \toprule
    & Alice  &  Bob \\
    \midrule
    \emph{Private \linebreak Computation} & %    
    Alice randomly selects $a \in \mathbb{F}_p$ and then computes the following:

    $A \equiv g^a \mod p$ once computed Alice sends Bob $A$& Bob randomly selects $b \in \mathbb{F}_p$ and then computes the following:

     $B \equiv g^b \mod p$ once computed Bob sends Alice $B$\\\addlinespace
     \emph{Key \linebreak Computation} & Alice who now has $B$, calculates the  following:$B^a \equiv (g^b)^a \equiv g^{ab} \mod p$  & Bob who now has $A$, calculates the following:$A^b \equiv (g^a)^b \equiv g^{ab} \mod p$
     \\
    \bottomrule


    \end{tabularx}
\end{document}

enter image description here

4
  • Thanks just wondering is it possible to have the subheadings for the bob column as well? And to have a horizontal line above the setup? Just looking through the code now trying to work out what's happening. :)
    – Dead_Ling0
    Sep 6, 2019 at 16:01
  • @Dead_Ling0 Try with \emph{Private Computation}:&\emph{Private Computation}:\\ \addlinespace, but having redundant information in your table will decrease the information-to-noise ratio dramatically Sep 6, 2019 at 16:04
  • Thank you kindly you've been most helpful, will try to understand what you've done any resources where I can learn about tableux the latex wiki wasn't very helpful.
    – Dead_Ling0
    Sep 6, 2019 at 16:10
  • @Dead_Ling0 I can recommend dickimaw-books.com/latex/novices/html/index.html for latex beginners. From your question, I think your problem is not really related to tabularx, but rather about general mechanics of tabular in latex (tabularx is just a special case of a tabular). A short summary: www1.maths.leeds.ac.uk/LaTeX/TableHelp1.pdf Sep 6, 2019 at 16:20

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.