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

1 Answer 1

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}

enter image description here

share|improve this answer
    
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 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. –  Mike Taylor Jul 24 at 15:46

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.