5

How to remove the unbalanced white space below the top rule of the formatted output?

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=25mm]{geometry}
\usepackage{xcolor,showexpl}

\usepackage[active,tightpage]{preview}
\PreviewBorder=3pt
\PreviewEnvironment{LTXexample}

\lstset
{
    language={[LaTeX]TeX},
    basicstyle=\scriptsize\ttfamily,
    keywordstyle=\color{blue}\bfseries,
    backgroundcolor=\color{yellow!50},
    numbers=none,
    frame=single,
    rframe=single,
    tabsize=1,
    pos=r,
    explpreset={%
    },
}

\usepackage{amsmath}
\begin{document}

\begin{LTXexample}
\begin{equation}
E=mc^2
\end{equation}
\end{LTXexample}

\begin{LTXexample}
\begin{align}
ax^2+bx+c
        & = 0\\
ax^2+bx 
        & = -c 
\end{align}
\end{LTXexample}

\end{document}
Moriambar
  • 11,466

2 Answers2

5

You can work with a trick. The environment LTXexample uses the environment lstlisting. That means all options of the package listings are available.

So you can start the displaying at line 2 and in the first line you can prevent the skip:

\begin{LTXexample}[firstline=2]
\abovedisplayskip0pt
\begin{align}
ax^2+bx+c
        & = 0\\
ax^2+bx 
        & = -c 
\end{align}
\end{LTXexample}

Here the complete example:

\documentclass{article}
\usepackage[a4paper,margin=25mm]{geometry}
\usepackage{xcolor,showexpl}

%\usepackage[active,tightpage]{preview}
%\PreviewBorder=3pt
%\PreviewEnvironment{LTXexample}

\lstset
{
    language={[LaTeX]TeX},
    basicstyle=\scriptsize\ttfamily,
    keywordstyle=\color{blue}\bfseries,
    backgroundcolor=\color{yellow!50},
    numbers=none,
    frame=single,
    rframe=single,
    tabsize=1,
    pos=r,
    explpreset={%
    },
}

\usepackage{amsmath}
\begin{document}

\begin{LTXexample}
\begin{equation}
E=mc^2
\end{equation}
\end{LTXexample}

\begin{LTXexample}[firstline=2]
\abovedisplayskip0pt
\begin{align}
ax^2+bx+c
        & = 0\\
ax^2+bx 
        & = -c 
\end{align}
\end{LTXexample}

\end{document}

enter image description here

David Carlisle
  • 757,742
Marco Daniel
  • 95,681
2

I got a more elegant solution: Use preset option.

\documentclass{article}
\usepackage[a4paper,margin=25mm]{geometry}
\usepackage{xcolor,showexpl}


\lstset
{
    language={[LaTeX]TeX},
    basicstyle=\scriptsize\ttfamily,
    keywordstyle=\color{blue}\bfseries,
    backgroundcolor=\color{yellow!50},
    numbers=none,
    frame=single,
    rframe=single,
    tabsize=1,
    pos=r,
    explpreset={%
    },
}

\usepackage{amsmath}
\begin{document}

\begin{LTXexample}
\begin{equation}
E=mc^2
\end{equation}
\end{LTXexample}

\begin{LTXexample}[preset={\abovedisplayskip0pt}]
\begin{align}
ax^2+bx+c
        & = 0\\
ax^2+bx 
        & = -c 
\end{align}
\end{LTXexample}

\end{document}
David Carlisle
  • 757,742