1

I want to use captions beside figures, so I used the floatrow package. Yet, as illustrated below, I can't auto change the positioning of the caption text from left to right, depending on odd or even page.

Any thoughts would be appreciated.

\documentclass[12pt]{book}

\usepackage{lipsum}
\usepackage{graphicx}

\usepackage[paperheight=24.0cm, paperwidth=20cm, top=1.75cm,bottom=2.0cm,left=2.0cm,right=6.0cm, headsep=0.25cm]{geometry} 

\usepackage{floatrow}
\floatsetup[widefigure]{margins=hangleft,capposition=beside,capbesideposition={top,left},floatwidth=\textwidth}

\begin{document}
\lipsum[6]

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

\lipsum[6] \lipsum[6] \lipsum[6] \lipsum[6]

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


\lipsum[6]
\end{document}

enter image description here

enter image description here

  • Why does the 2nd figure have a number and not the 1st?? – Steven B. Segletes May 22 '17 at 17:34
  • That is because the first figure has been left hand cropped . – user3060854 May 22 '17 at 17:38
1

Perhaps you can use something like this. I create the altfig environment that calls on the macro \csname floatsetup\mypage\endcsname before invoking figure*. The value of \mypage is toggled at every shipout, so that one of two \floatsetups are used, alternating page by page.

\documentclass[12pt]{book}

\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage {atbegshi}
\usepackage[paperheight=24.0cm, paperwidth=20cm, top=1.75cm,bottom=2.0cm,left=2.0cm,right=6.0cm, headsep=0.25cm]{geometry} 

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

\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] \lipsum[6] \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-8]

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

\end{document}

enter image description here

  • OK, seems to work, yet I can't get rid off the demo picture (black square) and use a real picture instead. What should I change in the code? – user3060854 May 22 '17 at 18:18
  • I just had to remove the [demo] from the \usepackage[demo]{graphicx}. It works fine. – user3060854 May 22 '17 at 20:13
  • @user3060854 Indeed. Demo mode is for those who don't have access to your images. Alternately, it is common for people to develop MWE's using images from the mwe package, such as example-image, etc. – Steven B. Segletes May 22 '17 at 20:53
  • Just a last question. Is this possible to work with tables as well? (posistioning the caption of the tables left or right). If so, should I create a new environment? Thank you in advance. – user3060854 May 23 '17 at 5:19
  • 1
    I couldn't repeat it with tables, so I created a new question in order to be fully answered tex.stackexchange.com/questions/371234/… . I would appreciated if you could also help there. – user3060854 May 23 '17 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.