方程式周围的花式方框

方程式周围的花式方框

我试图让我的方程式像这样显示出来: enter image description here

这是我迄今为止的尝试:

\documentclass[11pt,fleqn]{book} 
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry} 

\usepackage{xcolor}
\definecolor{ocre}{RGB}{243,102,25}
\usepackage{avant} 
\usepackage{empheq}
\usepackage{mathptmx}

\usepackage{microtype} 
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage{calc} 
\begin{document}

\newcommand*\Ocrebox[2][Example]{%
\sbox{\mysaveboxM}{#2}%
\sbox{\mysaveboxT}{\fcolorbox{ocre}{ocre!10}{#1}}%
sbox{\mysaveboxM}{%
\parbox[b][\ht\mysaveboxM+.5\ht\mysaveboxT+.5\dp\mysaveboxT][b]{%
\wd\mysaveboxM}{#2}%
}%
\sbox{\mysaveboxM}{%
\fcolorbox{black}{shadecolor}{%
\makebox[\linewidth-10em]{\usebox{\mysaveboxM}}%
}%
}%
\usebox{\mysaveboxM}%
\makebox[0pt][r]{%
\makebox[\wd\mysaveboxM][c]{%
\raisebox{\ht\mysaveboxM-0.5\ht\mysaveboxT
+0.5\dp\mysaveboxT-0.5\fboxrule}{\usebox{\mysaveboxT}}%
}%
}%
}

\begin{empheq}[box=\Ocrebox]
\frac{C(s)}{R(s)}= \frac{G(s)}{1+G(s)H(s)}
\label{e5}
\end{empheq}

\end{document}

但我没能编译它。任何帮助都将不胜感激!

答案1

对于围绕定理结构的框架,一种可能性是使用mdframedamsthm;对于围绕方程的简单框架,empheq-style,说类似的话就足够了:

\newcommand*\mymathbox[1]{%
  \fcolorbox{ocre}{mygray}{\hspace{1em}#1\hspace{1em}}}

然后box=\mymathbox在 的可选参数中使用empheq。完整的示例:

\documentclass{book}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{empheq}
\usepackage{bookman}
\usepackage[framemethod=tikz]{mdframed}

\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}

\newcommand*\mymathbox[1]{%
  \fcolorbox{ocre}{mygray}{\hspace{1em}#1\hspace{1em}}}

\newtheoremstyle{mystyle}
  {\topsep}
  {\topsep}
  {\normalfont}
  {}
  {\sffamily\bfseries}
  {.}
  {.5em}
  {{\color{ocre}\thmname{#1}~\thmnumber{#2}}\thmnote{\,--\,#3}}%
\theoremstyle{mystyle}
\newmdtheoremenv[
  backgroundcolor=mygray,
  linecolor=ocre,
  leftmargin=20pt,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  ]{theo}{Theorem}[section]

\begin{document}

\chapter{Test chapter}
\section{Test section}

\begin{theo}[Name of the theorem]
In $E=\mathbb{R}^n$ all norms are equivalent.
\begin{align}
a &= b\\
E &= mc^2 + \int_a^a x\, \mathrm{d}x
\end{align}
\end{theo}

\begin{empheq}[box=\mymathbox]{align}
a&=b\\
E&=mc^2 + \int_a^a x\, \mathrm{d}x
\end{empheq}

\end{document}

enter image description here

在评论中,有人要求使用与我之前的解决方案中的定理类似的框架,但用于数学表达式;这里的一种可能性是使用tcolorbox包裹:

\documentclass{book}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{bookman}
\usepackage[most]{tcolorbox}

\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}

\tcbset{myformula/.style={
  arc=0pt,
  outer arc=0pt,
  colback=mygray,
  colframe=ocre,
  boxrule=0.4pt,
  left=2pt,
  right=2pt,
  highlight math style={
    arc=0pt,
    outer arc=0pt,
    colback=mygray,
    colframe=red.
    }
  }
}

\begin{document}

\chapter{Test chapter}
\section{Test section}

\begin{tcolorbox}[ams equation,myformula]
E = mc^2 + \int_a^a x\, \mathrm{d}x
\end{tcolorbox}

\begin{tcolorbox}[ams align,myformula]
a &= b \\
E &= mc^2 + \int_a^a x\, \mathrm{d}x
\end{tcolorbox}

\end{document}

enter image description here

或者,mdframed再次使用,

\documentclass{book}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{bookman}
\usepackage[framemethod=tikz]{mdframed}

\definecolor{ocre}{RGB}{243,102,25}
\definecolor{mygray}{RGB}{243,243,244}

\newmdenv[
  innertopmargin=0pt,
  backgroundcolor=mygray,
  linecolor=ocre,
  innerleftmargin=0pt,
  innerrightmargin=0pt,
  leftmargin=10pt
  ]{mymath}

\begin{document}

\chapter{Test chapter}
\section{Test section}

\begin{mymath}
\begin{align}
a &= b\\
E &= mc^2 + \int_a^a x\, \mathrm{d}x
\end{align}
\end{mymath}

\end{document}

enter image description here

相关内容