floatrow: can I use an alternative figure object?

What I want to do is to use Figure, Table and Alternative Figure captions, placed on the left or the right side depending on whether the current page is odd or even.

Thanks to the great help of the user which answered my two questions floatrow: change caption position in odd and even pages and floatrow: change caption position in odd and even pages (continued) , the floatrow package was used in order to auto position the captions of Figure and Table objects.

I want to use a new object as well, which will contain a picture, but the caption name shall not be "Figure" but something else, let's call it "AlternativeFigure". Thus I created an infobox (see code below) which I try to use the same way I do with Figure and Table, but it doesn't seem to work that way.

Any thoughts would be appreciated.

\documentclass[12pt]{book}

\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage {atbegshi}

\usepackage{floatrow}
\def\mypage{0}
\AtBeginShipout{\ifnum\mypage=0\relax\gdef\mypage{1}%
\else\gdef\mypage{0}\fi}
\expandafter\def\csname floatsetup0\endcsname{%
\floatsetup[widefigure]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}%
\floatsetup[table]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}}
\expandafter\def\csname floatsetup1\endcsname{%
\floatsetup[widefigure]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}%
\floatsetup[table]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}}

\newenvironment{altfig}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{figure*}[#1]}{\end{figure*}}

\newenvironment{alttable}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{table}[#1]}{\end{table}}

%-------------------------------
%   INFOBOX
\usepackage{float}
\newfloat{infobox}{tbp}{ext}
\restylefloat*{infobox}
\floatname{infobox}{AlternativeFigure}

\newenvironment{altfigure}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{infobox}[#1]}{\end{infobox}}
%-------------------------------

\begin{document}
\lipsum[66]

\begin{altfig}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is the first caption text}
\end{altfig}

\lipsum[66]

\begin{alttable}[htp]
\begin{tabular}{lll}
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
\end{tabular}
\caption{This is a table text}
\end{alttable}

\lipsum[66]

\begin{infobox}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is an alternative caption text (should be positioned in the right hand side)}
\end{infobox}

\lipsum[66]

\begin{altfig}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is the second caption text}
\end{altfig}

\lipsum[66]

\begin{alttable}[htp]
\begin{tabular}{lll}
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
\end{tabular}
\caption{This is a table text}
\end{alttable}

\lipsum[66]

\begin{infobox}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is an alternative caption text (should be positioned in the left hand side)}
\end{infobox}

\end{document}


• The floatrow package documentation says not to use it with the float package, which you do here in your MWE. Here are the first words of the abstract: "This package was created as extension of the float package. The floatrow package borrows core code from the float 1 and rotfloat 2 packages, so you must not load these packages." See Section 4.1 How to replace \newfloat with \DeclareNewFloatType – Steven B. Segletes May 23 '17 at 15:06
• @Steven B. Segletes I got it, so should I stick to the floatrow package and try to create the three objects (Figure, Table and AlternativeFigure) with caption texts as illustrated above, or should I give a try to the float package instead? – user3060854 May 23 '17 at 15:14
• I am not familiar enough to suggest which approach to take, but I would presume that one or the other package (or both!) could individually accomplish it. However, wait to see what other responses you get to the question. The fix may be simple and straightforward. – Steven B. Segletes May 23 '17 at 15:16

The floatrow package documentation says not to use it with the float package, which you do here in your MWE. Here are the first words of the abstract: "This package was created as extension of the float package. The floatrow package borrows core code from the float and rotfloat packages, so you must not load these packages."

So, to accomplish these things in the context of floatrow, see Section 4.1 "How to replace \newfloat with \DeclareNewFloatType". As a result, I eliminated the float package and replaced your \newfloat with \DeclareNewFloatType{infobox}{placement=tbp,fileext=ext}.

Finally, you had set up the altfigure environment to take advantage of the side captions, but then failed to use it...you were still calling directly on the infobox environment. Thus, the document calls changed from infobox to altfigure.

\documentclass[12pt]{book}

\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage {atbegshi}

\usepackage{floatrow}
%-------------------------------
%   INFOBOX
\DeclareNewFloatType{infobox}{placement=tbp,fileext=ext}
\restylefloat*{infobox}
\floatname{infobox}{AlternativeFigure}

\newenvironment{altfigure}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{infobox}[#1]}{\end{infobox}}
%-------------------------------

\def\mypage{0}
\AtBeginShipout{\ifnum\mypage=0\relax\gdef\mypage{1}%
\else\gdef\mypage{0}\fi}
\expandafter\def\csname floatsetup0\endcsname{%
\floatsetup[widefigure]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}%
\floatsetup[table]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}%
\floatsetup[infobox]
{margins=hangright,capposition=beside,capbesideposition={top,right},
floatwidth=\textwidth}}
\expandafter\def\csname floatsetup1\endcsname{%
\floatsetup[widefigure]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}%
\floatsetup[table]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}%
\floatsetup[infobox]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}}

\newenvironment{altfig}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{figure*}[#1]}{\end{figure*}}

\newenvironment{alttable}[1][htbp]{\csname floatsetup\mypage\endcsname%
\begin{table}[#1]}{\end{table}}

\begin{document}
\lipsum[66]

\begin{altfig}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is the first caption text}
\end{altfig}

\lipsum[66]

\begin{alttable}[htp]
\begin{tabular}{lll}
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
\end{tabular}
\caption{This is a table text}
\end{alttable}

\lipsum[66]

\begin{altfigure}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is an alternative caption text (should be positioned in the right hand side)}
\end{altfigure}

\lipsum[66]

\begin{altfig}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is the second caption text}
\end{altfig}

\lipsum[66]

\begin{alttable}[htp]
\begin{tabular}{lll}
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
\end{tabular}
\caption{This is a table text}
\end{alttable}

\lipsum[66]

\begin{altfigure}[htp]
\includegraphics[width=0.5\textwidth]{image_test.png}
\caption{This is an alternative caption text (should be positioned in the left hand side)}
\end{altfigure}

\end{document}


• @Steven B. Segletes: Do you know why the solution using the floatrow tools: capbesideposition={top, outside}, which would lead to still simpler code, happens not to work? – Bernard May 23 '17 at 15:38
• @Bernard I am just using what the OP brought to the question. I don't know enough about the packages to answer your question. – Steven B. Segletes May 23 '17 at 15:40
• I hoped you would. A problem with float row is it sometimes seems unstable, as apparently minor modifications in a code sometimes make it unstable, so to say. – Bernard May 23 '17 at 15:43