[Tex/LaTex] How to align multiple equation using tcolorbox in latex enviroment for Rmarkdown

equationsr

I have the following latex inside Rmarkdown:

\begin{tcolorbox}

\begin{equation}
   \sigma =  \beta_{0}                                                               
   \label{eq:Model0}
\end {equation}
\begin{equation}
   \sigma =  \beta_{0} + \beta_{1}K + \beta_{2}K^2 
  \label{eq:Model1}
\end {equation}
\begin{equation}
    \sigma = \beta_{0} + \beta_{1}K + \beta_{2}K^2 + \beta_{3}(T-t) +   \beta_{5}K(T-t)                 \label{eq:Model2}
\end {equation}
\begin{equation}
    \sigma = \beta_{0} + \beta_{1}K + \beta_{2}K^2 + \beta_{3}(T-t) + \beta_{4}(T-t)^2 + \beta_{5}K(T-t)
   \label{eq:Model3}
\end {equation}

\end{tcolorbox}

I want a box with these multiple equations, which one getting its own number (this is the reason for begining and ending 3 different eq environments) AND all equations aligned to the left.

How to define the alignment by the above latex?

I saw some reference for using alignfrom \usepackage{amsmath} and then putting the & in the anchor for the alignment (e.g: "="), but also saw some advices for avoiding such package in Rmarkdown environment.

Best Answer

I do not use R markdown, however check of it documentation show, that in its use is not difference to between standard equation. So you can use align

\begin{tcolorbox}
\vspace{-\baselineskip}% <-- to remove extra vertical space
    \begin{align}
\sigma & = \beta_{0}      \label{eq:Model0}   \\
\sigma & = \beta_{0} + \beta_{1}K + \beta_{2}K^2
                        \label{eq:Model1}   \\
\sigma & = \beta_{0} + \beta_{1}K + \beta_{2}K^2 + \beta_{3}(T-t) + \beta_{5}K(T-t)
                        \label{eq:Model2}   \\
\sigma & = \beta_{0} + \beta_{1}K + \beta_{2}K^2 + 
                     \beta_{3}(T-t) + \beta_{4}(T-t)^2 + \beta_{5}K(T-t)
                        \label{eq:Model3}
    \end{align}
\end{tcolorbox}

if you like to have equation aligned ad = or gather, if you like to have equations centered:

\begin{tcolorbox}
\vspace{-\baselineskip}% <-- to remove extra vertical space
    \begin{gather}
\sigma = \beta_{0}      \label{eq:Model0}   \\
\sigma = \beta_{0} + \beta_{1}K + \beta_{2}K^2
                        \label{eq:Model1}   \\
\sigma = \beta_{0} + \beta_{1}K + \beta_{2}K^2 + \beta_{3}(T-t) + \beta_{5}K(T-t)
                        \label{eq:Model2}   \\
\sigma = \beta_{0} + \beta_{1}K + \beta_{2}K^2 + 
                     \beta_{3}(T-t) + \beta_{4}(T-t)^2 + \beta_{5}K(T-t)
                        \label{eq:Model3}
    \end{gather}
\end{tcolorbox}

Note: vertical spacing in amsmath or (better) mathtools math environments and ordinary equation environment is different!. Consequently, before align and gather I suggest to add \vspace{-\baselineskip} if before equations equations isn't text.

Edit: Another possible way to change distance between equation and tcolorbox is set vertical spaces before and after equation (as pointed John Kormylo in his comment) to zero. With this option the complete, compilable code is:

\documentclass{article}
    \usepackage{mathtools}
    \usepackage{tcolorbox}

\usepackage[active,tightpage]{preview}% for show only tcolorbox
\PreviewEnvironment{tcolorbox}
    \setlength\PreviewBorder{1em}

    \begin{document}
\begin{tcolorbox}
\abovedisplayskip=0pt% <--- remove vertical space above align
\belowdisplayskip=0pt% <--- remove vertical space below align
%\vspace{-1\baselineskip} %<--- original solution
    \begin{align}
\sigma & = \beta_{0}      \label{eq:Model0}   \\
\sigma & = \beta_{0} + \beta_{1}K + \beta_{2}K^2
                        \label{eq:Model1}   \\
\sigma & = \beta_{0} + \beta_{1}K + \beta_{2}K^2 + \beta_{3}(T-t) + \beta_{5}K(T-t)
                        \label{eq:Model2}   \\
\sigma & = \beta_{0} + \beta_{1}K + \beta_{2}K^2 +
                     \beta_{3}(T-t) + \beta_{4}(T-t)^2 + \beta_{5}K(T-t)
                        \label{eq:Model3}
    \end{align}
\end{tcolorbox}
    \end{document}

Which gives the same result as the first suggestion:

enter image description here

Related Question