我尝试为下表(附件)编写不同的代码,但无法使其工作。有人能帮助我吗?
这是我使用的代码,但当我尝试在 LaTeX 中生成它时,它不起作用。单元格内的文本太大。我对 LaTeX 还不太熟悉,所以任何帮助都很好。
\begin{tabular}{ |p{8cm}||p{8m}}
\hline
Person A & Person B \\
\multicolumn{2}{|c|}{Key Generation} \\
\hline
Choose two primes p and q.
Choose encryption exponent e with gcd(e, \phi(n)) = 1.
Share private key n = pxq and e. & \\
\hline
\multicolumn{2}{|c|}{Encryption} \\
& Choose plaintext P.
Use person A’s key (n, e) to compute C \equiv P^e (mod n).
Send ciphertext C to Person A.\\
\hline
\multicolumn{2}{|c|}{Decryption} \\
Find d such that
ed \equiv 1 (mod \phi(n)) .
Compute for P \equiv C^d (mod n). & \\
\hline
\end{tabular}
答案1
我会删除大部分规则:
\documentclass{article}
\usepackage{booktabs,array}
\begin{document}
\begin{table}[!htp]
\begin{tabular}{
@{}
>{\raggedright}p{\dimexpr 0.5\columnwidth-\tabcolsep}
>{\raggedright}p{\dimexpr 0.5\columnwidth-\tabcolsep}
@{}
}
\toprule
\multicolumn{1}{c}{Person A} & \multicolumn{1}{c}{Person B} \tabularnewline
\midrule
\multicolumn{2}{c}{\itshape Key Generation} \tabularnewline
Choose two primes $p$ and $q$.
Choose encryption exponent $e$ with $\gcd(e, \phi(n)) = 1$.
Share private key $n = p\cdot q$ and $e$. \tabularnewline
\midrule
\multicolumn{2}{c}{\itshape Encryption} \tabularnewline
&
Choose plaintext $P$.
Use person $A$'s key $(n, e)$ to compute $C \equiv P^e \pmod{n}$.
Send ciphertext $C$ to Person $A$. \tabularnewline
\midrule
\multicolumn{2}{c}{\itshape Decryption} \tabularnewline
Find $d$ such that $ed \equiv 1 \pmod{\phi(n)}$.
Compute for $P\equiv C^d\pmod{n}$. \tabularnewline
\bottomrule
\end{tabular}
\caption{Description of RSA}
\end{table}
\end{document}
答案2
结合 Mico 的想法的解决方案回答,埃格的回答以及我自己的。我不认为字幕属于这两个人,而是属于以下动作描述。通过将字幕移到动作上,可以大大减少许多分散注意力的台词。
例子:
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{YY}
\toprule
Person A & Person B \\
\midrule
\emph{Key Generation}\\
\cmidrule(lr){1-1}
Choose two primes $p$ and $q$.
Choose encryption exponent $e$ with $\gcd(e, \phi(n)) = 1$.
Share private key $n = p\cdot q$ and $e$. & \\
&\emph{Encryption}\\
\cmidrule(lr){2-2}
& Choose plaintext $P$.
Use person $A$'s key $(n, e)$ to compute $C \equiv P^e \pmod{n})$.
Send ciphertext $C$ to Person $A$.\\
\emph{Decryption}\\
\cmidrule(lr){1-1}
Find $d$ such that $ed \equiv 1 \pmod{\phi(n)}$ .
Compute for $P\equiv C^d\pmod{n}$. & \\
\bottomrule
\end{tabularx}
\end{document}
此解决方案还可以通过将第二个和第三个操作移至表格行高度的顶部来节省一些垂直空间。它减少了表格中的大白色“洞”,并使 TeX 更容易找到分页符。但分隔字幕的线不应在前一个操作的区域中移动。
例子:
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\noindent
\edef\TabularRowHeight{\the\dimexpr-\arraystretch\baselineskip}
\begin{tabularx}{\textwidth}{YY}
\toprule
Person A & Person B \\
\midrule
\emph{Key Generation}\\
\cmidrule(lr){1-1}
Choose two primes $p$ and $q$.
Choose encryption exponent $e$ with $\gcd(e, \phi(n)) = 1$.
Share private key $n = p\cdot q$ and $e$. & \\[\TabularRowHeight]
&\emph{Encryption}\\
\cmidrule(lr){2-2}
& Choose plaintext $P$.
Use person $A$'s key $(n, e)$ to compute $C \equiv P^e \pmod{n})$.
Send ciphertext $C$ to Person $A$.\\[\TabularRowHeight]
\emph{Decryption}\\
\cmidrule(lr){1-1}
Find $d$ such that $ed \equiv 1 \pmod{\phi(n)}$ .
Compute for $P\equiv C^d\pmod{n}$. & \\
\bottomrule
\end{tabularx}
\end{document}
答案3
这是一个使用tabularx
环境的解决方案,将宽度设置为\textwdith
,并将两列设置为右侧不规则模式。我还将\extrarowheight
长度设置为较小的正值,以使表格材料看起来更“开放”。
\documentclass{article}
\usepackage{tabularx,ragged2e,array}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\setlength\extrarowheight{2pt}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|Y|Y|}
\hline
Person A & Person B \\
\hline
\multicolumn{2}{|c|}{Key Generation} \\
\hline
Choose two primes $p$ and $q$.
Choose encryption exponent $e$ with $\gcd(e, \phi(n)) = 1$.
Share private key $n = p\cdot q$ and $e$. & \\
\hline
\multicolumn{2}{|c|}{Encryption} \\
\hline
& Choose plaintext $P$.
Use person $A$'s key $(n, e)$ to compute $C \equiv P^e \pmod{n})$.
Send ciphertext $C$ to Person $A$.\\
\hline
\multicolumn{2}{|c|}{Decryption} \\
\hline
Find $d$ such that $ed \equiv 1 \pmod{\phi(n)}$ .
Compute for $P\equiv C^d\pmod{n}$. & \\
\hline
\end{tabularx}
\end{document}
答案4
我真的不明白你的问题。似乎你只是有很多拼写错误。我明白了
\documentclass{article}
\usepackage{booktabs,multirow,amsmath}
\begin{document}
\begin{tabular}{ |p{6cm}|p{6cm}|}
\toprule
Person A & Person B \\
\midrule
\multicolumn{2}{|c|}{Key Generation} \\
\midrule
Choose two primes $p$ and $q$.
Choose encryption exponent $e$ with $\gcd(e, \phi(n)) = 1$.
Share private key $n = p\times q$ and $e$. & \\
\midrule
\multicolumn{2}{|c|}{Encryption} \\
\midrule
& Choose plaintext $P$.
Use person A's key $(n, e)$ to compute $C \equiv P^e (\text{mod} n)$.
Send ciphertext $C$ to Person A.\\
\midrule
\multicolumn{2}{|c|}{Decryption} \\
\midrule
Find $d$ such that
$ed \equiv 1 (\text{mod} \phi(n))$ .
Compute for $P \equiv C^d (\text{mod} n)$. & \\
\bottomrule
\end{tabular}
\end{document}
希望我自己没有犯太多错误。我把柱子弄窄了一点。6厘米对我来说看起来正好。