# \centering and showexpl

Consider the following MWE, where the table is clearly not centered by \centering. Actually, moving \centering outside the table environment give the desired output, but that's no good...

\documentclass{article}
\usepackage{showexpl}

\begin{document}
\begin{LTXexample}
\begin{table}
\centering
\caption{This is a fairly simple table.}
\begin{tabular}{|c|c|} \hline
a & e \\ \hline
b & f \\ \hline
c & g \\ \hline
d & h \\ \hline
\end{tabular}
\end{table}
\end{LTXexample}
\end{document}


Output

-
removed previous comments since I had misread the question. Sorry! –  dcmst Dec 13 '13 at 21:13
@dcmst Adding \par after \end{tabular} works, but why? I never do that when writing... –  Holene Dec 13 '13 at 21:14
A blank line works too. I always put the caption after the table, and that fixes it too. –  marczellm Dec 13 '13 at 21:15
@Holene \centering always needs a following \par try {\centering abc} however end{table} normally adds it implictly. the fact that it doesn't here is probably a bug. –  David Carlisle Dec 13 '13 at 21:18
showexpl surely needs to redefine table (else it would float) and probably the new definition is missing a \par –  cgnieder Dec 13 '13 at 21:19

This is a package bug but easy to fix, the redefinition of table and figure should end with \par not with nothing.

\documentclass{article}
\usepackage{showexpl}

\makeatletter
\renewcommand*\SX@@preset{%
\renewcommand\documentclass[2][]{\SX@eat@version}%
\renewcommand\usepackage[2][]{\SX@eat@version}%
\renewenvironment{document}{}{}%
\renewenvironment{figure}[1][]{\def\@captype{figure}}{\par}%<<<<<<
\renewenvironment{table}[1][]{\def\@captype{table}}{\par}%<<<<<<<<
\renewcommand\cite[1][]{}%
\let\tableofcontens\relax \let\listoffigures\relax
\let\listoftables\relax \let\printindex\relax
\let\listfiles\relax \let\nofiles\relax
\let\index\@gobble \let\label\@gobble
\let\bibliography\@gobble
\let\pagestyle\@gobble \let\thispagestyle\@gobble
%%\let\immediate\relax \let\write\@gobbletwo
%%\let\closeout\@gobble \let\@@input\@gobble
\renewcommand\marginpar[2][]{}%
\renewcommand\footnote[2][]{}%
\let\@footnotetext\@gobble
%%\abovedisplayskip=\z@
%%\abovedisplayshortskip=\z@
}
\makeatother

\begin{document}
\begin{LTXexample}
\begin{table}
\centering
\caption{This is a fairly simple table.}
\begin{tabular}{|c|c|} \hline
a & e \\ \hline
b & f \\ \hline
c & g \\ \hline
d & h \\ \hline
\end{tabular}
\end{table}
\end{LTXexample}
\end{document}

-