There are two issues in this situation. The first issue is that vwcol
sets the contents in a \parbox
, which does not display footnotes. See Why does \parbox lose footnotes? for more discussion, and also a solution by redefining \@footnotetext
.
The second issue is that vwcol
processes the same input several times in a loop, to compute the correct distribution of the columns. Every time the input is processed the footnote counters are increased. The final run is actually used in the document, with the shown footnote counter having skipped the values of the previous runs.
To address this issue you can process the footnotes only at the first run (to show the correct numbers at the bottom of the page and to prevent the same footnote being added multiple times). However, now the numbers are not shown in the paragraph, because that is the result of the last run. Therefore you can print only the number using \footnotemark
, and reset this number before every run to the initial value.
A relatively easy way to accomplish the above is to define a new footnote command for use within vwcol
environments (\footnotevwc
in the MWE below). The necessary modifications to the rest of the code are minor (8 lines of code in total) but because vwcol
uses \NewEnvironment
from the environ
package unfortunately the code cannot be patched easily. Instead a full redefinition of the environment is used in the code below, copied from the source of vwcol
. The code for the footnotes in a \parbox
from the other question is another 20 lines.
Full 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}
Result (note that the geometry
package is used to make the pages smaller):