8

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

12

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

  • Thank you for the welcome I'll make sure to read the starter guide, your solution worked a treat so thank you for that. – Dead_Ling0 Oct 19 at 21:23
8

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

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

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.