我目前正在尝试将 2 个带框的方程式放在同一条线上。我用它{mybox}
来创建框的轮廓和颜色。同时将方程式放置在我想要的位置。框内必须有 5% 的灰色。
我有这个代码:
\documentclass[a4paper, 11pt]{report}
\usepackage{amsmath}
\usepackage{empheq}
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}
\usepackage[top=15mm, bottom=15mm, left=35mm, right=20mm]{geometry}
\newmdenv[innerlinewidth=0.5pt, roundcorner=4pt,linecolor=blue,innerleftmargin=6pt,
innerrightmargin=6pt,innertopmargin=6pt,innerbottommargin=6pt,
leftmargin=179.5pt, rightmargin=179.5pt]{mybox1}
\newmdenv[innerlinewidth=0.5pt, roundcorner=4pt,linecolor=blue,innerleftmargin=6pt,
innerrightmargin=6pt,innertopmargin=6pt,innerbottommargin=6pt,
leftmargin=179.5pt, rightmargin=179.5pt]{mybox2}
\newmdenv[innerlinewidth=0.5pt, roundcorner=4pt,linecolor=blue,innerleftmargin=6pt,
innerrightmargin=6pt,innertopmargin=6pt,innerbottommargin=6pt,
leftmargin=179.5pt, rightmargin=179.5pt]{mybox3}
\newmdenv[innerlinewidth=0.5pt, roundcorner=4pt,linecolor=blue,innerleftmargin=6pt,
innerrightmargin=6pt,innertopmargin=6pt,innerbottommargin=6pt,
leftmargin=30.5pt, rightmargin=255pt]{mybox4}
\begin{document}
Simple linear regression relates one dependent variable to one independent variable in the form of a linear equation:
\begin{mybox1}[backgroundcolor=gray!5, shadowsize=10pt, shadowcolor=gray]
\begin{center}
$y = a + bx$
\end{center}
\end{mybox1}
To develop the linear equation, the intercept a and slope b must first be computed using the
following least squares formulas:
\begin{mybox2}
\begin{center}
$a = \bar{y} + b \bar{x}$
\end{center}
\end{mybox2}
and
\begin{mybox3}
\begin{center}
$b = \frac{\sum{x y - n \bar{x}\ \bar{y}}}{\sum{x^2 - n \bar{x}^2}}$
\end{center}
\end{mybox3}
Where:
\begin{mybox4}
\begin{center}
$\bar{x} = \frac{\sum{x}}{n} = mean\ of\ x\ data$
\end{center}
\end{mybox4}
We can use correlation to measure the strength of the relationship between the independent and dependent variables. The formula for the
correlation coefficient is:
\end{document}
我明白了,但我必须得到这个:
如您所见,我必须水平对齐方程式,为框添加阴影,并制作绿色框。提前感谢您的帮助。
答案1
这是一个tcolorbox
解决方案(而不是mdframed
)
该\tcboxmath
命令可以在方程式内部使用,也可以作为独立框使用,颜色等的配置使用colframe
和colback
等非常简单,可以tcbset
在可选参数中本地使用或使用。
\documentclass{article}
\usepackage{mathtools}
\usepackage[most]{tcolorbox}
\tcbset{enhanced,colframe=blue,colback={black!5!white},drop shadow}
\begin{document}
Simple linear regression relates one dependent variable to one independent variable in the form of a linear equation:
\begin{equation}
\tcboxmath{y = a + bx}
\end{equation}
To develop the linear equation, the intercept a and slope b must first be computed using the
following least squares formulas:
\begin{equation}
\tcboxmath{%
a = \bar{y} + b \bar{x}
}
\text{ and }
\tcboxmath{%
b = \frac{\sum{x y - n \bar{x}\ \bar{y}}}{\sum{x^2 - n \bar{x}^2}}
}
\end{equation}
Where:
\begin{equation}
\tcboxmath[colframe=green]{%
\bar{x} = \frac{\sum{x}}{n} = \text{mean\ of\ x\ data}
}
\end{equation}
We can use correlation to measure the strength of the relationship between the independent and dependent variables. The formula for the
correlation coefficient is:
\end{document}