Tcolorbox - catatan kaki di akhir setiap halaman
Saya menggunakan tcolorbox
untuk mengelilingi teks saya dengan kotak berwarna.
Tampaknya tidak dapat menempatkan catatan kaki di akhir setiap halaman. Sebaliknya, itu menempatkan mereka di ujung seluruh kotak. Demonstrasi di bawah ini:

Seperti yang dapat Anda lihat:
- Catatan kaki 1 muncul di akhir kotak (karena saya memasukkannya menggunakan
\footnote{}
perintah yang benar . - Catatan kaki 2-4 palsu - Saya membuatnya secara manual menggunakan superskrip di teks, dan kombinasi dari
\hrule\
,\fakefill
perintah, danenumitem
paket.
Bagaimana saya bisa mendapatkan sesuatu seperti catatan kaki 'palsu' yang saya buat dengan perintah \ footnote? Yaitu ditempatkan di bagian bawah halaman yang relevan (bukan akhir dari seluruh kotak).
Selain itu, saya ingin teks catatan kaki diratakan kiri dengan aturan catatan kaki, mirip dengan catatan kaki palsu saya, daripada menjorok ke dalam (seperti catatan kaki 1 yang sebenarnya di bagian akhir).
MWE untuk gambar diatas:
\documentclass[12pt]{article}
% look of the page
\usepackage[margin=0.8in, top = 1.3in, bottom = 1.3in, headheight = 0.6in]{geometry}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\setlength{\footskip}{50pt}
\setlength{\footnotesep}{\baselineskip} % space between footnotes
\setlength{\parindent}{0pt} % space at start of paragraph
\setlength{\parskip}{0.14in} % space between paragraphs
% math
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
% relevant to this question
\usepackage{enumitem}
\usepackage[many]{tcolorbox}
\usepackage{xcolor}
\newcommand*{\fakebreak}{\par\vspace{\textheight minus \textheight}\pagebreak}
\newcommand*{\fakefill}{\par\vspace{\textheight minus \textheight}}
\begin{document}
\begin{tcolorbox}[%
parbox = false,
colback = white, colframe = black,
left = 0.5in, right = 0.5in, top = 0.4in, bottom = 0.4in,
height = 9.06in,
sharp corners,
boxrule = 1pt,
breakable,
]
\renewcommand{\thempfootnote}{\arabic{mpfootnote}}
First sentence.\footnote{Footnote 1.} \\
Second sentence.$^2$
\fakefill
\par\noindent\rule{0.3\textwidth}{0.4pt}
{\footnotesize
\begin{enumerate}[leftmargin = 0in, rightmargin = 0in, topsep = 0pt]
\item[$^2$] Footnote 2.
\end{enumerate}
}
\newpage
Third sentence.$^3$\\
Fourth sentence.$^4$
\fakefill
\par\noindent\rule{0.3\textwidth}{0.4pt}
{\footnotesize
\begin{enumerate}[leftmargin = 0in, rightmargin = 0in, topsep = 0pt]
\item[$^3$] Footnote 3.
\item[$^4$] Footnote 4.
\end{enumerate}
}
\end{tcolorbox}
\end{document}
Jawaban
Secara default, konten tcolorbox
lingkungan diproses dalam minipage
env (ditetapkan oleh capture=minipage
). Itu minipage
yang mengubah perilaku \footnote
.
Dalam contoh berikut, saya meniru perilaku normal \footnote
oleh
- memulihkan penghitung terkait catatan kaki (dari
mpfootnote
kefootnote
), dan - menunda penyisipan ke
\footins
(biasanya dilakukan di\@footnotetext
) hingga akhir lapisan pertamatcolorbox
.
Saat ini, semua \footnote
s yang digunakan dalam breakable tcolorbox
adalah set huruf seolah-olah digunakan di akhir bagian terakhir.
Tambalan serupa dapat dilakukan minipage
, tetapi sistem nilai kunci tcolorbox
membuat tambalan lebih lembut (lebih sedikit kebutuhan untuk memodifikasi makro internal) dan lebih ringan (kode yang lebih pendek).
\documentclass{article}
\usepackage[papersize={10cm, 15cm}]{geometry}
\usepackage{lipsum}
\usepackage[hooks]{tcolorbox}
\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
\begin{document}
text\footnote{first}
\begin{tcolorbox}
content\footnote{inside tcolorbox}\par
footnote with optional argument\footnote[10]{inside tcolorbox 2}
\end{tcolorbox}
text\footnote{third}
\begin{tcolorbox}
content\footnote{inside second tcolorbox}\par
footnote with optional argument\footnote[20]{inside second tcolorbox 2}
\begin{tcolorbox}
content\footnote{layer 2}
\begin{tcolorbox}
content\footnote{layer 3}
\end{tcolorbox}
\end{tcolorbox}
\end{tcolorbox}
text\footnote{seventh}
\end{document}
