0

I did not find very much information about how to create ones footnote style within koma script docs. This is what I get after a very first try. What I need is more difficult and shown in the example below. Are there any footnote experts who can help? Thx, HaraldThe code output and what I need

\documentclass[pagesize,parskip=half,DIV=11]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{microtype}
\usepackage{blindtext}
\usepackage{lipsum}
%\usepackage{patchx}
\parindent 7mm

\newlength{\currentfnumwidth}
\makeatletter
\pretocmd{\@footnotetext}{%
    \settowidth{\currentfnumwidth}{\footnotesize\bfseries\thefootnotemark\quad\enskip}%
  \deffootnote[\currentfnumwidth]{0em}{1em}{%
      \bfseries\thefootnotemark\quad\enskip
  }%
}{}{}
\makeatother
 
\begin{document}

\lipsum[1]

\setcounter{footnote}{7}
Very small footnotemark.\footnote{\blindtext}
 
\setcounter{footnote}{887}
Much bigger footnotemark.\footnote{\blindtext}
 
\setcounter{footnote}{7}
This shows what I would need.\footnote{\blindtext}

\setcounter{footnote}{887}
This shows what I would need.\footnote{\blindtext}
 
\end{document}

2 Answers 2

4

It is not really clear, what you want. There are several possibilities:

  1. Per document with manual setting of the indent:

    \documentclass[pagesize,parskip=half,DIV=11]{scrartcl}[2022/05/01]% at least KOMA-Script 3.36
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}% shouldn't be needed any longer
    \usepackage[german]{babel}
    \usepackage{microtype}
    \usepackage{blindtext}
    \usepackage{lipsum}
    \parindent 7mm% Really, paragraph skip _and_ indent???
    
    \newlength{\myfnumwidth}
    \AtBeginDocument{% becaue font initialization usually happens at \begin{document}
      \settowidth{\myfnumwidth}{\footnotesize\bfseries 888\enskip}% in this example 888 is the widest used number
      \deffootnote{\myfnumwidth}{\myfnumwidth}{\bfseries\thefootnotemark\enskip}%
    }
    
    \begin{document}
    
    \lipsum[1]
    
    \setcounter{footnote}{7}
    Very small footnotemark.\footnote{\blindtext}
    
    \setcounter{footnote}{887}
    Much bigger footnotemark.\footnote{\blindtext}
    
    \end{document}
    

    static footnote indent

  2. Per footnote:

    \documentclass[pagesize,parskip=half,DIV=11]{scrartcl}% at least KOMA-Script 3.36
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}% shouldn't be needed any longer
    \usepackage[german]{babel}
    \usepackage{microtype}
    \usepackage{blindtext}
    \usepackage{lipsum}
    \parindent 7mm% Really, paragraph skip _and_ indent???
    
    \newlength{\myfnumwidth}
    \deffootnote{\myfnumwidth}{\myfnumwidth}{\bfseries\thefootnotemark\enskip}%
    \makeatletter
    \AddtoDoHook{footnote/text/begin}{%
      \settowidth{\myfnumwidth}{\footnotesize\bfseries\thefootnotemark\enskip}% use the needed width of the current number
      \@gobble}
    \makeatother
    
    \begin{document}
    
    \lipsum[1]
    
    \setcounter{footnote}{7}
    Very small footnotemark.\footnote{\blindtext}
    
    \setcounter{footnote}{887}
    Much bigger footnotemark.\footnote{\blindtext}
    
    \end{document}
    

    dynamic with of footnote indent

  3. Per page with automatic setting of the indent:

    \documentclass[pagesize,parskip=half,DIV=11]{scrartcl}% at least KOMA-Script 3.36
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}% shouldn't be needed any longer
    \usepackage[german]{babel}
    \usepackage{microtype}
    \usepackage{blindtext}
    \usepackage{lipsum}
    \parindent 7mm% Really, paragraph skip _and_ indent???
    
    \newlength{\myfnnumwidth}
    \deffootnote{\myfnnumwidth}{\myfnnumwidth}{\bfseries\thefootnotemark\enskip}%
    \makeatletter
    \AddtoDoHook{footnote/text/begin}{%
      \settowidth{\myfnnumwidth}{\footnotesize\bfseries\thefootnotemark\enskip}%
      \immediate\write\@auxout{\noexpand\global\noexpand\@namedef{fnnumwidth@\thepage}{\the\myfnnumwidth}}% store the current width for this page in the aux-file
      \@ifundefined{fnnumwidth@\thepage}{}{% if a width for this page has been stored
        \setlength{\myfnnumwidth}{\@nameuse{fnnumwidth@\thepage}}% use it
      }%
      \@gobble}
    \makeatother
    
    \begin{document}
    
    \lipsum[1-3]
    
    \setcounter{footnote}{7}
    Very small footnotemark.\footnote{\blindtext}
    
    Very small footnotemark.\footnote{\blindtext}
    
    \lipsum[1-3]
    
    Very small footnotemark.\footnote{\blindtext}
    
    Bigger footnotemark.\footnote{\blindtext}
    
    \lipsum[1-3]
    
    \setcounter{footnote}{98}
    Bigger footnotemark.\footnote{\blindtext}
    
    Much bigger footnotemark.\footnote{\blindtext}
    
    \setcounter{footnote}{887}
    Much, much bigger footnotemark.\footnote{\blindtext}
    
    \end{document}
    

    Note, this last example needs at least two LaTeX runs to show:

    with per page width automatism

  4. Per document with automatism for last used footnote number:

    \documentclass[pagesize,parskip=half,DIV=11]{scrartcl}[2022/05/01]% at least KOMA-Script 3.36
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}% shouldn't be needed any longer
    \usepackage[german]{babel}
    \usepackage{microtype}
    \usepackage{blindtext}
    \usepackage{lipsum}
    \parindent 7mm% Really, paragraph skip _and_ indent???
    
    \newlength{\myfnnumwidth}
    \deffootnote{\myfnnumwidth}{\myfnnumwidth}{\bfseries\thefootnotemark\enskip}%
    \makeatletter
    \AddToHook{enddocument/afterlastpage}{% after the final page
      \settowidth{\@tempdima}{\footnotesize\bfseries \thefootnotemark\enskip}% get the width of last footnote number
      \immediate\write\@auxout{\global\noexpand\myfnnumwidth\the\@tempdima\relax}% write it to aux file to be used in next LaTeX run
    }
    \makeatother
    
    \begin{document}
    
    \lipsum[1]
    
    \setcounter{footnote}{7}
    Very small footnotemark.\footnote{\blindtext}
    
    \lipsum[2-5]
    
    \setcounter{footnote}{887}
    Much bigger footnotemark.\footnote{\blindtext}
    
    \end{document}
    

    This example also needs at least two LaTeX runs and would fail, if the last footnote number is not the widest number. If you LaTeX is older than 2020/10/01, you should replace \AddToHook{enddocument/afterlastpage} by \BeforeClosingMainAux (see the KOMA-Script manual for more information about \BeforeClosingMainAux).

    per document

  5. Combination of example 3 with example 1 = static indent of the footnote text but automatic right alignment of the footnote number in the width of the widest footnote per page:

    \documentclass[pagesize,parskip=half,DIV=11]{scrartcl}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}% shouldn't be needed any longer
    \usepackage[german]{babel}
    \usepackage{microtype}
    \usepackage{blindtext}
    \usepackage{lipsum}
    \parindent 7mm% Really, paragraph skip _and_ indent???
    
    \newlength{\myfnindent}
    \newlength{\myfnnumwidth}
    \deffootnote{\myfnindent}{\myfnindent}{% indent of footnote text and paragraphs
      \makebox[\myfnindent][l]{% inside this indent left align a 
        \makebox[\myfnnumwidth][r]{% box of per page number width with right aligned
          \bfseries\thefootnotemark% bold footnote mark
        }%
      }%
    }
    \makeatletter
    \AddtoDoHook{footnote/text/begin}{%
      \settowidth{\myfnnumwidth}{\footnotesize\bfseries\thefootnotemark}% width of current footnote mark
      \immediate\write\@auxout{\noexpand\global\noexpand\@namedef{fnnumwidth@\thepage}{\the\myfnnumwidth}}% write it as current widest per page mark width to aux-file
      \@ifundefined{fnnumwidth@\thepage}{}{% if the aux file has had per page values for this page
        \setlength{\myfnnumwidth}{\@nameuse{fnnumwidth@\thepage}}% use (the last one) as current width of the number bix
      }%
      \@gobble% Because the do-hook code expects always has an argument.
    }
    \makeatletter
    
    \AtBeginDocument{% becaue font initialization usually happens at \begin{document}
      \settowidth{\myfnindent}{\footnotesize\bfseries 888\enskip}% In this example
                                    % 888 is the widest used number and this is
                                    % used to setup the footnote text indent.
    }
    
    \begin{document}
    
    \lipsum[1-3]
    
    \setcounter{footnote}{8}
    Very small footnotemark.\footnote{\blindtext}
    
    Very small footnotemark.\footnote{\blindtext}
    
    \lipsum[1-3]
    
    \setcounter{footnote}{98}
    Bigger footnotemark.\footnote{\blindtext}
    
    Much bigger footnotemark.\footnote{\blindtext}
    
    \setcounter{footnote}{887}
    Much, much bigger footnotemark.\footnote{\blindtext}
    
    \end{document}
    

    combination of static footnote text indent with right aligned numbers in the width of the widest number per page

  6. Combination of example 3 and 4: Same like above but with automatic detection of the width of the last footnote number. To do this, in example 5 just replace

    \AtBeginDocument{% becaue font initialization usually happens at \begin{document}
      \settowidth{\myfnindent}{\footnotesize\bfseries 888\enskip}% In this example
                                    % 888 is the widest used number and this is
                                    % used to setup the footnote text indent.
    }
    

    by

    \AddToHook{enddocument/afterlastpage}{% after the final page
      \settowidth{\@tempdima}{\footnotesize\bfseries \thefootnotemark\enskip}% get the width of last footnote number
      \immediate\write\@auxout{\global\noexpand\myfnindent\the\@tempdima\relax}% write it to aux file to be used in next LaTeX run
    }
    

