我有以下 LaTeX 片段:
\begin{figure}[h]
\centering
\[\scalebox{2}{\color{blue}$some formula$}\]
\caption{a caption \label{fig:the-label}}
\end{figure}
我正在尝试创建一个新的浮动环境,它可以为我完成大部分格式化,这样我就可以简单地输入
\begin{bigblue}
$some formula$
\caption{a caption \label{fig:the-label}}
\end{bigblue}
我尝试了 environ 和 float 包,但无法做到这一点。这可能吗?
解决方案感谢 Herbert,我想出了以下解决方案:
\documentclass{article}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{floatrow}
\DeclareNewFloatType{bigblue}{placement=!htb,fileext=bb,name=Figure}
\DeclareFloatFont{blue}{\color{blue}}
\DeclareFloatFont{Huge}{\Huge}
\floatsetup[bigblue]{style=plain,framefit=yes,font={Huge,blue},valign=c}
\usepackage{blindtext}
\begin{document}
In \ref{myformula} we see
\blindtext
\begin{bigblue}
\[ E = mc^2 \]
\caption{foo\label{myformula}}
\end{bigblue}
\blindtext
\end{document}
答案1
\documentclass{article}
\usepackage{mathtools}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{floatrow}
\DeclareNewFloatType{bigblue}{placement=!htb,fileext=bb,name=BlueEqn}
\DeclareColorBox{bblue}{\colorbox{blue!30}}
\floatsetup[bigblue]{style=plain,framestyle=colorbox,framearound=row,
colorframeset=bblue,framefit=yes,valign=c}
\usepackage{blindtext}
\begin{document}
In \ref{myformula} or in \eqref{myotherformula} we see
\blindtext
\begin{bigblue}
\[ E = mc^2 \]
\caption{foo\label{myformula}}
\end{bigblue}
\blindtext
\begin{bigblue}
\begin{equation} E^2 = p^2c^2 + (mc^2)^2 \label{myotherformula} \end{equation}
\caption{bar\label{Some}}
\end{bigblue}
\end{document}
答案2
然而,这是一个浮动tcolorbox
版本,由于\tcblower
需要声明将标题放在上面的框(作为一个ams equation
框)下方,因此并不完全令人满意。
\documentclass{article}
\usepackage[most]{tcolorbox}
\newtcolorbox{bigblue}[2][]{
ams equation upper,
sharp corners,
enhanced jigsaw,
boxrule=0pt,
float=b,
colback=white,
colupper={blue},
coltitle={black},
lower separated=false,
detach title,
before lower={\tcbtitle\par},
title={\centering
\bfseries Equation \theequation: #2
},
#1
}
%\AtEndEnvironment{bigblue}{\tcblower}
\usepackage{blindtext}
\begin{document}
In \eqref{myformula} or in \eqref{myotherformula} we see
\blindtext[2]
\begin{bigblue}{Foo}
E = mc^2 \label{myformula}
\tcblower
\end{bigblue}
\blindtext[5]
\begin{bigblue}{Foobar}
E^2 = p^2c^2 + (mc^2)^2 \label{myotherformula}
\tcblower
Some addition
\end{bigblue}
\end{document}