2

The question could have been subtitled: "how to force a caption to appear always on top of object float". I have a complex set of configurations and commands which I could resume to that MWE.

% !TeX encoding = UTF-8
% !TeX spellcheck = fr_FR

\documentclass[11pt, frenchb, twoside]{report}

% LENGTH
\newlength{\goldenMargin}
\setlength{\goldenMargin}{1.618in}
\newlength{\imageWidth}
\setlength{\imageWidth}{.5\paperwidth}

% IMPORTS
\usepackage{adjustbox}
\usepackage{blindtext}
\usepackage{floatrow}
\usepackage{caption}
\usepackage{ifoddpage}
\usepackage[first=0, last=1, quiet]{lcg}
\usepackage{polyglossia}
\usepackage[paperwidth=8.125in,paperheight=10.25in,
            hmargin={.5\goldenMargin,\goldenMargin},vmargin={.5\goldenMargin},
            marginparwidth={\dimexpr \goldenMargin - 2\marginparsep}]{geometry}
\usepackage[usenames,dvipsnames,svgnames,rgb]{xcolor}
\usepackage{xparse}
\usepackage{xifthen}
\usepackage{xstring}

% % % % % % % % RIGHTLAST % % % % % % % %
\ProvideDocumentCommand \rightlast{}
{\leftskip0ptplus1fil\rightskip0ptplus-1fil\parfillskip0ptplus1fil}

% GRAPHICS
\graphicspath{{../assets/}}

% FLOATS & CAPTIONS
\floatsetup{heightadjust=all}
\DeclareColorBox{blackplate}{\colorbox{black}}
\DeclareFloatStyle{blackFloat}{style=plain,framestyle=colorbox,
        framearound=all,colorframeset=blackplate,frameset={\fboxrule0pt},
        framestyle=colorbox,framefit=yes}

\DeclareFloatSeparators{oddCapSep}{\hspace{\dimexpr -\parindent-.5\goldenMargin}}

