# floatrow: change caption position in odd and even pages (continued)

According to this question floatrow: change caption position in odd and even pages I asked for help in order to auto position the caption text of a figure from the floatrow package in odd and even pages.

The question was fully answered, but now I try to use both figures and tables captions in odd and even pages. Yet, the tables captions don't seem to work.

This is the new code:

\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}}
\expandafter\def\csname floatsetup1\endcsname{%
\floatsetup[widefigure]
{margins=hangleft,capposition=beside,capbesideposition={top,left},
floatwidth=\textwidth}}

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

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

\begin{document}
\lipsum[6]

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

\lipsum[6]

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

\lipsum[6] \lipsum[6]

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

\lipsum[6]

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

\lipsum[6-8]

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

\end{document}


And these are the results:

The caption texts of the figures are auto positioned left or right, depending on whether the page is odd or even. The same should work with tables as well, but it seems that something is wrong with the lines of code I added.

Any thoughts would be appreciated.

Your \floatsetup was only for widefigure. You need to add table capability to it. I redefined the \floatsetup0/1 macros:

\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}}


Here is the MWE:

\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*}}

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

\begin{document}
\lipsum[6]

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

\lipsum[6]

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

\lipsum[6] \lipsum[6]

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

\lipsum[6]

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

\lipsum[6-8]

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

\end{document}