[Tex/LaTex] How to top align AND left align a box flush with the top of a paragraph

boxesvertical alignment

Using a box technique (Paragraph numbers at left margin), I added margin text.

I'd like the top of the left-aligned number to be flush with the top of the paragraph text rather than having the baselines aligned.

I am hoping to learn a box trick here. (I can do this with tikz, but I'd like to learn how to do it with TeX or LaTeX boxes) I tried adding a third \makebox[0pt][t]{1.} but I could not get it to align as desired. Is minipage the only/best way? My skills got a little weak after the Christmas vacation :=)

Code

\documentclass{article}
\usepackage{fontspec}% xelatex
\usepackage{lipsum}
\setlength{\parindent}{0mm}
\newcommand{\marginnum}[1]{\makebox[0mm][r]{\makebox[12mm][l]{\Huge\bfseries #1.}}}
\begin{document}
\marginnum{1}\lipsum[1]
\end{document}

Output

enter image description here

Desired Output using TikZ

Using a similar \makebox of zero-width technique, I create an inline node on the first line of the paragraph. I then anchor a second node to the top of that node containing my margin text.

\documentclass{article}
\usepackage{fontspec}% xelatex
\usepackage{lipsum}
\usepackage{tikz}\usetikzlibrary{calc}
\setlength{\parindent}{0mm}
\newcommand{\marginnum}[1]{%
\makebox[0pt][r]{%
\begin{tikzpicture}[remember picture]%
\node [inner sep=0pt,outer sep=0pt] (parstart) {\phantom{L}};%
\end{tikzpicture}}%
\begin{tikzpicture}[remember picture, overlay]%
\node [inner sep=0pt,outer sep=0pt,anchor=north east,font=\bfseries\Huge] at ($ (parstart.north west)+(-12mm,0) $) {#1.};%
\end{tikzpicture}%
}%
\begin{document}
\marginnum{1}\lipsum[1]
\end{document}

enter image description here

Best Answer

Raise it into position:

enter image description here

\documentclass{article}

\usepackage{lipsum}

\setlength{\parindent}{0mm}

\newcommand{\marginnum}[1]{%
  \makebox[0mm][r]{%
    \makebox[12mm][l]{%
      \raisebox{\dimexpr-\height+.6\baselineskip}[0pt][0pt]{\Huge\bfseries #1.}}}}

\begin{document}

\marginnum{1}\lipsum[1]

\end{document}

A more exact method for the vertical position would be to use identify the height of some capital letter in the current font, and raise the number into position relative to that:

\newcommand{\marginnum}[1]{%
  \makebox[0mm][r]{%
    \makebox[12mm][l]{%
      \raisebox{\dimexpr-\height+\fontcharht\font`A}[0pt][0pt]{\Huge\bfseries #1.}}}}
Related Question