如何让脚注规则和脚注文本遵循“tcolorbox”中的文本颜色?

如何让脚注规则和脚注文本遵循“tcolorbox”中的文本颜色?

我正在尝试让脚注规则和脚注文本遵循 中的文本颜色tcolorbox。这是我的 MWE:

\documentclass{standalone}
\usepackage[rgb,dvipsnames,svgnames,table]{xcolor}
\usepackage{tcolorbox}
\usepackage[hang,flushmargin,abovefloats]{footmisc} % footnotes
\colorlet{textcolor}{Maroon}
\colorlet{framecolor}{Maroon!90!white}
\colorlet{bgcolor}{MistyRose}
\begin{document}
\begin{tcolorbox}[colback=bgcolor,coltext=textcolor,%
colframe=framecolor,top=1pt,title=Colorbox]
This is colored text within the colorbox\footnote{How do I get the footnote rule and the footnote text to follow the textcolor?}.
\end{tcolorbox}
\end{document}

我怎样才能实现这个目标?在此处输入图片描述

答案1

环境中脚注的黑色tcolorbox继承自minipage环境,在排版脚注(包括脚注行)之前\normalcolor使用的环境。\endminipage

\normalcolor使用\default@color文档开头的“当前颜色”作为当前颜色。这就是@samcarter 的回答有效:本地覆盖\default@color。请注意,应用此更改后, env\normalcolor中其他地方(例如,方程式标签)使用的效果tcolorbox也会被取消。也许这种副作用正是 OP 所期望的,也许不是。

tcolorbox这是另一种仅在环境中改变脚注颜色的方法。它\normalcolor不是从 中删除\endminipage,而是从tcolorbox别名\endtcb@lrbox(由 定义\let\endtcb@lrbox=\endminipage)中删除。对于可破坏的盒子,修补的命令是\endtcb@vbox。修补依赖于如何\endminipage定义,因此可能比@samcarter的答案更棘手。

  • /.try以下示例中使用的是pgfkeys密钥处理程序。它在这里用于使示例在有或没有tcolorbox库的情况下都能进行编译breakable。(breakable/.try意思是,如果breakable定义了就使用它,否则忽略它。)在非测试文档中,可以安全地删除/.try
\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\usepackage[margin=.3in, noheadfoot, paperheight=12cm, paperwidth=15cm]{geometry}
\usepackage{lipsum}
\usepackage{xpatch}

\makeatletter
\let\endtcb@lrbox@normal=\endtcb@lrbox
\let\endtcb@lrbox@footnoteinheritcolor=\endtcb@lrbox
\xpatchcmd\endtcb@lrbox@footnoteinheritcolor
  {\normalcolor}
  {\iftcb@hasLower\color{tcbcollower}\else\color{tcbcolupper}\fi}
  {}{\PatchFailed}

% if breakable library is loaded, patch \endtcb@vbox too
\ifdefined\endtcb@vbox
  \let\endtcb@vbox@normal=\endtcb@vbox
  \let\endtcb@vbox@footnoteinheritcolor=\endtcb@vbox
  \xpatchcmd\endtcb@vbox@footnoteinheritcolor
    {\normalcolor}
    {\iftcb@hasLower\color{tcbcollower}\else\color{tcbcolupper}\fi}
    {}{\PatchFailed}
  \def\tcb@footnote@normalcolor{%
    \let\endtcb@lrbox=\endtcb@lrbox@normal
    \let\endtcb@vbox=\endtcb@vbox@normal
  }
  \def\tcb@footnote@inheritcolor{%
    \let\endtcb@lrbox=\endtcb@lrbox@footnoteinheritcolor
    \let\endtcb@vbox=\endtcb@vbox@footnoteinheritcolor
  }
\else
  \def\tcb@footnote@normalcolor{%
    \let\endtcb@lrbox=\endtcb@lrbox@normal
  }
  \def\tcb@footnote@inheritcolor{%
    \let\endtcb@lrbox=\endtcb@lrbox@footnoteinheritcolor
  }
\fi

\tcbset{
  footnote inherit color/.is choice,
  footnote inherit color/true/.code={%
    \let\endtcb@lrbox=\endtcb@lrbox@footnoteinheritcolor
    \let\endtcb@vbox=\endtcb@vbox@footnoteinheritcolor
  },
  footnote inherit color/false/.code={%
    \let\endtcb@lrbox=\endtcb@lrbox@normal
    \let\endtcb@vbox=\endtcb@vbox@normal
  },
  footnote inherit color/.default=true
}
\makeatother

