Problem aligning two alphabets

by Dead_Ling0   Last Updated October 19, 2019 22:23 PM - source

I'm trying to align two alphabets in such a way that each letter is aligned to the one below such that they fit on the page. I'm having real difficulty of doing this any suggestions would be great i've tried as much as i can. Here is as close as i've managed to get.

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

Best regards and much thanks Jay

Tags : align alignment


Answers 3


Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format.

I would use the tabular environment and a monospace font.

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

enter image description here

erik
erik
October 19, 2019 21:18 PM

If you don't want to change font, you might use something like this:

\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}
cfr
cfr
October 19, 2019 21:27 PM

A tabular is better; one can also go the extra mile and simplify the input. With w{c}{1em} we get a fixed width cell; I also set the intercolumn space to zero, because in this application it's not needed.

The \tl_map_function:nN instruction splits the first argument into tokens and applies to each one the specified function, whose duty here is to add & in front of the letter.

\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}{[email protected]{\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}

enter image description here

If you prefer a monospaced font:

\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}{[email protected]{\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}

enter image description here

egreg
egreg
October 19, 2019 22:03 PM

Related Questions


How to align numbers in all rows

Updated February 23, 2019 10:23 AM

Define a custom align, and align* environment

Updated June 11, 2017 15:23 PM