# Is there a way to align the footnote mark with the top of the footnote text?

Here is a MWE:

\documentclass[12pt]{scrartcl}
%%Footnote Mods%%
\deffootnote[1.8em]{0pt}{1.6em}{\textsuperscript{\thefootnotemark}}
%%%%%%
\begin{document}

Sample text%
%
\footnote{Footnote text}
%
\end{document}


How do I align the top of the footnote mark with the top of the footnote text (in the MWE, I want to have the top of the "1" flush with the "F")?

New error: when implementing Werner's (great) solution I ran into an error when trying to add anything with a "\" in it into the footnote text.

Observe:

\documentclass[12pt]{scrartcl}% http://ctan.org/pkg/koma-script
\usepackage{xstring}% http://ctan.org/pkg/xstring
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
% Patch \scr@saved@footnotetext to extract first character of footnote and store         in \fnfirstchar
\patchcmd{\scr@saved@footnotetext}% <cmd>
{\@makefntext}% <search>
{\StrLeft{#1}{1}[\fnfirstchar]\@makefntext}% <replace>
{}{}% <success><failure>
\begin{document}

\makeatletter
\deffootnote[1.8em]{0pt}{1.6em}{%
\settoheight{\@tempdima}{\fnfirstchar}% Height of first character in footnote
\settoheight{\@tempdimb}{$\scriptstyle\thefootnotemark$}% Height of footnote mark
\raisebox{\dimexpr\@tempdima-\@tempdimb}{$\scriptstyle\thefootnotemark$}}
\makeatother

Sample text\footnote{Footnote text: \S modified}.

\end{document}

-

The short answer to this is that "exact placement" is not always possible. Why? It is important to note that TeX works with boxes and not characters. Each character has a bounding box that defines its horizontal and vertical size/structure. So, alignment of elements can only be done up to the precision of these boxes. In that sense, the best you can do is probably:

\makeatletter
\deffootnote[1.8em]{0pt}{1.6em}{%
\settoheight{\@tempdima}{F}% Height of F
\settoheight{\@tempdimb}{$\scriptstyle\thefootnotemark$}% Height of footnote mark
\raisebox{\dimexpr\@tempdima-\@tempdimb}{$\scriptstyle\thefootnotemark$}}
\makeatother


This stores the height of F and a \scriptstyle footnote mark in \@tempdima and \@tempdimb, respectively (these are scratch registers). Then it raises the footnotemark (given by \thefootnotemark) to the correct height. The output is not as expected, due to the "boxing restrictions." Here's a minimal example showing the different outputs, just as an example. It is also updated to capture the first character of the footnote (rather than fixing it to the character F):

\documentclass[12pt]{scrartcl}% http://ctan.org/pkg/koma-script
\usepackage{xstring}% http://ctan.org/pkg/xstring
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
% Patch \scr@saved@footnotetext to extract first character of footnote and store in \fnfirstchar
\patchcmd{\scr@saved@footnotetext}% <cmd>
{\@makefntext}% <search>
{\StrLeft{#1}{1}[\fnfirstchar]\@makefntext}% <replace>
{}{}% <success><failure>
\begin{document}

% Original footnote modification
\deffootnote[1.8em]{0pt}{1.6em}{\textsuperscript{\thefootnotemark}}
Sample text\footnote{Footnote text: original}.

\makeatletter
\deffootnote[1.8em]{0pt}{1.6em}{%
\settoheight{\@tempdima}{\fnfirstchar}% Height of first character in footnote
\settoheight{\@tempdimb}{$\scriptstyle\thefootnotemark$}% Height of footnote mark
\raisebox{\dimexpr\@tempdima-\@tempdimb}{$\scriptstyle\thefootnotemark$}}
\makeatother

Sample text\footnote{Footnote text: modified}.

\end{document}


xstring captures the first character of the footnote (via \StrLeft) and stores it in \fnfirstchar, while etoolbox patches the appropriate command by inserting the extraction in the right spot (after the footnote text has been read, but before it is being typeset).

As illustration, boxing the footnote mark and F character shows that they're placed at the same height (as TeX sees it):

-
Is there any way to modify your (great) suggestion to always set to the height of the letter that immediately follows the footnote mark as opposed to the letter "F"? –  Dennis Aug 23 '12 at 5:55
@Dennis: I've updated my answer to incorporate such a modification. Note that you might get unexpected results if you start your footnote with a space. –  Werner Aug 23 '12 at 6:22
Thank you for all of your help. Your MWE is working fine for me, but when I change it to add anything with a "\" in it, I get an error. I've updated my question to provide an MWE of the error. –  Dennis Aug 23 '12 at 7:23
@Dennis: As of now, I'm not sure how to solve the problem... I noticed you posted something on meta. –  Werner Aug 23 '12 at 21:08
Yes I did, I wasn't sure whether it was appropriate to keep bugging you for help or whether this warranted a new question. Thank you for all of your help. –  Dennis Aug 23 '12 at 22:29
show 1 more comment

A less technical but more typographical way might be to use the package superiors. Quoting from the manual:

The default behavior of footnote and endnote markers in LaTeX is to print the number as if it were a mathematical superscript. In most cases, this means the size is about 70% of the normal lining figure and the top is somewhat above the tops of capital letters. In many cases, the superscript figure is simply reduced in all dimensions by about 70%, making them appear rather slight, though overly tall. [...]

As an alternative, one may use superior figures—small figures, usually 50% to 60% of the height of lining figures, like 1234567890. Commonly, they are designed so that the tops of the numbers are aligned with the tops of the capital letters in the font, though sometimes a little higher, corresponding to the ascender height.

\documentclass[12pt]{scrartcl}
%%Footnote Mods%%
\deffootnote[1.8em]{0pt}{1.6em}{\textsu{\thefootnotemark}\,}
%%%%%%
\usepackage{newtxtext}
\usepackage[supstfm=ntxsups,supspaced=.06em]{superiors}
\begin{document}

Sample text%
%
\footnote{Footnote text}
%
\end{document}


Additionally the package option raised=<dim> would allow to adjust the vertical position of the superscript numbers. Of course the vertical position would not depend on following characters. (But what if the following token is a small a or a control sequence anyway?)

-
This seems to be roughly what I'm looking for. At a first pass I can't get it to do exactly what I want but that's a problem for another day. Thanks! –  Dennis Aug 23 '12 at 8:28

I didn't see the need to load any package in Werner's solution. Both etoolbox and xstring are relatively large packages.

\documentclass[12pt]{scrartcl}
\makeatletter
\begingroup
\let\@tempa\scr@saved@footnotetext
\edef\@tempa{\endgroup
\def\noexpand\scr@saved@footnotetext##1{%
\unexpanded\expandafter{\@tempa{#1}}%
\unexpanded{\fngetfirstchar\fnfirstchar{#1}}%
}%
}
\@tempa
\def\fngetfirstchar#1#2{%
\begingroup
\def\@tempa##1##2\fn@nil{\endgroup\gdef#1{##1}}%
\expandafter\@tempa#2\fn@nil
}
\def\usenewfootnotestyle{%
\deffootnote[1.8em]{0pt}{1.6em}{%
\begingroup
\let\s\ensuremath
\settoheight{\@tempdima}{\fnfirstchar}%
\settoheight{\@tempdimb}{\s{\scriptstyle\thefootnotemark}}%
\raisebox{\dimexpr\@tempdima-\@tempdimb}{\s{\scriptstyle\thefootnotemark}}%
\endgroup
}%
}
\makeatother
\begin{document}
% Original footnote style:
\deffootnote[1.8em]{0pt}{1.6em}{\textsuperscript{\thefootnotemark}}
Sample text\footnote{Footnote text: original}.
\par