\begin{document}

\begin{tcolorbox}[
  title={\texttt{footnote inherit color=false}, default behavior},
  colupper=blue!70!black,
  collower=red!70!black
]
  Upper part\footnote{text}. \color{gray!50}color changed
  \tcblower
  Lower part\footnote{text}. \color{gray!50}color changed
\end{tcolorbox}

\begin{tcolorbox}[
  title={\texttt{footnote inherit color=true}},
  colupper=blue!70!black,
  collower=red!70!black,
  footnote inherit color
]
  Upper part\footnote{text}. \color{gray!50}color changed
  \tcblower
  Lower part\footnote{text}. \color{gray!50}color changed
\end{tcolorbox}

\begin{tcolorbox}[
  title={\texttt{footnote inherit color=true}, broken at upper part},
  colupper=blue!70!black,
  collower=red!70!black,
  breakable/.try,
  use color stack/.try,
  footnote inherit color
]
  Upper part\footnote{text}. \color{gray!50}color changed\par
  \lipsum[1][1-6]\par
  Broken upper part\footnote{text}.
  \tcblower
  Lower part\footnote{text}. \color{gray!50}color changed
\end{tcolorbox}

\begin{tcolorbox}[
  title={\texttt{footnote inherit color=true}, broken at lower part},
  colupper=blue!70!black,
  collower=red!70!black,
  breakable/.try,
  use color stack/.try,
  footnote inherit color
]
  Upper part\footnote{text}. \color{gray!50}color changed\par
  \tcblower
  Lower part\footnote{text}. \color{gray!50}color changed\par
  \lipsum[1][1-5]\footnote{text}.
\end{tcolorbox}
\end{document}

在此处输入图片描述

答案2

快速破解:更改\default@color为匹配您的文本的颜色:

\documentclass{standalone}
\usepackage[rgb,dvipsnames,svgnames,table]{xcolor}
\usepackage{tcolorbox}
\usepackage[hang,flushmargin,abovefloats]{footmisc} % footnotes
\colorlet{textcolor}{Maroon}
\colorlet{framecolor}{Maroon!90!white}
\colorlet{bgcolor}{MistyRose}

\makeatletter
\tcbsetforeverylayer{
  before upper={\let\default@color\current@color},
  before lower={\let\default@color\current@color}
}
\makeatother

\begin{document}

\begin{tcolorbox}[
  colback=bgcolor,
  coltext=textcolor,
  colframe=framecolor,
  top=1pt,
  title=Colorbox
]
This is colored text within the colorbox\footnote{How do I get the footnote rule and the footnote text to follow the textcolor?}.
\end{tcolorbox}

\end{document}

在此处输入图片描述

答案3

这是一个起点(但不是最好的),但它是有效的,如果你玩一些数字,你可以得到更好的结果,以满足你的口味:

\documentclass{standalone}
\usepackage[rgb,dvipsnames,svgnames,table]{xcolor}
\usepackage{tcolorbox}
\usepackage[hang,flushmargin,abovefloats]{footmisc} % footnotes
\colorlet{textcolor}{Maroon}
\colorlet{framecolor}{Maroon!90!white}
\colorlet{bgcolor}{MistyRose}
\renewcommand\thempfootnote{\color{textcolor} \arabic{mpfootnote}}
\renewcommand\footnoterule{\vspace{-5mm}\color{textcolor}\rule{0.4\linewidth}{0.5pt}\vspace{1mm}}
\begin{document}
    \begin{tcolorbox}[colback=bgcolor,coltext=textcolor,%
        colframe=framecolor,top=1pt,title=Colorbox]
        This is colored text within the colorbox\footnote{\color{textcolor} How do I get the footnote rule and the footnote text to follow the textcolor?}.
        This is colored text within the colorbox\footnote{\color{textcolor} How do I get the footnote rule and the footnote text to follow the textcolor?}.
        This is colored text within the colorbox\footnote{\color{textcolor} How do I get the footnote rule and the footnote text to follow the textcolor?}.
    \end{tcolorbox}
\end{document}

相关内容