4

I need an absolutely-positioned textblock* and a float to appear together on the same page. When the textblock* is written inside the figure, it is executed rightaway and thus seen on the page where the figure appears in the code, but not where the float is finally placed. The following MWE results in the output below.

How can I delay the execution of macros, in this case of \mytextblock, to when the float is actually layed out? Can I somehow store and hook it to the shipout of the float?

\documentclass[a7paper]{scrbook}
\usepackage[absolute]{textpos}

\newcommand{\mytextblock}[1]{%
    \begin{textblock*}{\textwidth}(0pt,0pt)
        #1
    \end{textblock*}%
}

\begin{document}

Some text.

\begin{figure}[p]
    Figure content
    \mytextblock{textblock content} % should appear on the same page as the figure
\end{figure}
    
\end{document}

Output:

the textblock appears on the first instead of on the float page

Instead, the the textblock* should be located on the page where LaTeX decided to put the float:

the textblock should be located on the page where the float is placed

7
  • 1
    Pages 9-10 of the textpos documentation discuss this
    – mbert
    Dec 2, 2023 at 19:32
  • @mbert Thanks for the reference. The documentation discusses a different situation; the workaround there is to use \afterpage to put the textblock* on the next page, but I cannot know what page LaTeX will decide to put the float on. When using relative mode, the textblock shows up on the float page, but it's cumbersome to address my actual layout needs in relative mode.
    – hschmauder
    Dec 2, 2023 at 20:33
  • @hschmauder, sorry, don't understand, how your final result should look like. Can you please add a mock-up for better illustration? Thank you // What's the purpose of your approach, i.e. if you could do it, what will you use it for?
    – MS-SPO
    Dec 2, 2023 at 20:43
  • @MS-SPO I read it as hschmauder wants the "textblock content" to be on the same side as the "Figure content".
    – mickep
    Dec 2, 2023 at 21:55
  • 1
    @MS-SPO I updated the question to better reflect my intention, i.e., although using absolute mode, I want the textblock* to be located on the same page as the float. Since the document is long and contains many images, this may be far away, e.g. at the end of a section.
    – hschmauder
    Dec 2, 2023 at 23:06

1 Answer 1

5

This requires a current LaTeX (with older LaTeX you can do something similar e.g. with zref) and two compilations

\documentclass[a7paper]{scrbook}
\usepackage[absolute]{textpos}
\ExplSyntaxOn
\newcommand{\mytextblock}[2]
 {
  \RecordProperties{#2}{abspage}
  \AddToHook{shipout/foreground}
   {     
     \int_compare:nNnT{\RefProperty{#2}{abspage}}={\g_shipout_readonly_int}
      {
        \begin{textblock*}{\textwidth}(0pt,0pt)
         #1
        \end{textblock*}
      }%
   }   
 }
\ExplSyntaxOff
\usepackage{lipsum}
\begin{document}

Some text.

\begin{figure}[p]
    Figure content
    \rule{1cm}{0.6\textheight}
    \mytextblock{textblock content1}{myfloat1} % 
\end{figure}

\lipsum*[1-3]

\begin{figure}[p]
    Figure content
    \rule{1cm}{0.6\textheight}
    \mytextblock{textblock content2}{myfloat2} % 
\end{figure}

    
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .