脚注在阴影环境中消失

脚注在阴影环境中消失

我的脚注在阴影环境中消失,如下例所示。请问如何解决?谢谢!

\documentclass[english]{scrartcl}

\usepackage{graphics}
\usepackage{environ}
\usepackage[round]{natbib}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\setkomafont{disposition}{\normalfont\bfseries}
\usepackage[printwatermark]{xwatermark}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{framed}

\colorlet{shadecolor}{gray!40}

\begin{document}

\title{}
\maketitle

\begin{shaded}
\begin{enumerate}
\item I love my mother.\footnote{Of course.} 
\end{enumerate}
\end{shaded}

\end{document}

图片

答案1

来自framed手册:

框架区域的内容受到限制:浮动文本、脚注、边距部分和标题条目将会丢失。

因此,只需在环境\footnotemark内部shaded\footnotetext{Of course.}其后使用即可。

梅威瑟:

\documentclass[english]{scrartcl}

\usepackage{graphics}
\usepackage{environ}
\usepackage[round]{natbib}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\setkomafont{disposition}{\normalfont\bfseries}
\usepackage[printwatermark]{xwatermark}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{framed}

\colorlet{shadecolor}{gray!40}

\begin{document}

\title{}
\maketitle

\begin{shaded}
\begin{enumerate}
\item I love my mother.\footnotemark
\end{enumerate}
\end{shaded}
\footnotetext{Of course.}

\end{document} 

输出

在此处输入图片描述


编辑

如果环境中有多个脚注shaded,请对其进行编号\footnotetext,如下例所示:

\documentclass[english]{scrartcl}

\usepackage{graphics}
\usepackage{environ}
\usepackage[round]{natbib}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\setkomafont{disposition}{\normalfont\bfseries}
\usepackage[printwatermark]{xwatermark}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{framed}

\colorlet{shadecolor}{gray!40}

\begin{document}

\title{}
\maketitle

\begin{shaded}
\begin{enumerate}
\item I love my mother.\footnotemark
\item And my father,too.\footnotemark
\end{enumerate}
\end{shaded}
\footnotetext[1]{Of course.}
\footnotetext[2]{Of course, again.}

And some text outside\footnote{A footnote}
\end{document}

输出:

在此处输入图片描述

答案2

这是一个自动解决方案,它支持\footnote{<text>}并在环境\footnote[<number>]{<text>}内部使用shaded,无论有无,是否hyperref嵌套在环境中。minipage

注意默认情况下hyperref不支持\footnotetext[<number>]{<text>},请参阅其包文档,第 12.3 节“脚注”。

\documentclass{article}
\usepackage{framed}
\usepackage{xcolor}
\usepackage[colorlinks]{hyperref}

\colorlet{shadecolor}{gray!40}

\makeatletter
\NewDocumentCommand \footnote@in@shaded { o m }{%
  \IfValueTF{#1}{%
    \begingroup
      \csname c@\@mpfn\endcsname #1\relax
      \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup
  }{%
    \stepcounter\@mpfn
    \protected@xdef\@thefnmark{\thempfn}%
  }%
  \@footnotemark
  \ExpandArgs{no}\AddToHookNext{env/shaded/after}{%
    \expanded{%
      \smuggle@macro@in@e\@thefnmark
      \ifdefined\Hy@footnote@currentHref
        \smuggle@macro@in@e\Hy@footnote@currentHref
      \fi
    }%
    \@footnotetext{#2}%
  }%
}

% inserting to hooks `cmd/MakeFrame/before` and `cmd/endMakeFrame/after` would
% be more general, since `framed` package provides mupliple similar envs
\AddToHook{env/shaded/begin}{%
  \let\footnote=\footnote@in@shaded
}

\newcommand\smuggle@macro@in@e[1]{%
  \def\noexpand#1{\unexpanded\expandafter{#1}}%
}
\newcommand\myfootnotesep{\textsuperscript{,}}
\makeatother

\begin{document}
\def\ShadedExample#1{%
  text\footnote{#1}\myfootnotesep\footnote{#1}
  \begin{shaded}
    shaded content%
    \footnote{inside shaded}\myfootnotesep
    \footnote[26]{inside shaded}\myfootnotesep
    \footnote{inside shaded}
  \end{shaded}
  text\footnote{#1}\myfootnotesep\footnote{#1}
}

\ShadedExample{outer}

\bigskip
\begin{minipage}{\linewidth}\sffamily
  \ShadedExample{inside minipage}
\end{minipage}

\bigskip
\ShadedExample{outer}

\newpage
abc
\end{document}

主输出 页面脚注

更新扩展到所有framed环境

\documentclass{article}
\usepackage{etoolbox}
\usepackage{framed}
\usepackage{xcolor}
\usepackage[colorlinks]{hyperref}

\colorlet{shadecolor}{gray!40}

\makeatletter
\NewDocumentCommand \footnote@in@shaded { o m }{%
  \IfValueTF{#1}{%
    \begingroup
      \csname c@\@mpfn\endcsname #1\relax
      \unrestored@protected@xdef\@thefnmark{\thempfn}%
    \endgroup
  }{%
    \stepcounter\@mpfn
    \protected@xdef\@thefnmark{\thempfn}%
  }%
  \@footnotemark
  \ExpandArgs{no}\AddToHookNext{env/shaded/after}{%
    \expanded{%
      \smuggle@macro@in@e\@thefnmark
      \ifdefined\Hy@footnote@currentHref
        \smuggle@macro@in@e\Hy@footnote@currentHref
      \fi
    }%
    \@footnotetext{#2}%
  }%
}

% Adding to hooks `cmd/MakeFramed/before` and `cmd/endMakeFramed/after` would
% be more general, since `framed` package provides mupliple similar envs.
% Will `\MakeFrame` and `\endMakeFrame` nest?
\AddToHook{cmd/MakeFramed/before}{%
  \let\footnote=\footnote@in@shaded
}

\newcommand\smuggle@macro@in@e[1]{%
  \def\noexpand#1{\unexpanded\expandafter{#1}}%
}
\newcommand\myfootnotesep{\textsuperscript{,}}
\makeatother

\begin{document}
\def\FramedEnvExample#1#2{%
  text\footnote{#2}\myfootnotesep\footnote{#2}
  \begin{#1}
    #1 content%
    \footnote{inside #1}\myfootnotesep
    \footnote[26]{inside #1}\myfootnotesep
    \footnote{inside #1}
  \end{#1}
%  text\footnote{#2}\myfootnotesep\footnote{#2}
}

\FramedEnvExample{shaded}{outer}

\bigskip
\begin{minipage}{\linewidth}\sffamily
  \FramedEnvExample{shaded}{inside minipage}
\end{minipage}

\bigskip
\FramedEnvExample{framed}{outer}

\bigskip
\begin{minipage}{\linewidth}\sffamily
  \FramedEnvExample{framed}{inside minipage}
\end{minipage}

\newpage
abc
\end{document}

阴影和框架环境 对应页脚注

相关内容