# How to add verbatim in a float figure on right page?

I've discovered this post to define the command addfig{} to put figures on the right page.

My problem is that it doesn't work if the figure is a verbatim element.

Here is a minimal not working example :

\documentclass[a4paper,twoside,12pt]{article}

\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[labelsep=endash]{caption}

\usepackage{afterpage}

\makeatletter
\newcommand\blankpage{%
\null
\vfill
\@putfig%
\vfill
\thispagestyle{empty}%
\clearpage%
\afterpage{\blankpage}}
\makeatother

\begin{document}
\afterpage{\blankpage}

\addfig{ % The example work without it
\begin{figure}
\begin{verbatim}
Something
\end{verbatim}
\caption{content of the caption}
\end{figure}
}

First Page

\end{document}


Is there a way to redefine the command to accept verbatim?

• The command doesn't seem to be doing anything very much (why not simply use \begin{figure} ? – David Carlisle Jun 3 '15 at 13:52
• \afterpage{\blankpage} at the beginning of the document add blank page after each page. The command addfig move the figure on this blank page. It's usefull to set all figures on the backside of the page to print it. \begin{figure} alone just add the figure in the text. That's not what I want. – Thibaut Guirimand Jun 3 '15 at 13:59
• But it doesn't check that the figure is being added to a a right hand (odd) page it just always throws a blank page. In what way is it usefully different to \clearpage\begin{figure} (or variants using \cleardoublepage or \cleartoevenpage (eg here – David Carlisle Jun 3 '15 at 14:14

The verbatimbox package can be helpful here. It allows you to stuff verbatim into a box. In this case, I stuff it before the invocation of \addfig into a box named \myafterfig. Then I can recall that box as part of the figure content. Because it is a box, I can center it, as well.

\documentclass[a4paper,twoside,12pt]{article}

%\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[labelsep=endash]{caption}
\usepackage{verbatimbox}
\usepackage{afterpage}

\makeatletter
\newcommand\blankpage{%
\null
\vfill
\@putfig%
\vfill
\thispagestyle{empty}%
\clearpage%
\afterpage{\blankpage}}
\makeatother

\begin{document}
\afterpage{\blankpage}

\begin{myverbbox}{\myafterfig}
Something \verbatim $%^& ANd then &*)$% some more
\end{myverbbox}
\addfig{ % The example work without it
\begin{figure}
\centering
\myafterfig
\caption{content of the caption}
\end{figure}
}

First Page

\end{document}