![对齐两个字母表的问题](https://linux22.com/image/403307/%E5%AF%B9%E9%BD%90%E4%B8%A4%E4%B8%AA%E5%AD%97%E6%AF%8D%E8%A1%A8%E7%9A%84%E9%97%AE%E9%A2%98.png)
我正在尝试对齐两个字母,使每个字母都与下面的字母对齐,以便它们适合页面。我很难做到这一点,任何建议都很好,我已经尽我所能尝试了。这是我能做到的最接近的。
\begin{align*}
&\text{Plaintext:\;\;\; }\text{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\\
&\text{Ciphertext: }\;\text{Z Y X W V U T S R Q P O N M L K J I H G F E D C B A}
\end{align*}
谨致问候并感谢 Jay
答案1
欢迎来到 TeX.SX!您可以查看我们的入门指南以进一步熟悉我们的格式。
我会使用tabular
环境和等宽字体。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
&\text{Plaintext:\;\;\; }\text{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\\
&\text{Ciphertext: }\;\text{Z Y X W V U T S R Q P O N M L K J I H G F E D C B A}
\end{align*}
\noindent\begin{tabular}{ll}
Plaintext: & \texttt{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}\\
Ciphertext: & \texttt{Z Y X W V U T S R Q P O N M L K J I H G F E D C B A}
\end{tabular}
\end{document}
答案2
如果您不想更改字体,您可以使用如下方法:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array,tabularx,rotating}
\begin{document}
\begin{sidewaystable}
\centering\setlength\tabcolsep{2.5pt}%
\begin{tabularx}\linewidth{l*{26}X}
Plaintext: &A &B &C &D &E &F &G &H &I &J &K &L &M &N &O &P &Q &R &S &T &U &V &W &X &Y &Z\\
Ciphertext: &Z &Y &X &W &V &U &T &S &R &Q &P &O &N &M &L &K &J &I &H &G &F &E &D &C &B &A\\
\end{tabularx}
\end{sidewaystable}
\end{document}
答案3
Atabular
更好;还可以再进一步简化输入。这样w{c}{1em}
我们就得到了一个固定宽度的单元格;我还将列间距设置为零,因为在这个应用程序中不需要它。
该\tl_map_function:nN
指令将第一个参数拆分为标记,并将指定的函数应用于每个标记,其职责是添加&
到字母前面。
\documentclass{article}
\usepackage{xparse,array}
\ExplSyntaxOn
\NewDocumentCommand{\cipher}{m}
{% #1 = a permutation of 26 letters
\deadlingo_cipher:n { #1 }
}
\cs_new_protected:Nn \deadlingo_cipher:n
{
\group_begin:
\setlength{\tabcolsep}{0pt}
\begin{tabular}{l@{\hspace{1em}}*{26}{w{c}{1em}}}
Plaintext:
\tl_map_function:nN {ABCDEFGHIJKLMNOPQRSTUVWXYZ} \__deadlingo_cipher_cell:n \\
Ciphertext:
\tl_map_function:nN {#1} \__deadlingo_cipher_cell:n \\
\end{tabular}
\group_end:
}
\cs_new:Nn \__deadlingo_cipher_cell:n { & #1 }
\ExplSyntaxOff
\begin{document}
Here is one cipher
\begin{center}
\cipher{Z Y X W V U T S R Q P O N M L K J I H G F E D C B A}
\end{center}
and here's another one, usually called ROT13,
\begin{center}
\cipher{N O P Q R S T U V W X Y Z A B C D E F G H I J K L M}
\end{center}
\end{document}
如果您喜欢等宽字体:
\documentclass{article}
\usepackage{xparse,array}
\ExplSyntaxOn
\NewDocumentCommand{\cipher}{m}
{% #1 = a permutation of 26 letters
\deadlingo_cipher:n { #1 }
}
\cs_new_protected:Nn \deadlingo_cipher:n
{
\group_begin:
\setlength{\tabcolsep}{0pt}\ttfamily
\begin{tabular}{l@{\hspace{1em}}*{26}{w{c}{1em}}}
\normalfont Plaintext:
\tl_map_function:nN {ABCDEFGHIJKLMNOPQRSTUVWXYZ} \__deadlingo_cipher_cell:n \\
\normalfont Ciphertext:
\tl_map_function:nN {#1} \__deadlingo_cipher_cell:n \\
\end{tabular}
\group_end:
}
\cs_new:Nn \__deadlingo_cipher_cell:n { & #1 }
\ExplSyntaxOff
\begin{document}
Here is one cipher
\begin{center}
\cipher{Z Y X W V U T S R Q P O N M L K J I H G F E D C B A}
\end{center}
and here's another one, usually called ROT13,
\begin{center}
\cipher{N O P Q R S T U V W X Y Z A B C D E F G H I J K L M}
\end{center}
\end{document}