4

Is there a way of ensuring that a given floating object (e.g., a figure) is always placed on a specific page in the output PDF? For instance, "this graphic should always be placed at the top of page 2."

I can usually achieve this behavior with \begin{figure}[t] and then moving around this environment until I find a place where it ends up on the desired output page, but that does not feel very principled, plus I might have to move the environment again every time I make any changes to the preceding text.

And yes, I am aware that this, to some extent, defeats the purpose of a floating object :-)

5

2 Answers 2

5

enter image description here

You can hide the requested page in the width of the float (making it 4sp wider than the page for page 4, or to enable twocolumn support double the value, adding one for the 2nd column) and then adjust the code that looks for (the power of 2 representing) t in [htb]arguments to report t not present on such over-wide floats until the appropriate page is found.

\documentclass{article}

\usepackage{placeonpage}

\usepackage{lipsum}
\begin{document}

\begin{figure}[t]
  \centering
   \rule{3cm}{3cm}
  \caption{A figure on page 4}
 \placeonpage{4}
\end{figure}


\begin{figure}[t]
  \centering
   \rule{3cm}{3cm}
  \caption{A figure on page 6}
 \placeonpage{6}
\end{figure}
\lipsum\lipsum\lipsum\lipsum
\end{document}

a two column example

enter image description here

\documentclass[twocolumn]{article}

\usepackage{placeonpage}

\usepackage{lipsum}
\begin{document}

\begin{figure}[t]
  \centering
   \rule{3cm}{3cm}
  \caption{A figure on top page 4}
 \placeonpage{4}
\end{figure}


\begin{figure}[b]
  \centering
   \rule{3cm}{3cm}
  \caption{A figure on bottom page 5}
 \placeonpage{5}
\end{figure}


\begin{figure}[t]
  \centering
   \rule{3cm}{3cm}
  \caption{A figure on top right page 6}
  \placeonrightcolumn{6}
\end{figure}


\begin{figure*}[t]
  \centering
   \rule{7cm}{3cm}
  \caption{A spanning figure on top page 8}
 \placeonpage{8}
\end{figure*}

\lipsum\lipsum\lipsum\lipsum
\lipsum\lipsum\lipsum\lipsum
\end{document}

placeonpage.sty


\let\latex@getfpsbit\@getfpsbit

\def\@getfpsbit#1{%
   \ifnum\numexpr2*\c@page\if@firstcolumn\else+1\fi\relax
      <\numexpr\wd\@currbox-%
          \ifdim\f@depth=\z@\columnwidth\else\textwidth\fi\relax
    \@tempcnta\z@
    \else
     \latex@getfpsbit#1%
    \fi
}


\def\placeonpage#1{%
  \hrule height 0pt depth 0pt width \dimexpr\hsize+\numexpr2*(#1)\relax sp\relax}
\let\placeoleftcolumn\placeonpage
\def\placeonrightcolumn#1{%
  \hrule height 0pt depth 0pt width \dimexpr\hsize+\numexpr2*(#1)+1\relax sp\relax}


11
  • +1! So, now it does. :)
    – mickep
    Feb 8, 2023 at 5:54
  • This looks very promising! I noticed it does not seem to work if the twocolumn option is used for the document class (neither with \begin{figure} nor with \begin{figure*}). Do you have any ideas for how to fix this?
    – der_herr_g
    Feb 8, 2023 at 21:18
  • 1
    @der_herr_g sigh you just need to do the same thing, in more places:-) I just did single column document t floats. may do the twocolumn topfloats later and add here:-) Feb 8, 2023 at 21:29
  • 1
    @der_herr_g try now, I deleted 90% of the code so now the cases you mention work, also b float. I may change it to use odd/even sp values to denote left or right col, currently only page, so it comes on first column Feb 8, 2023 at 22:15
  • 1
    @der_herr_g left/right column support added Feb 8, 2023 at 22:41
0

In general, no. How do you think that in your code you could put the figure at the end of your 30 page document but expect that it will appear on the second page.

You could use a nonfloating graphic and use \captionof from the caption package to give it a caption.

Something like (after correcting typos and adding text)

 \documentclass...
    \usepackage{caption}
    \begin{document}
    Bunch of text

    \includegraphics{...}
    \captionof{Non floating illustration}

    More text etc...
1
  • 1
    This seems similar to placing a figure with [H]? I feel like that doesn't help with my problem because I will still have to move the figure block around every time I change the surrounding text?
    – der_herr_g
    Jan 31, 2023 at 13:38

You must log in to answer this question.

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