I want to create a table with 2 columns.
The first column will show latex code and the corresponding rendered output. I use
LTXexample to do that.
The second column will show some description about the code.
I can do this scenario successfully if I put the LTXexample environment in each cell of the first column.
Here is the complete minimal code:
Code: Select all
\documentclass{article}
\usepackage{array}
\usepackage{showexpl}
\lstset{
basicstyle=\ttfamily\scriptsize,
tabsize=2,
explpreset={pos=r,rframe={}}
}
\newenvironment{MyTableEnvi}[2]
{
\newcolumntype{C}{m{#1\linewidth}}
\newcolumntype{D}{>{\scriptsize\centering\arraybackslash}m{#2\linewidth}}
\ignorespaces
\begin{tabular}{|C|D|}
\hline
}
{
\end{tabular}
}
\begin{document}
\begin{MyTableEnvi}{0.6}{0.2}
%%%% FIRST ROW
\begin{LTXexample}
$y=\sin x$
\end{LTXexample}
&
Sine function\\ \hline
%%%% SECOND ROW
\begin{LTXexample}
\[
\frac{dy}{dx}=\cos x
\]
\end{LTXexample}
&
Derivative\\ \hline
\end{MyTableEnvi}
\end{document}
My idea is to create a new column type with >{} and <{} that enclose \begin{LTXexample} and \end{LTXexample}, respectively.
Unfortunately, this idea does not work.
Here is the code that I tried, but it did not work.
Code: Select all
\documentclass{article}
\usepackage{array}
\usepackage{showexpl}
\lstset{
basicstyle=\ttfamily\scriptsize,
tabsize=2,
explpreset={pos=r,rframe={}}
}
\newenvironment{MyTableEnvi}[2]
{
\newcolumntype{C}{>{\begin{LTXexample}}m{#1\linewidth}<{\end{LTXexample}}}
\newcolumntype{D}{>{\scriptsize\centering\arraybackslash}m{#2\linewidth}}
\ignorespaces
\begin{tabular}{|C|D|}
\hline
}
{
\end{tabular}
}
\begin{document}
\begin{MyTableEnvi}{0.6}{0.2}
%%%% FIRST ROW
$y=\sin x$
&
Sine function\\ \hline
%%%% SECOND ROW
\[
\frac{dy}{dx}=\cos x
\]
&
Derivative\\ \hline
\end{MyTableEnvi}
\end{document}
Does anyone know how to solve this problem?
Thank you in advance.
Yoyo