3

I'm writing a distilled latex manual for my students, and I want to use tables with one column displaying the code and another column displaying the outcome, for all the commands that we need in class.

So far I managed to make it work, but the code is messy, and I would like to create a new column type, something like

\newcolumntype{E}{>{\begin{minipage}{5cm}\begin{equation*}}c<{\end{equation*}\end{minipage}}}

The working code I have is:

\usepackage{mathtools}

\begin{table*}[ht]
\centering
\begin{tabular}{|c |c |}
\hline 
\texttt{Code}       & Output   \\
\hline
\hphantom{-} & \hphantom{-} \\
\begin{minipage}{5cm}
\begin{verbatim} 
\begin{equation*} 
\begin{matrix} 
a_1 & a_2 & a_3 \\ 
b_1 & b_2 & b_3 \\ 
c_1 & c_2 & c_3  
\end{matrix}
\end{equation*} 
\end{verbatim}
\end{minipage} 
& \begin{minipage}{3cm}
\begin{equation*} 
\begin{matrix} 
a_1 & a_2 & a_3 \\ 
b_1 & b_2 & b_3 \\ 
c_1 & c_2 & c_3  
\end{matrix}
\end{equation*}
\end{minipage} \\
\hphantom{-} &  \hphantom{-}\\
\hline
\hphantom{-} &  \hphantom{-}\\
\end{tabular}
\end{table*}
Mahoma
  • 675

1 Answers1

4

How about this -- with the tcolorbox package and sidebyside, there's no need to fiddle around with the minipage and a tabular. The LaTeX code is displayed on the right panel of the box.

enter image description here

\documentclass{article}

\usepackage[most]{tcolorbox}

\usepackage{mathtools}


\begin{document}

\begin{tcblisting}{sidebyside}
\begin{equation*} 
  \begin{matrix} 
    a_1 & a_2 & a_3 \\ 
    b_1 & b_2 & b_3 \\ 
    c_1 & c_2 & c_3  
  \end{matrix}
\end{equation*} 
\end{tcblisting}

\end{document}