答案1
一些替代方案:
\documentclass{article}
\usepackage{tabstackengine,tokcycle}
\parskip 1em
\begin{document}
\begin{center}
OP Method:
\begin{tabular}{ c c c c c c c c c c c c }
C&R&Y&P&T&O&G&R&A&P&H&Y \\
A&B&C&D&E&F&G&H&I&J&K&L \\
\end{tabular}
\setstacktabbedgap{2ex}% INTER-COLUMN GAP
\setstackgap{L}{1.1\baselineskip}% BASELINESKIP FOR LONG STACKS
Stack: \tabbedCenterstack{
C&R&Y&P&T&O&G&R&A&P&H&Y \\
A&B&C&D&E&F&G&H&I&J&K&L}
Token Cycle:\\
\tokencycle{\makebox[4ex]{#1}}{}{#1}{\makebox[4ex]{#1}}
CRYPTOGRAPHY\\
ABCDEFGHIJKL\\
MY TEST
\endtokencycle
ttfamily and spaceskip:\\
\ttfamily\spaceskip=2ex
C R Y P T O G R A P H Y\\
A B C D E F G H I J K L
\end{center}
\end{document}
答案2
答案3
只是为了好玩,这是凯撒密码的一个实现,所以你甚至不需要选择第二行。每个字符保留的宽度与表中最宽的字符相同。
\documentclass{article}
\usepackage{array}
\ExplSyntaxOn
\NewDocumentCommand{\caesar}{mm}
{
\group_begin:
\setlength{\tabcolsep}{0pt}
\seq_set_split:Nnn \l_tmpa_seq { } { #2 }
\seq_set_map_x:NNn \l_tmpb_seq \l_tmpa_seq
{
\char_generate:nn
{
`##1 + (#1)
\int_compare:nT { `##1 + (#1) < `A } { +26 }
\int_compare:nT { `##1 + (#1) > `Z } { -26 }
}
{ 11 }
}
\dim_zero:N \l_tmpa_dim
\seq_map_inline:Nn \l_tmpa_seq
{
\hbox_set:Nn \l_tmpa_box { ##1 }
\dim_compare:nT { \box_wd:N \l_tmpa_box > \l_tmpa_dim}
{
\dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }
}
}
\seq_map_inline:Nn \l_tmpb_seq
{
\hbox_set:Nn \l_tmpa_box { ##1 }
\dim_compare:nT { \box_wd:N \l_tmpa_box > \l_tmpa_dim}
{
\dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }
}
}
\begin{tabular}{*{\seq_count:N \l_tmpa_seq}{wc{\l_tmpa_dim}}}
\seq_use:Nn \l_tmpa_seq { & } \\
\seq_use:Nn \l_tmpb_seq { & }
\end{tabular}
\group_end:
}
\ExplSyntaxOff
\begin{document}
\caesar{-2}{CRYPTOGRAPHY} \qquad \caesar{2}{CRYPTOGRAPHY}
\bigskip
\caesar{2}{APWNRMEPYNFW} \qquad \caesar{-2}{ETARVQITCRJA}
\end{document}
答案4
您可以不使用表格等宏来完成此对齐,仅使用 TeX 基元:
\def\cryp #1{\hbox\bgroup \crypA#1\end}
\def\crypA #1{\ifx\end#1\egroup\else \hbox to1em{\hss#1\hss}\expandafter\crypA\fi}
\cryp{CRYPTOGRAPHY}
\cryp{ABCDEFGHIJKL}
你可以按你想要的\hbox to1em
改变。\hbox to<another value>