![创建自定义方框脚注(带符号/数字标记)](https://linux22.com/image/471694/%E5%88%9B%E5%BB%BA%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%A1%86%E8%84%9A%E6%B3%A8%EF%BC%88%E5%B8%A6%E7%AC%A6%E5%8F%B7%2F%E6%95%B0%E5%AD%97%E6%A0%87%E8%AE%B0%EF%BC%89.png)
我正在尝试为一个项目创建自定义脚注,我们需要选择使用符号脚注和使用数字脚注(文本显示在框内)。使用 bigfoot 包,到目前为止,我已经设法制作了不同类型的脚注,并将数字脚注文本放在框内,但是脚注标记出现在框的外面和上方。有没有办法把它放在里面?
相关代码如下:
\documentclass{book}
\usepackage{tcolorbox}
\usepackage{bigfoot}
\DeclareNewFootnote[para]{symb}[fnsymbol]
\DeclareNewFootnote[para]{num}
\newcommand{\boxedfootnote}[1]{%
\footnotenum{%
\begin{tcolorbox}[colback=lightgray,colframe=white, boxrule=0.5pt]%
#1%
\end{tcolorbox}%
}%
}
\begin{document}
Text with numeric footnote \footnotenum{This is a numeric footnote.}.\\
Text with symbolic footnote \footnotesymb{This is a symbolic footnote.}.\\
Text with a boxed footnote \boxedfootnote{This is a boxed footnote.}.
\end{document}
非常感谢您的任何想法,我对此很陌生,所以我主要是猜测该怎么做。
答案1
我认为这满足了您的要求。不需要bigfoot
包。直接\@footnotetext
在组中重新定义。并使用\thefootnote
在组中重新定义的以及和\footnotemark[n]
来footnotetext[n]
键入符号脚注。
\documentclass{book}
\usepackage{tcolorbox}
\newcounter{symbcount}
\newcommand{\footnotesymb}[1]{%
{\stepcounter{symbcount}\renewcommand{\thefootnote}{\fnsymbol{footnote}}\footnotemark[\thesymbcount]\footnotetext[\thesymbcount]{#1}}%
}
\makeatletter
\newcommand{\boxedfootnote}[1]{%
{\long\def\@footnotetext##1{\insert\footins{%
\reset@font\footnotesize
\interlinepenalty\interfootnotelinepenalty
\splittopskip\footnotesep
\splitmaxdepth \dp\strutbox \floatingpenalty \@MM
\hsize\columnwidth \@parboxrestore
\def\@currentcounter{footnote}%
\protected@edef\@currentlabel{%
\csname p@footnote\endcsname\@thefnmark
}%
\color@begingroup%
\begin{tcolorbox}[colback=lightgray,colframe=white, boxrule=0.5pt,left=-3pt,right=-3pt,nobeforeafter]\@makefntext{%
\rule\z@\footnotesep\ignorespaces##1\@finalstrut\strutbox}%
\par\end{tcolorbox}%
\color@endgroup}}\footnote{#1}}%
}
\makeatother
\begin{document}
Text with numeric footnote\footnote{test}
Text with symbolic footnote\footnotesymb{This is a symbolic footnote.}.
Text with a boxed footnote\boxedfootnote{This is a boxed footnote.}
Text with symbolic footnote\footnotesymb{This is a symbolic footnote.} again.
Text with numeric footnote\footnote{test} again.
\end{document}
更新:简化代码以使 tcolorbox 具有更好的对齐效果。现在代码与
hyperref
包兼容。
\documentclass{book}
\usepackage{tcolorbox}
\newcounter{symbcount}
\newcounter{oldfootnote}
\newcommand{\footnotesymb}[1]{%
{\setcounter{oldfootnote}{\thefootnote}\setcounter{footnote}{\thesymbcount}\stepcounter{symbcount}\renewcommand{\thefootnote}{\fnsymbol{footnote}}\footnotemark\footnotetext{#1}\setcounter{footnote}{\theoldfootnote}}%
}
\makeatletter
\newcommand{\boxedfootnote}[1]{%
{\let\old@footnotetext\@footnotetext\long\def\@footnotetext##1{\let\old@makefntext\@makefntext\let\@makefntext\relax\old@footnotetext{\begin{tcolorbox}[colback=lightgray,colframe=white, boxrule=0pt,left=0pt,right=0pt,boxsep=0pt,nobeforeafter]\old@makefntext ##1\end{tcolorbox}}}\footnote{#1}}%
}
\makeatother
\usepackage[hidelinks]{hyperref}
\begin{document}
Text with numeric footnote\footnote{test}
Text with symbolic footnote\footnotesymb{This is a symbolic footnote.}.
Text with a boxed footnote\boxedfootnote{This is a boxed footnote.}.
Text with symbolic footnote\footnotesymb{This is a symbolic footnote.} again.
Text with numeric footnote\footnote{test} again.
\end{document}
答案2
像这样:
代码:
\documentclass{book}
%\usepackage{tcolorbox}
\usepackage{bigfoot}
\DeclareNewFootnote[para]{symb}[fnsymbol]
\DeclareNewFootnote[para]{num}
\newcommand{\boxedfootnote}[1]{%
\footnotenum{%
% \vspace{-.5 cm}
\fbox{#1}
}%
}
\begin{document}
Text with numeric footnote \footnotenum{This is a numeric footnote.}.\\
Text with symbolic footnote \footnotesymb{This is a symbolic footnote.}.\\
Text with a boxed footnote \boxedfootnote{This is a boxed footnote.}.
\end{document}