2

My MWE:

\documentclass[twoside]{book}%

\usepackage{tikzducks}% Delivers figures for testing purposes \usepackage{lipsum}% Delivers blind text

\newcounter{totalnumberold} \newcounter{topnumberold} \newcounter{bottomnumberold}

\newcommand\adaptplacement{% \setcounter{totalnumber}{1} \setcounter{topnumber}{1} \setcounter{bottomnumber}{1} \renewcommand{\topfraction}{.99} \renewcommand{\bottomfraction}{.99} \renewcommand{\textfraction}{.01} \renewcommand\floatpagefraction{1.0}% This makes it nearly impossible to generate a page of floats }%

\begin{document}

\begin{figure}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\begin{figure}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}

% Control:
\typeout{Before group:}
\typeout{topfraction: \topfraction , bottomfraction: \bottomfraction , textfraction: \textfraction , floatpagefraction: \floatpagefraction}%
\typeout{totalnumber: \arabic{totalnumber} , topnumber: \arabic{topnumber}, bottomnumber: \arabic{bottomnumber}}%
{%
    \adaptplacement
    \begin{figure}
        \includegraphics[width=0.5\textwidth]{example-image-duck}
        \caption{A duck}
    \end{figure}
    \begin{figure}
        \includegraphics[width=0.5\textwidth]{example-image-duck}
        \caption{A duck}
    \end{figure}

    % Control:
    \typeout{Inside group:}
    \typeout{topfraction: \topfraction , bottomfraction: \bottomfraction , textfraction: \textfraction , floatpagefraction: \floatpagefraction}%
    \typeout{totalnumber: \arabic{totalnumber} , topnumber: \arabic{topnumber}, bottomnumber: \arabic{bottomnumber}}%
}%

% Control:
\typeout{After group:}
\typeout{topfraction: \topfraction , bottomfraction: \bottomfraction , textfraction: \textfraction , floatpagefraction: \floatpagefraction}%
\typeout{totalnumber: \arabic{totalnumber} , topnumber: \arabic{topnumber}, bottomnumber: \arabic{bottomnumber}}%

\begin{figure}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\begin{figure}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
    \begin{figure}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\begin{figure}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\begin{figure}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\lipsum

\end{document}

I have 9 floating figures and I try to position them such, that the third and the fourth should appear alone on a text page, while the others before and after should appear in bigger numbers per text page.

As one can see after compiling, that doesn't work: There are two groups of placement parameters: counters and macros, which behave differently.

The macros are only valid inside the group of the third and fourth figures, which I marked by brackets {}. One can control that via the \typeout inside the logfile. The behavior even doesn't change, if I make much use of \global.

On the other hand, counters are generally changed globally, so they stay changed even after leaving the group, as the \typeout into the logfile shows. But they only achieve their aim for the eighth and ninth figures -- not for the third and fourth, as intended.

So my question: How can I change placement macros and counters especially and only for the two figures, while leaving the parameters of the other figures unchanged?

