Tcolorbox - catatan kaki di akhir setiap halaman

Aug 15 2020

Saya menggunakan tcolorboxuntuk 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:

  1. Catatan kaki 1 muncul di akhir kotak (karena saya memasukkannya menggunakan \footnote{}perintah yang benar .
  2. Catatan kaki 2-4 palsu - Saya membuatnya secara manual menggunakan superskrip di teks, dan kombinasi dari \hrule\, \fakefillperintah, dan enumitempaket.

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

4 muzimuzhiZ Aug 17 2020 at 06:02

Secara default, konten tcolorboxlingkungan diproses dalam minipageenv (ditetapkan oleh capture=minipage). Itu minipageyang mengubah perilaku \footnote.

Dalam contoh berikut, saya meniru perilaku normal \footnoteoleh

  • memulihkan penghitung terkait catatan kaki (dari mpfootnoteke footnote), dan
  • menunda penyisipan ke \footins(biasanya dilakukan di \@footnotetext) hingga akhir lapisan pertama tcolorbox.

Saat ini, semua \footnotes yang digunakan dalam breakable tcolorboxadalah set huruf seolah-olah digunakan di akhir bagian terakhir.

Tambalan serupa dapat dilakukan minipage, tetapi sistem nilai kunci tcolorboxmembuat 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}