# Top align characters

I wonder if there's a good way to vertically align the tops of characters.

I'm trying to reproduce a particular style of the No. symbol which has an N with an ọ next to it (that's an o with a dot below). The top of the o and the top of the N should be level.

I tried

\documentclass[12pt]{article}

\newlength{\nheigh}
\settoheight{\nheigh}{N}

\begin{document}

N\raisebox{\nheigh}{\d{o}}

\end{document}


But of course this aligns the bottom of the o with the top of the N

Let TeX do the computations; for such jobs, lower level primitives are more flexible.

\documentclass{article}

\newcommand{\fancyno}{%
\begingroup
\sbox0{N}%
N\vbox to\ht0{%
\offinterlineskip
\ialign{\hfil##\hfil\cr o\cr\noalign{\vfill}.\cr}%
}%
\endgroup
}

\begin{document}

\end{document}


If you don't want the period to sit on the baseline, no measuring is necessary, under the assumption that \d{o} has total vertical size less than N.

\documentclass{article}

\newcommand{\fancyno}{%
\begingroup\tabskip 0pt % just for safety
\valign{##\vfill\cr\hbox{N}\cr\hbox{\d{o}}\cr}%
\endgroup
}

\begin{document}

\end{document}


Good start. The height of the o needs to be subtracted from the height of the N for the raise amount. The height of o is available as \height inside \raisebox and the calculation can be done with e-TeX's \dimexpr:

\documentclass[12pt]{article}

\newlength{\nheigh}
\settoheight{\nheigh}{N}

\begin{document}

N\raisebox{\dimexpr\nheigh-\height\relax}{\d{o}}

\end{document}


A macro can be defined that uses a local scratch register for measuring the height of the N. Then, the macro automatically adapts to the current size:

\documentclass[11pt]{article}

\newcommand*{\No}{%
\begingroup
\settoheight{\dimen0}{N}%
N\raisebox{\dimexpr\dimen0-\height\relax}{\d{o}}%
\endgroup
}

\begin{document}

{\Huge\No}{\huge\No}{\LARGE\No}{\Large\No}{\large\No}{\No}%
{\small\No}{\footnotesize\No}{\scriptsize\No}{\tiny\No}

\end{document}


Instead of using \raisebox, you can also stack \vboxes. For this \lineskip has to be zeroo to avoid unwanted space and \lineskiplimit must be big such that \lineskip is used in the first place. Then you can create a \vtop for every character which aligns at an empty box above the characters, sucht that the tops are aligned:

\documentclass[12pt]{article}

\newcommand\topalign[1]{%
\leavevmode%
\hbox{%
\providecommand\tachar[1]{\vtop{\null\hbox{##1}}}%
\vbox{%
\lineskip0pt%
\lineskiplimit\maxdimen%
\hbox{%
#1%
}%
\null%
}%
}%
}

\begin{document}
\topalign{\tachar{N}\tachar{\d{o}}}
\end{document}


With this approach you do not have to know which character is the largest.