ThorstenL
  • 161
  • you are setting them in the wrong place, they have no effect when the figure is stored, they affect how all floats are added to the page by the output routine, so (more or less) has an effect on pages following the setting. If you set within a group the \setcounter values are global so affect following pages. the \renewcommand are local so have no effect unless a page break happens within the group – David Carlisle Jun 23 '23 at 21:03
  • you dont really say what effect you want. to attach properties to a float you can use [htbp!] option and or use \vspace or other mechanisms to modify the box size – David Carlisle Jun 23 '23 at 21:14
  • I want, figures 3 and 4 each to be printed on one page alone, with no other figures, but with text. Figures 1 and 2 should rather be on one common page, figures 5 to 9 should group on pages as well. But I don't want to sort this manually, but by the floating algorithm. I have tried to accomplish this by hook as well, but I couldn't manage ... By the way: I don't understand either, why only the LAST figures appear on one page each, not the first ones ... – ThorstenL Jun 23 '23 at 22:02
  • If I use the properties[hbtp] and for example have one figure[t] and one figure[b], still both can go on one page. I rather want, that two consecutive figures definitely appear near each other without any other figures on two consecutive pages (and I don't want to use \afterpage). – ThorstenL Jun 23 '23 at 22:10
  • "If I use the properties[hbtp] and for example have one figure[t] and one figure[b], still both can go on one page. " not if totalnumber is 1 (for example) – David Carlisle Jun 23 '23 at 23:12
  • See here and infalible way to waintain two figures stacked and then forget that dirty trick and take your time to fully understand floats starting with this question. – Fran Jun 23 '23 at 23:22
  • @David Carlisle: Yes, that is, why I want to have totalnumber = 1. I think the other parameters are not necessary for that, I can have e.g. bottomnumber = topnumber = 5 and still, there should be only one figure per page. But the problem is: totalnumber is a counter, that is set in the text, where I wrote it -- and thus will start much too early (why, then, does it only work that late?) and never stop again. – ThorstenL Jun 23 '23 at 23:30
  • @Fran: I am sorry, but you misunderstood me: I don't want two figures on one page, but two consecutive pages with one figure each -- just the contrary! Think of a panorama over two pages, cut in half for each page ... and I want to do it without \afterpage. I know "this question" already, thank you, I am already fighting with this since several days .... – ThorstenL Jun 23 '23 at 23:35
  • oh, sorry, I was short of time and skimmed it alone. For one image in a double page images may be you want take a look to hvfloat of dpfloat packages, but to me that David answer is much safer. If fix figure options is a problem, consider that you can also change counters topnumber totalnumber or bottomnumber as many times as you want anywere in text, as long as you keep in mind that set one of these counters affect not only next floats , but also to previous floats that end in the same page. – Fran Jun 24 '23 at 18:45
  • @Fran: If you look inside hvfloat, that uses \afterpage for that purpose, and I am just trying to get rid of it's usage. With David Carlisles solution in my eyes the problem is, that for many pages only one float per page will be printed -- I have 430 figures, quite a bunch of tables and some self defined floats as well, so many floats will be printed too late, if I will not die with the "Float(s) lost"-error. – ThorstenL Jun 26 '23 at 09:48
  • Then, the best is use always as many options as possible (i.e., [htbp!] although I prefer avoid has far a posible for a better layout) and only in the final version worry about really very bad placed floats, and the is usually enough to move them some paragraphs or o using a restrictive options, but as little as possible. – Fran Jun 26 '23 at 20:56
  • On the other hand, for the "too many un processed error", since 2015 LaTeX have the command \extrafloats an also \FloatBarrier of placeins, or just \clearpage could help a if you have a bulk of floats. – Fran Jun 26 '23 at 21:03
  • @Fran: Thank you for the hint to \extrafloats, that was new to me, up to now I still used the inferior package morefloats! But if in a document of more than 1000 pages, I always can have only one float per page and then suddenly, after a \clearpage or before a \FloatBarrier, lots of them, that doesn't yet feel like a perfect solution to me ...

    Generally, I use [tbp] or [htbp], I would need the trick with two pages with only one float just for panoramas, which up to now I printed with \afterpage.

    – ThorstenL Jun 27 '23 at 20:16
  • "I always can have only one float ..." Maybe are you setting top/botom/totalnumber to 1 in a real a huge document with many floats ? Seem that you are forcing big delays to process the floats, but that what you need really by is just the contrary, (i.e., increase the 2+1 default) and allow page of floats (using always p or not using options al all) in order to place every float as soon as possible. If you avoid significant delays of floats in all the document, force in some couple of pages two top floats should not be a big issue. – Fran Jun 28 '23 at 00:53
  • @Fran: I have a document of (till now) 1022 pages with 430 figures, a lot of tables, and even other, self-defined floats. In this document, I have placed about 10 double-page floats (panoramas) with \afterpage. But then I got problems with footnotes and Ulrike Fischer advised me, not to use the packages fewerfloatpages and afterpage. So I tried to write a new algorithm for placing the panoramas and this question was an attempt, to solve at least one partial problem. Since an hour, thanks to this and several other discussions on StackExchange, my problem seems to be solved. – ThorstenL Jun 29 '23 at 15:23
  • @Fran: You are right of course: I have generally set totalnumber to 4 and also modified some other float placement parameters in my document, to organize the huge amount of floats without too many floats pages or the error "Float(s) lost". I have described my solution for the panorama on https://tex.stackexchange.com/questions/688991/two-page-panorama-without-afterpage-tables-as-well-as-figures/689127#689127 . It only reduces totalnumber for the two pages of the panorama. – ThorstenL Jun 29 '23 at 15:29

1 Answers1

3

Like this?

enter image description here

\documentclass[twoside]{book}%

\usepackage{graphicx} \usepackage{lipsum}% Delivers blind text

\setcounter{totalnumber}{1} \begin{document}

\begin{figure}[!t]
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\begin{figure}[!t]
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck2}
\end{figure}

    \begin{figure}[t]
        \includegraphics[width=0.5\textwidth]{example-image-duck}
        \caption{A duck3}
    \end{figure}
    \begin{figure}[t]
        \includegraphics[width=0.5\textwidth]{example-image-duck}
        \caption{A duck4}
    \end{figure}

\begin{figure}[t]
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck5}
\end{figure}
\begin{figure}[t]
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
    \begin{figure}[!t]
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\begin{figure}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\begin{figure}[!t]
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{A duck}
\end{figure}
\lipsum

\end{document}

David Carlisle
  • 757,742
  • This result looks exactly like what I want to achieve. You did it in quite an elegant way and it solves, what I asked for with my MWE. Nevertheless, it doesn't solve my original problem ...

    I need a macro, that can do it, like I tried here: https://tex.stackexchange.com/questions/688991/two-page-panorama/689127#689127 in my answer. And I don't want to change the other figures in the text by replacing e.g. [t] with [!t], as I still want to have for example the possibility to hold them from a page with \suppressfloats, I still want floats with [t] to behave different from floats with [!t].

    – ThorstenL Jun 24 '23 at 15:25
  • @ThorstenL as I said, the parameters you were changing are page layout parameters not attached to any float, so as far as I understood your requirements, they do not help. I showed how to solve the example, but I'm sorry I could not extrapolate from that example to any general rules, or guess how you wanted the float settings to act. But that's ok, perhaps someone else may make an answer that covers more cases. – David Carlisle Jun 24 '23 at 15:31
  • that was rather my than your fault, as I wasn't clear enough in my question, about what I wanted. I didn't notice, one could solve my MWE in a way, that might not help with my original problem. Nevertheless, every discussion is helpful to better understand things, thank you! – ThorstenL Jun 24 '23 at 16:06