如何进行个体浮标放置?

如何进行个体浮标放置?

我的 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}

我有 9 个浮动图形,我尝试将它们定位为使得第三和第四个图形应该单独出现在文本页面上,而之前和之后的其他图形应该在每个文本页面上以更大的数字出现。

编译后可以看到,这不起作用:有两组放置参数:计数器和宏,它们的行为不同。

这些宏仅在第三和第四个数字的组中有效,我用括号 {} 标记了这些数字。可以通过日志文件中的 \typeout 来控制它。如果我大量使用 \global,行为甚至不会改变。

另一方面,计数器通常是全局更改的,因此即使离开组后它们仍会保持更改,如日志文件中的 \typeout 所示。但它们只实现了第八和第九个数字的目标——而不是预期的第三和第四个数字。

所以我的问题是:我怎样才能特别且仅针对这两个图形更改放置宏和计数器,同时保持其他图形的参数不变?

答案1

像这样?

在此处输入图片描述

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

相关内容