我有一份这样的文档,其中我使用了vwcol
。我还想在文本中添加脚注。
\documentclass{article}
\usepackage{vwcol}
\begin{document}
\begin{vwcol}[widths={.5,.5}, sep=.8cm, justify=flush]
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque mauris purus, rhoncus in scelerisque vitae, viverra ac quam. Pellentesque habitant morbi tristique senectus\footnote{et netus et malesuada fames ac turpis egestas}. Duis in ligula sed massa aliquam accumsan. Aliquam erat volutpat. Donec nec lectus sit amet turpis pellentesque posuere vel a lorem. Pellentesque laoreet nisl eu justo varius, quis pharetra ligula iaculis.
\end{vwcol}
\end{document}
但是,脚注没有显示出来。虽然显示了段落内的脚注编号,但是编号是错误的(本例中是 3,而不是 1)。
我想在页面底部添加脚注(就像注释掉设置 vwcol 环境的行时显示的那样)。如何在使用 vwcol 时显示脚注?
答案1
这种情况有两个问题。第一个问题是将vwcol
内容设置为\parbox
,它不显示脚注。请参阅为什么 \parbox 会丢失脚注?进行更多讨论,并通过重新定义找到解决方案\@footnotetext
。
第二个问题是,vwcol
在循环中多次处理相同的输入,以计算正确的列分布。每次处理输入时,脚注计数器都会增加。文档中实际使用了最后一次运行,显示的脚注计数器跳过了前几次运行的值。
为了解决这个问题,您可以在第一次运行时只处理脚注(以在页面底部显示正确的数字并防止多次添加相同的脚注)。但是,现在段落中不显示数字,因为这是上次运行的结果。因此,您可以使用 仅打印数字\footnotemark
,并在每次运行之前将此数字重置为初始值。
实现上述目标的一个相对简单的方法是定义一个新的脚注命令,供在vwcol
环境中使用(\footnotevwc
在下面的 MWE 中)。对其余代码的必要修改很小(总共 8 行代码),但由于vwcol
使用了包\NewEnvironment
中的代码environ
,因此不幸的是代码无法轻松修补。相反,在下面的代码中使用了环境的完整重新定义,从源代码复制而来。另一个问题vwcol
中的脚注代码是另外 20 行。\parbox
完整 MWE:
\documentclass{article}
\usepackage[totalheight=8cm]{geometry}
\usepackage{vwcol}
\makeatletter
\RenewEnviron{vwcol}[1][]{%
\par\noindent
\@vwcol@boxreadyfalse
\vwcolsetup{#1}%
\splittopskip=\ht\strutbox
\expandafter\vwcol@process@widths\expandafter{\vwcol@widths}%
\vwcol@para@setup
\ifdim\vwcol@sep=1sp
\vwcol@totalwidth=\linewidth
\else
\vwcol@totalwidth=\numexpr
\vwcol@totalwidth+(\vwcol@Ncols-1)*\vwcol@sep
\relax sp
\if@vwcol@presep
\advance\vwcol@totalwidth\dimexpr(\vwcol@sep-\vwcol@rule)/2\relax
\fi
\if@vwcol@postsep
\advance\vwcol@totalwidth\dimexpr(\vwcol@sep-\vwcol@rule)/2\relax
\fi
\if@vwcol@prerule \advance\vwcol@totalwidth \vwcol@rule\fi
\if@vwcol@postrule\advance\vwcol@totalwidth \vwcol@rule\fi
\fi
\ifdim\vwcol@totalwidth > \linewidth
\vwcol@PackageWarning{%
Total width of columns plus their separations
is greater than the linewidth^^J\space\space
(by \the\vwcol@totalwidth\space - \the\linewidth\space =
\the\dimexpr \vwcol@totalwidth-\linewidth\relax)}%
\fi
\ifnum\vwcol@Nlines=0%
\@tempcnta=\hbadness
\hbadness=\maxdimen
\gdef\footnotereset{exec}%%%% set flag to process footnotes at first run
\setcounter{fntemp}{\value{footnote}}%%%% store initial footnote counter
\setbox\vwcol@plainbox\hbox{%
\parbox{\vwcol@averagewidth}{\vwcol@justify\BODY}}%
\gdef\footnotereset{reset}%%%% don't process footnotes after first run
\hbadness=\@tempcnta
\vwcol@Nlines=\numexpr
(\ht\vwcol@plainbox+\dp\vwcol@plainbox)/
(\baselineskip*\vwcol@Ncols)
\relax
\@tempcnta=1%
\loop\unless\if@vwcol@boxready
\setcounter{footnote}{\value{fntemp}}%%%% reset counter for \footnotemark
\savebox\vwcol@outputbox{%
\hbox to \vwcol@totalwidth{\vwcol@{\BODY}}}%
\unless\if@vwcol@boxready
\advance\@tempcnta 1%
\advance\vwcol@Nlines 1%
\ifnum\@tempcnta>\vwcol@maxrecursion
\@vwcol@boxreadytrue
\vwcol@PackageError{%
The estimated number of lines is greater than
\the\vwcol@maxrecursion\space lines too small,%
^^J\space\space
so I gave up (last tried maximum value of
[lines=\the\vwcol@Nlines])%
}{%
Text will be truncated in the multicolumns;
please select the%
^^J\space\space
number of lines explicitly or increase
[maxrecursion=\the\vwcol@maxrecursion].%
}%
\fi
\fi
\repeat
\usebox\vwcol@outputbox
\else
\hbox to \vwcol@totalwidth{\vwcol@{\BODY}}%
\unless\if@vwcol@boxready
\vwcol@PackageError{%
Not enough lines to fit the entire text;
some text has been truncated.^^J\space\space
Increase [lines=\the\vwcol@Nlines] to fit more%
}{%
Or remove [lines=\the\vwcol@Nlines] altogether
to have 'vwcol' estimate the value.}%
\fi
\fi\par}
\def\fnexec{exec} % comparison value for \ifx
\newcounter{fntemp} % counter to store initial footnote number
\newcommand{\footnotevwc}[1]{%
% process footnotes if flag is set to 'exec', i.e., first run
% otherwise print only the mark (using the initial number)
\ifx\footnotereset\fnexec\footnote{#1}\else\footnotemark\fi%
}
% macros for showing footnotes outside of \parbox
\newcommand{\global@insert}[2]% #1=box number, #2=vertical list
{\bgroup
\setbox\@tempboxa=\box#1
\global\setbox#1=\vbox{\unvbox\@tempboxa #2}
\egroup}
\long\def\@footnotetext#1{\global@insert\footins{%
\reset@font\footnotesize
\interlinepenalty\interfootnotelinepenalty
\splittopskip\footnotesep
\splitmaxdepth \dp\strutbox \floatingpenalty \@MM
\hsize\columnwidth \@parboxrestore
\protected@edef\@currentlabel{%
\csname p@footnote\endcsname\@thefnmark
}%
\color@begingroup
\@makefntext{%
\rule\z@\footnotesep\ignorespaces#1\@finalstrut\strutbox}%
\color@endgroup}}%
\makeatother
\begin{document}
Footnote\footnote{before}
\begin{vwcol}[widths={.5,.5}, sep=.8cm, justify=flush]
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Quisque mauris purus, rhoncus in scelerisque vitae, viverra ac quam.
Pellentesque habitant morbi tristique
senectus\footnotevwc{et netus et malesuada fames ac turpis egestas}.
Duis in ligula sed massa aliquam accumsan.\footnotevwc{Aliquam erat volutpat.}
Donec nec lectus sit amet turpis pellentesque posuere vel a lorem.
Pellentesque laoreet nisl eu justo varius, quis pharetra ligula iaculis.
\end{vwcol}
Footnote\footnote{after}
\end{document}
结果(注意,geometry
使用了包来使页面变小):