Put two elements next to each other with {minipage}

minipagepositioningspacing

My problem is that I want to put two elements next two each other. First I tried to do this with the table-environment and then create a table with two rows. The problem that occurred there was that I cannot use the equation environment there. So now I try to do it with minipage which works much better already. Still I have the problem that the second column is not at the same height as the other column. How can I solve this?
Further I would like to add more horizontal blank space between the text and the equation in the second row (e.g. with \hspace{}). But instead it added a linebreak. How can I do that?

This is my code so far:

\documentclass{scrreport}
 
\usepackage{mathtools}
\usepackage{fancyvrb} 
\usepackage{xcolor}
 
\begin{document}

\begin{minipage}{0.2\textwidth}
    \begin{SaveVerbatim}{det}
\begin{equation*}
    \det A =
    \begin{vmatrix}
        1 & 2 \\
        3 & 4
    \end{vmatrix}
\end{equation*}
    \end{SaveVerbatim}
\end{minipage}
    \colorbox{lightgray}{%
    \BUseVerbatim{det}}
\begin{minipage}{0.2\textwidth}
    \centering
    You get:
    \fcolorbox{green}{white}{
        \(
            \det A =
            \begin{vmatrix}
                1 & 2 \\
                3 & 4
            \end{vmatrix}
        \)}
\end{minipage}

\end{document}

Best Answer

You can define the SaveVerbatim environment outside of the minipage and then use that inside the minipage.

\documentclass{scrreport}

\usepackage{mathtools}
\usepackage{fancyvrb} 
\usepackage{xcolor}
 
\begin{document}

\begin{SaveVerbatim}{det}
    \begin{equation*}
        \det A =
        \begin{vmatrix}
            1 & 2 \\
            3 & 4
        \end{vmatrix}
    \end{equation*}
\end{SaveVerbatim}

\begin{minipage}{0.2\textwidth}
    \colorbox{lightgray}{%
        \BUseVerbatim{det}}
\end{minipage}
\hfill
\begin{minipage}{0.2\textwidth}
    \centering
    You get:\\
    \fcolorbox{green}{white}{
        \(
            \det A =
            \begin{vmatrix}
                1 & 2 \\
                3 & 4
            \end{vmatrix}
        \)}
\end{minipage}

\end{document}

enter image description here

Related Question