Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.