对齐环境中方程式周围的花式框

对齐环境中方程式周围的花式框

我知道empheq问题。但是,我们可以将它们结合起来吗?我的意思是,我可以在对齐环境中将方程的一部分放在一个花哨的框中吗?

(我认为没有必要使用 MWE,因为这个问题很简单,而且两个链接问题中都有 MWE;但是如果你需要 MWE 评论,我会添加一个)

编辑:添加 MWE

\documentclass{minimal}

\usepackage{color}
\definecolor{myblue}{rgb}{.8, .8, 1}
\usepackage{empheq}
\usepackage{amsmath,mathtools}

\newlength\mytemplen
\newsavebox\mytempbox

\makeatletter
\newcommand\mybluebox{%
\@ifnextchar[%]
{\@mybluebox}%
{\@mybluebox[0pt]}}

\def\@mybluebox[#1]{%
\@ifnextchar[%]
{\@@mybluebox[#1]}%
{\@@mybluebox[#1][0pt]}}

\def\@@mybluebox[#1][#2]#3{
\sbox\mytempbox{#3}%
\mytemplen\ht\mytempbox
\advance\mytemplen #1\relax
\ht\mytempbox\mytemplen
\mytemplen\dp\mytempbox
\advance\mytemplen #2\relax
\dp\mytempbox\mytemplen
\colorbox{myblue}{\hspace{1em}\usebox{\mytempbox}\hspace{1em}}}

\makeatother

\begin{document}
\begin{align}
\Aboxed{\text{stuff} &= \text{other stuff}}
\end{align}
\begin{empheq}[box={\mybluebox[5pt]}]{equation*}
\text{stuff} = \text{other stuff}
\end{empheq}
Now, both?
\end{document}

谢谢,之前

答案1

如果你不介意加载 TiZ,你可以尝试

\documentclass{minimal}
\usepackage{color}
\usepackage{tikz}
\usetikzlibrary{fit}
\newcommand{\tikznode}[1]{
  \tikz[remember picture,baseline=(#1.base)]{
    \node(#1)[inner sep=0pt]{\strut};
  }
}

\definecolor{myblue}{rgb}{0.8, 0.8, 1}
\usepackage{amsmath,mathtools}

\begin{document}
Draw a box with border.
\begin{align}
  \tikznode{1} \text{stuff} &= \text{other stuff}\tikznode{2}
\end{align}
\tikz[remember picture,overlay]{
  \node[draw,fit=(1) (2)]{};
}

Draw a box with a transparent overlay.
\begin{align}
  \tikznode{3} \text{stuff} = \text{other stuff} \tikznode{4}
\end{align}
\tikz[remember picture,overlay]{
  \node[fit=(3) (4),fill=blue,fill opacity=0.25]{};
}

Draw both.
\begin{align}
  \tikznode{5}\text{stuff} = \text{other stuff}\tikznode{6}
\end{align}
\tikz[remember picture,overlay]{
  \node[draw,fit=(5) (6),fill=blue,fill opacity=0.25]{};
}

It also works if you want to put the box around several lines
\begin{align}
  \tikznode{7}E &= m_0\, c^2\notag \\
  &=\frac{m}{\sqrt{1-v^2/c^2}\tikznode{9}}c^2\tikznode{8}
\end{align}\tikz[remember picture,overlay]{
\node[draw,fit=(7) (8) (9),fill=blue,fill opacity=0.25]{};}

As you see in this example, you need to place 
the tikznodes in the most extreme positions. 
\end{document}

Latex 输出 当然,加载Ti仅为此目的而使用 Z 可能有些过度,但如果您无论如何都要加载它和/或追求更奇特的风格,那么它可能是值得的。

答案2

像这样?

在此处输入图片描述

\documentclass{minimal}

\usepackage{color}
\definecolor{myblue}{rgb}{.8, .8, 1}
\usepackage{empheq}
\usepackage{amsmath,mathtools}

\newlength\mytemplen
\newsavebox\mytempbox

\makeatletter
\newcommand\mybluebox{%
\@ifnextchar[%]
{\@mybluebox}%
{\@mybluebox[0pt]}}

\def\@mybluebox[#1]{%
\@ifnextchar[%]
{\@@mybluebox[#1]}%
{\@@mybluebox[#1][0pt]}}

\def\@@mybluebox[#1][#2]#3{
\sbox\mytempbox{#3}%
\mytemplen\ht\mytempbox
\advance\mytemplen #1\relax
\ht\mytempbox\mytemplen
\mytemplen\dp\mytempbox
\advance\mytemplen #2\relax
\dp\mytempbox\mytemplen
\setlength{\fboxsep}{0pt}%
\fbox{\colorbox{myblue}{\hspace{1em}\usebox{\mytempbox}\hspace{1em}\mathstrut}}}

\makeatother

\begin{document}
\begin{align}
\Aboxed{\text{stuff} &= \text{other stuff}}
\end{align}
\begin{empheq}[box={\mybluebox[5pt]}]{equation*}
\text{stuff} = \text{other stuff}
\end{empheq}
Now, both?
\end{document}

相关内容