脚注标记定位

脚注标记定位

我在手稿中使用代码以特殊方式设置脚注标记。所有脚注标记都设置为左对齐。除了脚注标记具有不同数字的页面。在这样的页面上,最大脚注的最右边的数字为所有其他脚注提供了位置。

代码来自@cabohah,已发布这里

一切都运行良好。经过两次编译后,一切都很好。每个带有 1、2 甚至 3 位数字的脚注的位置都符合我的要求。

但是我发现了一个例子,当代码失败并向aux文件写入损坏的脚注 - 页面 - 关系时。\setcounter{footnote}{4}提供脚注标记 5-9 的错误定位,以 3 或 5 启动脚注计数器可获得正确的定位。

有什么帮助可以调试这个问题吗?

\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
      \thefootnotemark% bold footnote mark
      % HJELE \bfseries\thefootnotemark% bold footnote mark
    }%
  }%
}
\makeatletter
\AddtoDoHook{footnote/text/begin}{%
  \settowidth{\myfnnumwidth}{\footnotesize\thefootnotemark}% width of current footnote mark
  % HJELE \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}
  % HJELE \settowidth{\myfnindent}{\footnotesize\bfseries 888\enskip}% In this example
  \settowidth{\myfnindent}{\footnotesize 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]

% HJELE: set this value to 3 or 5, everything is fine
% HJELE: set this value to 4, the positioning of the
%        footnotemarks is just on this page incorrect
%        --> see the aux file for the wrong page--footnote--relation
\setcounter{footnote}{5}
Very small footnotemark.\footnote{\blindtext}

Very small footnotemark.\footnote{\blindtext}

Very small footnotemark.\footnote{\blindtext}

Very small footnotemark.\footnote{\blindtext}

Very small footnotemark.\footnote{\blindtext}

A one digit bigger footnotemark.\footnote{huhu}

\lipsum[1-2]

\end{document}

正确定位 错误定位

答案1

在这个荒谬的要求中,移动脚注会出现问题。例如,也许再运行一次 LaTeX,因为每个脚注都有一个标签,所以可以解决这个问题:

\documentclass[pagesize,% Option is already the default. So you can remove it.
  parskip=half,DIV=11]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}% shouldn't be needed any longer
\usepackage[german]{babel}% Do you really use the old German spelling from the
                          % last century???
\usepackage{microtype}
\usepackage{blindtext}
\usepackage{lipsum}
\usepackage{refcount}
\parindent 7mm% BAD CODE! See the KOMA-Script manual how to change paragraph
              % indent and paragraph skip. But using both is not recommended!

\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
      \thefootnotemark% bold footnote mark
      % HJELE \bfseries\thefootnotemark% bold footnote mark
    }%
  }%
}
\makeatletter
\AddtoDoHook{footnote/text/begin}{%
  \settowidth{\myfnnumwidth}{\footnotesize\thefootnotemark}% width of current footnote mark
  % HJELE \settowidth{\myfnnumwidth}{\footnotesize\bfseries\thefootnotemark}%
  % width of current footnote mark
  \label{ftn:\thefootnotemark}%
  \immediate\write\@auxout{\noexpand\global\noexpand\@namedef{fnnumwidth@\getpagerefnumber{ftn:\thefootnotemark}}{\the\myfnnumwidth}}% write it as current widest per page mark width to aux-file
  \@ifundefined{fnnumwidth@\getpagerefnumber{ftn:\thefootnotemark}}{}{% if the aux file has had per page values for this page
    \setlength{\myfnnumwidth}{\@nameuse{fnnumwidth@\getpagerefnumber{ftn:\thefootnotemark}}}% 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}
  % HJELE \settowidth{\myfnindent}{\footnotesize\bfseries 888\enskip}% In this example
  \settowidth{\myfnindent}{\footnotesize 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]

% HJELE: set this value to 3 or 5, everything is fine
% HJELE: set this value to 4, the positioning of the
%        footnotemarks is just on this page incorrect
%        --> see the aux file for the wrong page--footnote--relation
\setcounter{footnote}{4}
Very small footnotemark.\footnote{\blindtext}

Very small footnotemark.\footnote{\blindtext}

Very small footnotemark.\footnote{\blindtext}

Very small footnotemark.\footnote{\blindtext}

Very small footnotemark.\footnote{\blindtext}

A one digit bigger footnotemark.\footnote{huhu}

\lipsum[1-2]

\end{document}

注意:我不推荐这种奇怪的脚注格式。所以我不会为此花费更多时间。

相关内容