See Figure 3.1 in the KOMA-Script manual for more information about the three length arguments (one optional and two mandatory) of \deffootnote.

See Section 12.8 of the KOMA-Script manual for more information about \AddtoDoHook.

13
  • Thanks a lot @cabohah. Your very first code example perfectly fits my needs. Simple and clever, I must say. But I do not see the "page automatism" in your last code. Sorry, it's late in the evening. Harald
    – hjele
    Feb 24 at 20:43
  • In the morning I recognized what your third example does. Thx for the explanation. Of course, I voted for it, but I do not have enough points of interaction that you can see this. But the system counted this ;-)
    – hjele
    Feb 25 at 16:16
  • I thought your example one would fit my needs. But indeed, I need a pagewise one. When compiling your ex. 3 I did not get what you posted in your figures. Please see [link]wwwu.aau.at/hjele/latex_examples/… -- or could I post a picture into comments?? Thx for your help!
    – hjele
    Feb 27 at 9:09
  • @hjele Have you done at least 2 LaTeX runs? Is your TeX installation – at least KOMA-Script – up-to-date? I've tested with KOMA-Script 3.38 of an up-to-date TeX Live 2022 and TeX Live 2023 pretest. Both with pdflatex and lualatex. Even the first LaTeX run does not show your result. Additionally I've tested with TeX Live 2021 and KOMA-Script 3.36.3772. All of them show the result I've shown in my screenshot.
    – cabohah
    Feb 27 at 9:48
  • @hjele According to the KOMA-Script manual, the do-hook /footnote/text/begin is available from KOMA-Script 3.36. So if it does not work, I assume, you are using an outdated TeX installation and should update.
    – cabohah
    Feb 27 at 9:56
0

What you are trying to achieve probably is described in the KOMA-script manual. You get the whole book with texdoc scrguideon the command line. Have a look into section 3.14, there are some examples.

\documentclass[ngerman,parskip=half,DIV=11]{scrartcl} % pagesize no longer needed
\usepackage[T1]{fontenc}
%\usepackage[utf8]{inputenc} %% LaTeX is on UTF-8 as default since some years
\usepackage{babel}% put the language into the documentclass options
\usepackage{microtype}
\usepackage{blindtext}
%\usepackage{lipsum}
%\usepackage{patchx}
%\parindent 7mm

% \newlength{\currentfnumwidth}
% \makeatletter
% \pretocmd{\@footnotetext}{%
%     \settowidth{\currentfnumwidth}{\footnotesize\bfseries\thefootnotemark\quad\enskip}%
%   \deffootnote[\currentfnumwidth]{0em}{1em}{%
%       \bfseries\thefootnotemark\quad\enskip
%   }%
% }{}{}
% \makeatother

\deffootnote[2em]{2em}{0pt}{%
  \makebox[2em][l]{\thefootnotemark}%
}


\begin{document}

\blindtext

\setcounter{footnote}{7}
Very small footnotemark.\footnote{\blindtext}
 
\setcounter{footnote}{887}
Much bigger footnotemark.\footnote{\blindtext}
 
\setcounter{footnote}{7}
This shows what I would need.\footnote{\blindtext}

\setcounter{footnote}{887}
This shows what I would need.\footnote{\blindtext}
 
\end{document}

Result:

screenshot of PDF

3
  • For all I currently understand, he does not want left aligned numbers. He wants the numbers right aligned in the width of the largest number per page. And the indent of the text should be the same for all pages and depend on the overall largest number. Somehow strange, but see the chat for more information.
    – cabohah
    Mar 1 at 12:29
  • @cabohah Well, right aligned would be \makebox[2em][r]{\thefootnotemark}% instead of \makebox[2em][l]{\thefootnotemark}%. And having different margins on per page basis according to the width of the footnotenumber makes no sense at all.
    – Keks Dose
    Mar 1 at 12:54
  • Whether it makes sense or not is not the question. He wants it (once again: see the long discussion below my answer and also the chat), so I've shown how to get it. Sorry, but IMHO currently your answer does not answer the question.
    – cabohah
    Mar 1 at 13:03

You must log in to answer this question.

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