我想使用empheq
框来将方程式居中对齐,但希望框能够跨越整个页面宽度。
传递
gather/gather*
环境会empheq
产生中心对齐的方程式,但是框会紧紧包围方程式的内容。传递
flalign/flalign*
环境来empheq
产生全宽框但将方程式对齐到中心有点麻烦 - 必须手动完成并且需要一些猜测才能获得正确的对齐(我发现在某些情况下是不可能的)。
请参阅下面的 MWE。
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{empheq}
\usepackage{amsmath}
\newtcbox{\mymath}[1][]{%
nobeforeafter, width=\textwidth, math upper, enhanced,
colframe=gray!10!white, boxrule=0pt, arc=1mm, outer arc=1mm, opacityback=0.5,
frame hidden, borderline={0.5pt}{0pt}{gray!20!white},
#1}
\begin{document}
\begin{enumerate}
\item Boxed equation using \texttt{empheq} and \texttt{gather*}
\begin{empheq}[box=\mymath]{gather*}
\sigma_{xx} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{xx} + \nu(\epsilon_{yy} + \epsilon_{zz})\right] \\
\sigma_{yy} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{yy} + \nu(\epsilon_{xx} + \epsilon_{zz})\right] \\
\sigma_{zz} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{zz} + \nu(\epsilon_{xx} + \epsilon_{yy})\right] \\
\tau_{xy} = G\gamma_{xy} \\
\tau_{yz} = G\gamma_{yz} \\
\tau_{xz} = G\gamma_{xz}
\end{empheq}
\item Boxed equation using \texttt{empheq} and \texttt{flalign*}
\begin{empheq}[box=\mymath]{flalign*}
\sigma_{xx} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{xx} + \nu(\epsilon_{yy} + \epsilon_{zz})\right] \\
\sigma_{yy} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{yy} + \nu(\epsilon_{xx} + \epsilon_{zz})\right] \\
\sigma_{zz} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{zz} + \nu(\epsilon_{xx} + \epsilon_{yy})\right] \\
\tau_{xy} = G\gamma_{xy} \\
\tau_{yz} = G\gamma_{yz} \\
\tau_{xz} = G\gamma_{xz}
\end{empheq}
\end{enumerate}
\end{document}
答案1
需要告知 tcbox 尊重其自己的宽度键tcbox width=forced center
(其中一个对齐在此处给出了过度警告,但我认为这是虚假的)
\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{empheq}
\usepackage{amsmath}
\newtcbox{\mymath}[1][]{%
nobeforeafter, width=\linewidth, math upper, enhanced,
colframe=gray!10!white, boxrule=0pt, arc=1mm, outer arc=1mm, opacityback=0.5,
frame hidden, borderline={0.5pt}{0pt}{gray!20!white},tcbox width=forced center
#1}
\begin{document}
\noindent X\dotfill X
\begin{enumerate}
\item Boxed equation using \texttt{empheq} and \texttt{gather*}
\begin{empheq}[box=\mymath]{flalign*}
\sigma_{xx} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{xx} + \nu(\epsilon_{yy} + \epsilon_{zz})\right] \\
\sigma_{yy} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{yy} + \nu(\epsilon_{xx} + \epsilon_{zz})\right] \\
\sigma_{zz} = \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{zz} + \nu(\epsilon_{xx} + \epsilon_{yy})\right] \\
\tau_{xy} = G\gamma_{xy} \\
\tau_{yz} = G\gamma_{yz} \\
\tau_{xz} = G\gamma_{xz}
\end{empheq}
\item Boxed equation using \texttt{empheq} and \texttt{gather*}
\begin{empheq}[box=\mymath]{gather*}
a=b\\
c=d
\end{empheq}
\item Boxed equation using \texttt{empheq} and \texttt{flalign*}
\begin{empheq}[box=\mymath]{flalign*}
\sigma_{xx} &= \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{xx} + \nu(\epsilon_{yy} + \epsilon_{zz})\right] \\
\sigma_{yy} &= \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{yy} + \nu(\epsilon_{xx} + \epsilon_{zz})\right] \\
\sigma_{zz} &= \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{zz} + \nu(\epsilon_{xx} + \epsilon_{yy})\right] \\
\tau_{xy} &= G\gamma_{xy} \\
\tau_{yz} &= G\gamma_{yz} \\
\tau_{xz} &= G\gamma_{xz}
\end{empheq}
\item Boxed equation using \texttt{empheq} and \texttt{align*}
\begin{empheq}[box=\mymath]{align*}
\sigma_{xx} &= \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{xx} + \nu(\epsilon_{yy} + \epsilon_{zz})\right] \\
\sigma_{yy} &= \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{yy} + \nu(\epsilon_{xx} + \epsilon_{zz})\right] \\
\sigma_{zz} &= \frac{E}{(1+\nu)(1-2\nu)}\left[(1-\nu)\epsilon_{zz} + \nu(\epsilon_{xx} + \epsilon_{yy})\right] \\
\tau_{xy} &= G\gamma_{xy} \\
\tau_{yz} &= G\gamma_{yz} \\
\tau_{xz} &= G\gamma_{xz}
\end{empheq}
\end{enumerate}
\end{document}