\documentclass[10pt]{article}
\usepackage{ulem,amsmath}
\newcommand{\unline}[1]{\rule[0pt]{#1}{0.6pt}}
\usepackage[T1]{fontenc}
\usepackage[sfdefault]{AlegreyaSans}
\begin{document}
\begin{tabular}{llll}
1$^{\text{st}}$& first & 17$^{\text{th}}$ & seventeenth \\
2$^{\text{nd}}$& \unline{2cm} & 18$^{\text{th}}$ & \unline{2cm} \\
3$^{\text{rd}}$& \unline{2cm} & 19$^{\text{th}}$ & \unline{2cm} \\
4$^{\text{th}}$& \unline{2cm}& 20$^{\text{th}}$ & \unline{2cm} \\
5$^{\text{th}}$& \unline{2cm}& 21$^{\text{st}}$ & \unline{2cm} \\
6$^{\text{th}}$& \unline{2cm} & 22$^{\text{nd}}$ & \unline{2cm} \\
7$^{\text{th}}$& seventh& 23$^{\text{rd}}$& \unline{2cm}\\
8$^{\text{th}}$& \unline{2cm}& 24$^{\text{th}}$ & twenty$-$fourth \\
9$^{\text{th}}$& \unline{2cm}& 25$^{\text{th}}$ & twenty$-$fifth \\
10$^{\text{th}}$& \unline{2cm}& 26$^{\text{th}}$ & twenty$-$sixth \\
11$^{\text{th}}$& \unline{2cm}& 27$^{\text{th}}$ & \unline{2cm} \\
12$^{\text{th}}$& \unline{2cm} & 28$^{\text{th}}$ & twenty$-$eighth \\
13$^{\text{th}}$& \unline{2cm}& 29$^{\text{th}}$ & \unline{2cm} \\
14$^{\text{th}}$& fourteenth& 30$^{\text{th}}$ & \unline{2cm} \\
15$^{\text{th}}$& \unline{2cm} & 31$^{\text{st}}$ & \unline{2cm} \\
16$^{\text{th}}$& sixteenth& & \\
\end{tabular}
\end{document}
How can I align the numbers, st, nd, rd and th? As you can see they aren't aligned.
I'm trying to recreate this:
(For some reason the image is flipped.)
Best Answer
Your font choice
AlegreyaSans
uses lining figures with variable widths by default. That means the glyph width of digits are not constant but varies according the shape of the digit glyph.The package defines the font
\AlegreyaSansLTF
for lining figures in tables with constant width for better vertical alignments in tables.The following example uses
\textsuperscript
for raising the suffix letters. Also, the example uses packagearray
to smuggle in a macro at the start of the cell for formatting the ordinal number.Variant with right aligned digits: