# Create a LTXexample environment ala figure*

How can I patch LTXexample to have the behavior of span two columns when used as LTXexample* (like using figure* in a twocolumn mode document)?

Thus, the following code doesn't work due to the figure*, as it will span two columns, but the LTXexample will span only one.

\documentclass[twocolumn]{article}

\usepackage{showexpl}
\usepackage{subfig}

\begin{document}
\pagestyle{empty}

\begin{LTXexample}[pos=b]

\begin{figure*}[bt]%prefer bottom (b) and then top (t)
\centering
\subfloat[Case I]{%<- this stops spurious white spaces
\rule{5cm}{5cm}
\label{fig:first_case}
}%
\subfloat[Case II]{%
\rule{5cm}{6cm}
\label{fig:second_case}
}
\caption{Caption example.}
\label{fig:twocol}
\end{figure*}
\end{LTXexample}
\end{document}


I borrowed a line from David Carlisle's answer to fix an apparent bug in the figure environment, which (I think) was causing an outer par mode error. I then simply switched to \onecolumn mode before your example, then back to \twocolumn mode after.

\documentclass[twocolumn]{article}

\usepackage{showexpl}
\usepackage{subfig}

\makeatletter
\renewenvironment{figure*}[1][]{\def\@captype{figure}}{\par}%<<<<<<
\makeatother

\begin{document}
\pagestyle{empty}

\onecolumn

\begin{LTXexample}[pos=b]
{\begin{figure*}[bt]%prefer bottom (b) and then top (t)
\centering
\subfloat[Case I]{%<- this stops spurious white spaces
\rule{5cm}{5cm}
\label{fig:first_case}
}%
\subfloat[Case II]{%
\rule{5cm}{6cm}
\label{fig:second_case}
}
\caption{Caption example.}
\label{fig:twocol}
\end{figure*}}
\end{LTXexample}

\twocolumn

\end{document}


• I needed to show the example of using figure*. The issue is that I have a two column document, so I would like the figure and the code to appear both spanning the two columns. – adn Jul 24 '14 at 13:48
• I've edited my answer based on your comment. See if this suits your needs. If not, sorry. I've exhausted my limited knowledge. – Michael S Taylor Jul 24 '14 at 15:46