问题
我有一个使用 tikz 完成的自定义脚注样式,并且在 tcolorboxes 中这个脚注不适合,因此我尝试使用 Bernard 解决方案将 tcolorbox 环境内的所有脚注都从中去除:定理环境之外的脚注
\usepackage{etoolbox}
\BeforeBeginEnvironment{theorem}{\savenotes}
\AfterEndEnvironment{theorem}{\spewnotes}
当然不行,可能是因为自定义脚注。我想知道是否有可能修复这个错误
代码
%%%%%%%%%%% PACKAGES %%%%%%%%%%%%%%
\documentclass[12pt]{report}
\usepackage[a4paper, lmargin=2.75cm, rmargin=2.75cm, tmargin=3cm, bmargin=3cm]{geometry} % margins
\usepackage[hidelinks, linktoc=all]{hyperref} % \href{link}{text}
\usepackage{parskip} % auto new paragraph
\setlength{\parskip}{15pt} % more parskip length
\usepackage{tikz}
\usepackage{tcolorbox}
\tcbuselibrary{skins, breakable}
%%%%%%%%%% CUSTOM FOOTNOTE WITH TIKZ %%%%%%%%%%%%%
\usepackage[hang, flushmargin]{footmisc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\thefootnote}{[\arabic{footnote}]} % footnote config
\let\oldfootnote\footnote
\renewcommand{\footnote}[1]{\oldfootnote{\;#1}} % adds space automatically
\newcommand\varfootnote[1] % varfootnote (without number)
{\bgroup\renewcommand\thefootnote{\fnsymbol{footnote}}\renewcommand\thempfootnote{\fnsymbol{mpfootnote}}\footnotetext[0]{#1}\egroup}
\renewcommand{\footnoterule}{\kern-30pt\tikz{ % custom footnote rule
\draw[line width=0.4mm](1mm,0)--(15.4,0);
\draw[line width=0.4mm](0,0) circle (1mm);
\filldraw(0,0) circle (0.3mm);
\draw[line width=0.4mm](15.5,0) circle (1mm);
\filldraw(15.5,0) circle (0.3mm);
\draw[color=white](0,-0.2);}} % moves the line
\addtolength{\skip\footins}{2pc plus 5pt}
%%%%%%%%%%%% CUSTOM BOX %%%%%%%%%%%
\newtcolorbox{tbox}[1]{title={\centering\large#1}, fonttitle=\bfseries, toptitle=1.5mm, bottomtitle=1.5mm, enhanced, breakable, colback=yellow, colframe=black, boxrule=1pt, arc=2mm, rounded corners, coltitle=white, coltext=black}
%%%%%%%%%% SUPPOSED FIX %%%%%%%%%%%
\usepackage{etoolbox}
\BeforeBeginEnvironment{box}{\savenotes}
\AfterEndEnvironment{box}{\spewnotes}
%%%%%%%%%% DOCUMENT %%%%%%%%%%%%
\begin{document}
\footnote{outside footnote}
\begin{tcolorbox}[enhanced, breakable, colback=yellow, colframe=black, boxrule=0pt, arc=2mm, rounded corners, coltext=black, title=\bf{COLORBOX}, coltitle=white, colbacktitle=black, toptitle=1.5mm,
bottomtitle=1.5mm]
\varfootnote{inside footnote without number}
Random text to fill this up\footnote{inside footnote}
\end{tcolorbox}
\begin{tbox}{title}
custom box\footnote{custom box}
\end{tbox}
\end{document}
答案1
一个快速的解决方法是使用\linewidth
来绘制 tikz 装饰,并使用end_of_paragraph\\[vertical_par_spacing_longitude]
具有给定间距的命令来使一切正确,例如\baselineskip
。
结果:
梅威瑟:
%%%%%%%%%%% PACKAGES %%%%%%%%%%%%%%
\documentclass[12pt]{report}
\usepackage[a4paper, lmargin=2.75cm, rmargin=2.75cm, tmargin=3cm, bmargin=3cm]{geometry} % margins
\usepackage[hidelinks, linktoc=all]{hyperref} % \href{link}{text}
\usepackage{parskip} % auto new paragraph
\setlength{\parskip}{15pt} % more parskip length
\usepackage{tikz}
\usepackage{tcolorbox}
\usepackage{lipsum}
\tcbuselibrary{skins, breakable}
%%%%%%%%%% CUSTOM FOOTNOTE WITH TIKZ %%%%%%%%%%%%%
\usepackage[hang, flushmargin]{footmisc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\thefootnote}{[\arabic{footnote}]} % footnote config
\let\oldfootnote\footnote
\renewcommand{\footnote}[1]{\oldfootnote{\;#1}} % adds space automatically
\newcommand\varfootnote[1] % varfootnote (without number)
{\bgroup\renewcommand\thefootnote{\fnsymbol{footnote}}\renewcommand\thempfootnote{\fnsymbol{mpfootnote}}\footnotetext[0]{#1}\egroup}
\renewcommand{\footnoterule}{\kern-30pt\tikz{ % custom footnote rule
\draw[line width=0.4mm](1mm,0)--(\linewidth,0);
\draw[line width=0.4mm](0,0) circle (1mm);
\filldraw(0,0) circle (0.3mm);
\draw[line width=0.4mm](\linewidth,0) circle (1mm);
\filldraw(\linewidth,0) circle (0.3mm);
\draw[color=white](0,-0.2);}} % moves the line
\addtolength{\skip\footins}{2pc plus 5pt}
%%%%%%%%%%%% CUSTOM BOX %%%%%%%%%%%
\newtcolorbox{tbox}[1]{title={\centering\large#1}, fonttitle=\bfseries, toptitle=1.5mm, bottomtitle=1.5mm, enhanced, breakable, colback=yellow, colframe=black, boxrule=1pt, arc=2mm, rounded corners, coltitle=white, coltext=black}
%%%%%%%%%% SUPPOSED FIX %%%%%%%%%%%
\usepackage{etoolbox}
\BeforeBeginEnvironment{box}{\savenotes}
\AfterEndEnvironment{box}{\spewnotes}
%%%%%%%%%% DOCUMENT %%%%%%%%%%%%
\begin{document}
\lipsum*[1]\\[0.5\baselineskip]\footnote{\lipsum[2]}
\begin{tcolorbox}[enhanced, breakable, colback=yellow, colframe=black, boxrule=0pt, arc=2mm, rounded corners, coltext=black, title=\bf{COLORBOX}, coltitle=white, colbacktitle=black, toptitle=1.5mm,
bottomtitle=1.5mm]
\lipsum[2] whereas \varfootnote{inside footnote without number}
\lipsum[3]\\[0.5\baselineskip]\footnote{inside footnote}
\end{tcolorbox}
\begin{tbox}{title}
\lipsum[6]\\[0.5\baselineskip] \footnote{\lipsum[7]}
\end{tbox}
\lipsum[5]
\end{document}
附录:
在更详尽的审查中,他找到了 muzimuzhi Z 提出的解决方案,在帖子中Tcolorbox-每页末尾都有脚注,审查它并批准这个伟大的解决方案;就我而言,我只删除了使装饰看起来很高的定义,并且删除了 kern 命令,我希望它是有帮助的,有时它只是一个正确表述问题的问题,否则结果将是 42。
结果:
梅威瑟:
%%%%%%%%%%% PACKAGES %%%%%%%%%%%%%%
\documentclass[12pt]{report}
\usepackage[a4paper, lmargin=2.75cm, rmargin=2.75cm, tmargin=3cm, bmargin=3cm]{geometry} % margins
\usepackage[hidelinks, linktoc=all]{hyperref} % \href{link}{text}
\usepackage{parskip} % auto new paragraph
\setlength{\parskip}{15pt} % more parskip length
\usepackage{tikz}
\usepackage[hooks]{tcolorbox}
\usepackage{lipsum}
\tcbuselibrary{skins, breakable}
%%%%%%%%%% CUSTOM FOOTNOTE WITH TIKZ %%%%%%%%%%%%%
\usepackage[hang, flushmargin]{footmisc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\thefootnote}{[\arabic{footnote}]} % footnote config
\let\oldfootnote\footnote
\renewcommand{\footnote}[1]{\oldfootnote{\;#1}} % adds space automatically
\newcommand\varfootnote[1] % varfootnote (without number)
{\bgroup\renewcommand\thefootnote{\fnsymbol{footnote}}\renewcommand\thempfootnote{\fnsymbol{mpfootnote}}\footnotetext[0]{#1}\egroup}
\renewcommand{\footnoterule}{\tikz{ % custom footnote rule %<---- delete kern adjust.
\draw[line width=0.4mm](1mm,0)--(\linewidth,0);
\draw[line width=0.4mm](0,0) circle (1mm);
\filldraw(0,0) circle (0.3mm);
\draw[line width=0.4mm](\linewidth,0) circle (1mm);
\filldraw(\linewidth,0) circle (0.3mm);
\draw[color=white](0,-0.2);}} % moves the line
\addtolength{\skip\footins}{2pc plus 5pt}
%%%%%%%%%%%% CUSTOM BOX %%%%%%%%%%%
\newtcolorbox{tbox}[1]{title={\centering\large#1}, fonttitle=\bfseries, toptitle=1.5mm, bottomtitle=1.5mm, enhanced, breakable, colback=yellow, colframe=black, boxrule=1pt, arc=2mm, rounded corners, coltitle=white, coltext=black}
%%%%%%%%%% SUPPOSED FIX %%%%%%%%%%%
\usepackage{etoolbox}
\BeforeBeginEnvironment{box}{\savenotes}
\AfterEndEnvironment{box}{\spewnotes}
\tcbuselibrary{listings,theorems}
%%%%%%%%%%%%% WORK SOLUTION GIVEN BY muzimuzhi Z #############
% please check and upvote in https://tex.stackexchange.com/a/558922/154390
\makeatletter
% restore footnote internals to those in normal page, not minipage
\def\tcb@restore@footnote{%
\def\@mpfn{footnote}%
\def\thempfn{\arabic{footnote}}%
\let\@footnotetext\tcb@footnote@collect
}
% collect footnote text
\long\def\tcb@footnote@collect#1{%
% expand \@thefnmark before appending before app to \tcb@footnote@acc
\expandafter\gappto\expandafter\tcb@footnote@acc\expandafter{%
\expandafter\footnotetext\expandafter[\@thefnmark]{#1}%
}%
}
\def\tcb@footnote@use{%
\tcb@footnote@acc
\global\let\tcb@footnote@acc\@empty
}
\global\let\tcb@footnote@acc\@empty
\tcbset{
% restore for every box
every box/.style={
before upper pre=\tcb@restore@footnote
},
% use for layer 1 boxes only
every box on layer 1/.append style={
after app=\tcb@footnote@use
}
}
\makeatother
%%%%%%%%%% DOCUMENT %%%%%%%%%%%%
\begin{document}
\lipsum*[1] \footnote{foot note of the principal text} Principal text.
\begin{tcolorbox}[enhanced, breakable, colback=yellow, colframe=black, boxrule=0pt, arc=2mm, rounded corners, coltext=black, title=\bf{First Colorbox in page}, coltitle=white, colbacktitle=black, toptitle=1.5mm,
bottomtitle=1.5mm]
\lipsum*[2] \varfootnote{inside footnote without number} HERE
\lipsum*[3] \footnote{inside footnote} HERE.
\end{tcolorbox}
\,\\
\begin{tbox}{title}
\lipsum[6]\footnote{\lipsum[3]} HERE \lipsum[4] \footnote{\lipsum[2]}
\end{tbox}
\lipsum[5]
\end{document}