4

I am using the scrreprt class and I want footnotes defined as:

\deffootnote{2.0em}{1.5em}{\makebox[2.0em][l]{\thefootnotemark.\ }}

This footnote style works well for footnotes 1-99. However, there is not enough space for the number in the footnote when the footnote counter reaches 100. Currently, I am redefining the footnote by placing \CenturyFootnote on the page the 100th footnote appears. (It is acceptable if smaller footnotes also appear on this page.)

\newcommand*{\CenturyFootnote}{\deffootnote{2.4em}{1.9em}{\makebox[2.4em][r]{\thefootnotemark.\ \ }}}

However, this means I have to update the placement of this command whenever the text changes. How can I ensure this command is read just prior to the footnote reaching 100.

3 Answers 3

7

You can add tests to the various arguments of \deffootnote. As long as they are expandable it should work fine:

\documentclass{scrartcl}
\usepackage{xcolor,kantlipsum}
\deffootnote{\ifnum\the\value{footnote}<100 2.0em\else 3cm\fi}
            {\ifnum\the\value{footnote}<100 2.0em\else 2cm\fi}
            {\makebox[\ifnum\the\value{footnote}<100 2.0em\else 3cm\fi][l]{\thefootnotemark.\ }}

\begin{document}
\kant[9]\footnote{\kant[9] blblblb }

\setcounter{footnote}{99}
\kant[9]\footnote{\kant[9] blblbl }


\end{document}

enter image description here

5
  • You don't need \the\value, just \value is sufficient: \value{footnote} is a legal <number> in the context of \ifnum.
    – egreg
    Oct 28, 2016 at 8:25
  • @egreg: probably in my next life I will be able to remember when you need \the and when not in the context of mixed tex/latex code (in a real style I would use expl3 for this). Oct 28, 2016 at 8:36
  • Is it possible for the test to be of the value of the maximum footnote on the page?
    – Hugh
    Oct 30, 2016 at 3:39
  • Should be possible with zref. Oct 30, 2016 at 7:35
  • See tex.stackexchange.com/questions/348891/…
    – Hugh
    Jan 26, 2017 at 3:28
3

Instead of hard-coding the values of the footnote construction, assign them to lengths. This way you can change the lengths and the associated footnote mark definition would change along with it. It's similar to redefining the footnote mark definition, but doesn't require the overhead.

Below I define two lengths - \fnmarkA and \fnmarkB. I also redefine the way \footnote works in order to condition on the footnote number. All footnotes are set in the usual way until you reach footnote number 99. At that point, the \fnmarkA and \fnmarkB lengths are updated, and the original \footnote definition is restored (to avoid more overhead due to unnecessary conditioning).

enter image description here

\documentclass{scrreprt}

\usepackage{lipsum,xparse}

\newlength{\fnmarkA}\newlength{\fnmarkB}

\setlength{\fnmarkA}{2em}
\setlength{\fnmarkB}{1.5em}
\let\oldfootnote\footnote% Store \footnote definition
\deffootnote{\fnmarkA}{\fnmarkB}{\makebox[\fnmarkA][l]{\thefootnotemark.\ }}% < 100
\RenewDocumentCommand{\footnote}{ o m }{%
  \IfValueTF{#1}
    {\oldfootnote[#1]{#2}}% \footnote[.]{..}
    {\oldfootnote{#2}}% \footnote{..}
  \ifnum\value{footnote}=99
    \addtolength{\fnmarkA}{.5em}% Associated with \footnote 100+
    \addtolength{\fnmarkB}{.5em}% Associated with \footnote 100+
    \let\footnote\oldfootnote% Restore original footnote definition (avoid overhead)
  \fi
}


\def\x{\lipsum[2]\footnote{Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
  Proin sagittis mattis vulputate. Aliquam dignissim, nulla scelerisque hendrerit dictum, 
  enim ante molestie nulla, in fringilla massa nisi sit amet nulla.}}
\def\y{\x\x\x\x\x\x\x\x}


\begin{document}

\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y\y

\end{document}

xparse was merely used for its easy way of managing optional arguments (which \footnote provides) and/or conditioning on their existence/use.

2

Modify \footnote to make a check on the footnote number: if it is 99, issue the change.

However, this change should be act globally on the commands redefined by \deffootnote, so we have to make a “global” version. What's the problem? If \deffootnote is issued in an environment, like in the example below, the action will disappear as soon as the environment ends.

\documentclass{scrreprt}
\usepackage{xpatch,letltxmacro}

\deffootnote{2.0em}{1.5em}{\makebox[2.0em][l]{\thefootnotemark.\ }}

\makeatletter
\xpretocmd{\footnote}{\ifnum\value{footnote}=99 \hundredthfootnote\fi}{}{}
\LetLtxMacro\globaldeffootnote\deffootnote
\xpatchcmd{\globaldeffootnote}
  {\long\def\@makefntext}
  {\long\gdef\@makefntext}
  {}{}
\xpatchcmd{\globaldeffootnote}
  {\def\@@makefnmark}
  {\gdef\@@makefnmark}
  {}{}
\newcommand*{\hundredthfootnote}{%
  \globaldeffootnote{2.4em}{1.9em}{\makebox[2.4em][r]{\thefootnotemark.\ \ }}%
}
\makeatother

\textheight=4cm % just for making the picture

\begin{document}

\setcounter{footnote}{98}

x\footnote{Normal footnote}

\begin{itemize}
\item y\footnote{Hundredth footnote}
\end{itemize}

z\footnote{Another}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .