2

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}

2 Answers 2

0

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

1
  • Thank you, that really helped me. Actually, I left the SaveVerbatim environment inside the minipage and just changed the \hfill to a \hspace{1cm} so there is not too much empty space between the two objects. Now it works perfectly, thanks! Commented Dec 20, 2021 at 22:43
0

You can simplify the input quite a lot.

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

\newsavebox{\GrayBVbox}
\newenvironment{GrayBVerbatim}
 {%
  \VerbatimEnvironment
  \begin{lrbox}{\GrayBVbox}%
  \begin{BVerbatim}%
 }
 {%
  \end{BVerbatim}%
  \end{lrbox}%
  \begin{tabular}{@{}c@{}}
  \colorbox{lightgray}{\usebox{\GrayBVbox}}
  \end{tabular}%
 }
 
\begin{document}

\begin{GrayBVerbatim}
\begin{equation*}
    \det A =
    \begin{vmatrix}
        1 & 2 \\
        3 & 4
    \end{vmatrix}
\end{equation*}
\end{GrayBVerbatim}
\hspace{1cm}%
\begin{tabular}{@{}c@{}}
    You get: \\
    \fcolorbox{green}{white}{
        \(
            \det A =
            \begin{vmatrix}
                1 & 2 \\
                3 & 4
            \end{vmatrix}
        \)}
\end{tabular}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .