
為了讓footnotes
位於頁面底部而不是位於 的底部tcolorbox
,我在 的\footnotemark
內部tcolorbox
和\footnotetext
下面使用tcolorbox
。這是一個 MWE:
\documentclass[11pt]{book}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}
This is a \textbf{tcolorbox}\footnotemark.
And this is some text.\footnotemark.
\end{tcolorbox}
\footnotetext{This is footnote 1}
\footnotetext{This is footnote 2}
And more text.\footnote{This is footnote 3}
\end{document}
這是輸出:(為了保持圖片的大小合理,我不得不稍微偽造一下。):
請注意,在頁面底部,註腳 2 和註腳 3 均正確標示為 2 和 3,而註腳 1 錯誤標示為 2。
答案1
tcolorbox
這個問題的原因與--uses無關,每次應用都會被覆蓋\footnotetext
,因此多次調用會增加計數器,但這些腳註計數器值與相應的.多種規格不增加相關腳註計數器標籤。\@thefnmark
\footnotemark
\footnotemark
footnote
\footnotetext
\footnotetext
可以使用\footnotetext[value]{...}
相反的方式,將footnote
計數器設置在一個群組中—它不會洩漏到外面。
下面的解決方案追蹤呼叫次數\footnotemark
並為其分配標籤,\morefootnotetext
檢索標籤並提取計數器值,然後使用 進行排版\footnotetext[value]{...}
。
如果\footnotetext
呼叫次數多於\footnotemark
分配次數,這種方法將會失敗!
\documentclass[11pt]{book}
\usepackage{xassoccnt}
\usepackage{tcolorbox}
\usepackage{refcount}
\newcounter{totalfootnotes}
\newcounter{totalfootnotetexts}
\DeclareAssociatedCounters{footnote}{totalfootnotes}% Count all footnotes
\usepackage{xpatch}
\usepackage{xparse}
\xpatchcmd{\footnotemark}{\stepcounter}{\refstepcounter}{}{}
\xapptocmd{\footnotemark}{\label{fnmark-\number\value{totalfootnotes}}}{}{}
\xpretocmd{\footnote}{\stepcounter{totalfootnotetexts}}{}{}% Explicitly step!
\NewDocumentCommand{\morefootnotetext}{o+m}{%
\IfValueTF{#1}{%
\footnotetext[#1]{#2}%
}{%
\stepcounter{totalfootnotetexts}%
\footnotetext[\getrefnumber{fnmark-\number\value{totalfootnotetexts}}]{#2}
}%
}
\begin{document}
\begin{tcolorbox}
This is a \textbf{tcolorbox}\footnotemark
And this is some text.\footnotemark
\end{tcolorbox}
\morefootnotetext{This is footnote 1 from inside}
\morefootnotetext{This is footnote 2 from inside}
And more text.\footnote{This is footnote 3 from outside}
Now an example with 4 footnotemark\footnote{A dummy footnote} calls
\begin{tcolorbox}
This is a \textbf{tcolorbox}\footnotemark
And this is some text.\footnotemark
Stuff\footnotemark Otherstuff\footnotemark
\end{tcolorbox}
\morefootnotetext{This is footnote 3 from inside}
\morefootnotetext{This is footnote 4 from inside}
\morefootnotetext{This is footnote 5 from inside}
\morefootnotetext{This is footnote 6 from inside}
\end{document}