Latex tabularx 間距問題

Latex tabularx 間距問題

因此,只是嘗試編輯某人在 tabularx 中完成的表格,因為我喜歡這種風格,但我不知道我真正在做什麼,因此我遇到了問題。在下面的程式碼中,「設定」條目後面有一個很大的空間,我希望一切都很好且對稱,但空間使其非常不對稱。有沒有辦法去掉這個空格?

\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}

電流輸出圖

我想要實現的輸出

答案1

我認為從您展示的表格中刪除交替佈局沒有多大意義,但這是一個嘗試

\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}

在此輸入影像描述

相反,我更喜歡 3 列佈局:

\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}

在此輸入影像描述

相關內容