5

I am currently trying to make 2 boxed equations to be on the same line. I use {mybox} to create the outline of the box and the color. Also to position the equation where i want it to be. The boxes have to have a 5% gray color inside them.

I have this code:

\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}

enter image description here

I get this but I have to get this instead:

enter image description here

As you can see I have to align the equations horizontally, add shadow to the boxes and also make this green box. Thanks for the help in advance.

  • Welcome to TeX.SX! Your example is not compilable at all -- it contains no documentclass, syntax errors and requires code not available to us – user31729 Nov 22 '15 at 15:57
  • Thank you for telling me, I fixed the issues. Now it should work. – BlazeAxtrius Nov 22 '15 at 16:10
5

Here's a tcolorbox solution (instead of mdframed)

The \tcboxmath command can be used inside of an equation or as a standalone box, the configuration of colors etc. is quite simple with colframe and colback etc, either using tcbset or locally in the optional argument.

\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}

enter image description here

  • Thank you so much. Now I only need to figure out how to make the shadow. Worked perfectly – BlazeAxtrius Nov 22 '15 at 16:26
  • @BlazeAxtrius: I forgot the shadows in the screen-shot, but the updated code has them – user31729 Nov 22 '15 at 16:27
  • Yeap. Works like a charm. You are a god. :D – BlazeAxtrius Nov 22 '15 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.