\DeclareCaptionLabelFormat{oddLabel}{\fbox{\Large\scshape#1~#2}\hspace*{\fill}}
\DeclareCaptionLabelFormat{evenLabel}{\fbox{\Large\scshape#1~#2}}
\DeclareCaptionLabelSeparator{oddSep}{odd}

\DeclareCaptionFormat{innerCapFormat}
{%
    \parbox{\dimexpr \paperwidth-\imageWidth-\goldenMargin-\parindent-\columnsep}
    {%
        \IfStrEq{#2}{l}
            {\raggedright#1\hspace*{\fill}\bigbreak#3}
            {\rightlast#1\bigbreak#3}
    }
}

\DeclareCaptionStyle{innerCapStyle}%
{%
    singlelinecheck=off,format=innerCapFormat
}

% % % % % % % % UTILS % % % % % % % %
\ExplSyntaxOn
\tl_new:N \l_foo_tl
\tl_new:N \l_bar_tl

\DeclareExpandableDocumentCommand{\IfNoEmptyTF}{ m m m }
{
    \IfNoValueTF{#1}{#2}
    {
        \tl_if_empty:nTF {#1} {#2} {#3}
    }
}

% % % % % % % % BLACKARTWORK % % % % % % % %
% #1 TOC caption
% #2 Caption
% #3 Image Path
\ProvideDocumentCommand \blackArtwork{ m m m }
{
    \adjustboxset{bgcolor=black}
%   \floatsetup[figure]{style=blackFloat}
    \rand\ifthenelse{\equal{\arabic{rand}}{1}}
    {\begin{figure}[t!]}{\begin{figure}[b!]}
        \captionsetup{style=innerCapStyle,font={sf,color=white}}
        \checkoddpage
        \ifthenelse{\boolean{oddpage}}
        {%
            \tl_set:Nn \l_foo_tl {#2\hspace*{\fill}}
            \tl_set:Nn \l_bar_tl {l}
%       \begin{blackbox}
            \adjustboxset{lap=\dimexpr -\parindent - .5\goldenMargin}
            \captionsetup{labelsep=oddSep,labelformat=oddLabel,justification=raggedleft}
        \floatbox[{\capbeside\thisfloatsetup{capbesideposition={right,center},%
                                             capbesidesep=oddCapSep}}]
        }
        {%
            \tl_set:Nn \l_foo_tl {\hspace*{\fill}#2}
            \tl_set:Nn \l_bar_tl {r}
%       \begin{blackbox}
            \adjustboxset{lap=.5\goldenMargin}
            \captionsetup{labelformat=evenLabel}
        \floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,center}}}]
        }
        {figure}
        {\caption[#1]{\l_foo_tl}\label{fig:#3}}
        {\adjustbox{inner}{\makebox[\paperwidth][\l_bar_tl]{\includegraphics[width=\imageWidth]{#3}}}}
%        \end{blackbox}
    \end{figure}
    \adjustboxset{}
}
\ExplSyntaxOff

\ProvideDocumentEnvironment{blackbox}{}
    {\begin{adjustbox}{frame}}
    {\end{adjustbox}}

\begin{document}
\blindtext
\blackArtwork{Miguel Chevalier, \textit{Magic Carpets}, 2014}
             {Miguel Chevalier, Magic Carpets, 2014. Installation générative et interactive de réalité virtuelle. \O~17.5 m. Festival Internazionale di Andria, Castel del Monte.}
             {chevalier_magic-carpets}
\blindtext[3]
\blackArtwork{Zu Doyang, \textit{Mini-mondes oculaires}, 2002--2007}
             {Zu Doyang, \textit{Mini-mondes oculaires}, 2002--2007. Épreuve à développement chromogène, 1.23 $\times$ 1.25 m chacune. Association des musées d'art coréen, Séoul}
             {doyang_spheres}
\end{document}

mwe output

The blackArtwork randomly forces a figure to by typeset at the top | bottom of the page. The background is obtained via an adjustbox surrounding a \paperwidth wide mbox within which the graphic in finally included. You can see there's no caption on the second page. My guess is that everything is typeset from left to right and that "depth" (if that concept only exists in latex) of objects are given that way. So on an even page, the caption is typeset before the image, and then appears covered by the black background. I tried different mixtures in order to enclose the image and caption within a \paperwidth box with a solid background and no other margin, but I can't make it work.

So maybe there is a way to force the caption to be typeset after the image or not, or maybe I'm complicating it and there's a better way to achieve this.

3

The caption moving is being done by floatrow and you can modify its left placement to place it after the image but backspaced, rather than before the image. I don't know the package so I may have missed some cases, but this works here:

enter image description here

\documentclass[11pt, frenchb, twoside]{report}

% LENGTH
\newlength{\goldenMargin}
\setlength{\goldenMargin}{1.618in}
\newlength{\imageWidth}
\setlength{\imageWidth}{.5\paperwidth}

% IMPORTS
\usepackage{adjustbox}
\usepackage{blindtext}
\usepackage{floatrow}

\makeatletter
\renewcommand\flrow@FC@{\global\let\flrow@typ@tmpset\undefined
 \FB@frame{\begin@FBBOX
   \adj@dim\FBo@wd+\FBo@wadj=\hsize
   \settowidth\@tempdimb{\floatcapbesidesep}\advance\hsize\@tempdimb
   \advance\hsize\FBc@wd\@parboxrestore\leftmargin\z@\rightmargin\z@
   \@@FBabove
    \hbox{%
\floatfacing*%
      {%
\ifvoid\@floatcapt\else
\kern\FBc@wd
          \floatcapbesidesep
\fi
       \FBf@raise{\FBo@frame{\FCo@box{\FBw@box\FBc@wd\unvbox\@currbox}}}%%
\ifvoid\@floatcapt\else
\rlap{\kern-\FBc@wd\kern-\columnsep\kern-\wd\@floatcapt
         \FCc@box{\FBw@box\FBc@wd\unvbox\@floatcapt\FB@foot}}%
\fi
}%
{\FBf@raise{\FBo@frame{\FCo@box{\FBw@box\FBo@wd\unvbox\@currbox}}}%
       \ifvoid\@floatcapt\else
         \floatcapbesidesep\FCc@box{\FBw@box\FBc@wd
           \unvbox\@floatcapt\FB@foot}\fi
      }%
%
}%
\par\@@FBbelow\vskip\z@
    \end@FBBOX
    \global\setbox\@floatcapt\box\voidb@x}}
\makeatother


\usepackage{caption}
\usepackage{ifoddpage}
\usepackage[first=0, last=1, quiet]{lcg}
\usepackage{polyglossia}
\usepackage[paperwidth=8.125in,paperheight=10.25in,
            hmargin={.5\goldenMargin,\goldenMargin},vmargin={.5\goldenMargin},
            marginparwidth={\dimexpr \goldenMargin - 2\marginparsep}]{geometry}
\usepackage[usenames,dvipsnames,svgnames,rgb]{xcolor}
\usepackage{xparse}
\usepackage{xifthen}
\usepackage{xstring}

% % % % % % % % RIGHTLAST % % % % % % % %
\ProvideDocumentCommand \rightlast{}
{\leftskip0ptplus1fil\rightskip0ptplus-1fil\parfillskip0ptplus1fil}

% GRAPHICS
\graphicspath{{../assets/}}

% FLOATS & CAPTIONS
\floatsetup{heightadjust=all}
\DeclareColorBox{blackplate}{\colorbox{black}}
\DeclareFloatStyle{blackFloat}{style=plain,framestyle=colorbox,
        framearound=all,colorframeset=blackplate,frameset={\fboxrule0pt},
        framestyle=colorbox,framefit=yes}

\DeclareFloatSeparators{oddCapSep}{\hspace{\dimexpr -\parindent-.5\goldenMargin}}

\DeclareCaptionLabelFormat{oddLabel}{\fbox{\Large\scshape#1~#2}\hspace*{\fill}}
\DeclareCaptionLabelFormat{evenLabel}{\fbox{\Large\scshape#1~#2}}
\DeclareCaptionLabelSeparator{oddSep}{odd}

\DeclareCaptionFormat{innerCapFormat}
{%
    \parbox{\dimexpr \paperwidth-\imageWidth-\goldenMargin-\parindent-\columnsep}
    {%
        \IfStrEq{#2}{l}
            {\raggedright#1\hspace*{\fill}\bigbreak#3}
            {\rightlast#1\bigbreak#3}
    }
}

\DeclareCaptionStyle{innerCapStyle}%
{%
    singlelinecheck=off,format=innerCapFormat
}

% % % % % % % % UTILS % % % % % % % %
\ExplSyntaxOn
\tl_new:N \l_foo_tl
\tl_new:N \l_bar_tl

\DeclareExpandableDocumentCommand{\IfNoEmptyTF}{ m m m }
{
    \IfNoValueTF{#1}{#2}
    {
        \tl_if_empty:nTF {#1} {#2} {#3}
    }
}

% % % % % % % % BLACKARTWORK % % % % % % % %
% #1 TOC caption
% #2 Caption
% #3 Image Path
\ProvideDocumentCommand \blackArtwork{ m m m }
{
    \adjustboxset{bgcolor=black}
%   \floatsetup[figure]{style=blackFloat}
    \rand\ifthenelse{\equal{\arabic{rand}}{1}}
    {\begin{figure}[t!]}{\begin{figure}[b!]}
        \captionsetup{style=innerCapStyle,font={sf,color=white}}
        \checkoddpage
        \ifthenelse{\boolean{oddpage}}
        {%
            \tl_set:Nn \l_foo_tl {#2\hspace*{\fill}}
            \tl_set:Nn \l_bar_tl {l}
%       \begin{blackbox}
            \adjustboxset{lap=\dimexpr -\parindent - .5\goldenMargin}
            \captionsetup{labelsep=oddSep,labelformat=oddLabel,justification=raggedleft}
        \floatbox[{\capbeside\thisfloatsetup{capbesideposition={right,center},%
                                             capbesidesep=oddCapSep}}]
        }
        {%
            \tl_set:Nn \l_foo_tl {\hspace*{\fill}#2}
            \tl_set:Nn \l_bar_tl {r}
%       \begin{blackbox}
            \adjustboxset{lap=.5\goldenMargin}
            \captionsetup{labelformat=evenLabel}
        \floatbox[{\capbeside\thisfloatsetup{capbesideposition={left,center}}}]
        }
        {figure}
        {\caption[#1]{\l_foo_tl}\label{fig:#3}}
        {\adjustbox{inner}{\makebox[\paperwidth][\l_bar_tl]{\includegraphics[width=\imageWidth]{#3}}}}
%        \end{blackbox}
    \end{figure}
    \adjustboxset{}
}
\ExplSyntaxOff

\ProvideDocumentEnvironment{blackbox}{}
    {\begin{adjustbox}{frame}}
    {\end{adjustbox}}

\begin{document}
\blindtext
\blackArtwork{Miguel Chevalier, \textit{Magic Carpets}, 2014}
             {Miguel Chevalier, Magic Carpets, 2014. Installation générative et interactive de réalité virtuelle. \O~17.5 m. Festival Internazionale di Andria, Castel del Monte.}
             {example-image}
\blindtext[3]
\blackArtwork{Zu Doyang, \textit{Mini-mondes oculaires}, 2002--2007}
             {Zu Doyang, \textit{Mini-mondes oculaires}, 2002--2007. Épreuve à développement chromogène, 1.23 $\times$ 1.25 m chacune. Association des musées d'art coréen, Séoul}
             {example-image-a}
\end{document}
| improve this answer | |

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.