检查该页面上图形位置放置的情况?

检查该页面上图形位置放置的情况?

我已经创建了一个宏来适合图形侧面的标题(侧面标题),

  1. 当图形位于页面顶部时,标题应与
    图形顶部对齐

  2. 当图形位于页面底部时,标题应与图形底部对齐

我已经检查过该选项\ifthenelse{\equal{\@fps}{!t}}{}{\vfill},当我给出图形放置选项时!t,总是只在其他部分上工作

如何检查图形位于顶部或底部的情况?

梅威瑟:

\documentclass{book}
\usepackage{ifthen,color,showframe}
\definecolor{grayten}{cmyk}{0,0,0,0.1}


\makeatletter
\newdimen\tempdimb
\newif\ifsidecap
\newdimen\captionwidth
\newcommand{\processfigure}[3]{%
                \begingroup
                \def\@captype{figure}%
                \let\@makecaption\@figuremakecaption%
                \setbox\@tempboxa=\hbox{#1}%
                \global\@tempdima\wd\@tempboxa%
                \global\tempdimb\ht\@tempboxa%
                 \ifdim\@tempdima>.8\textwidth%
                    \global\sidecapfalse%
                       {\centering#1\par}%
                        \caption{#2\ifx!#3!\else{\ #3}\fi}%
                 \else%
                        \global\sidecaptrue%
                        \vbox to 0pt{#1}%\vskip-\lastskip%
                        \caption{#2\ifx!#3!\else{\ #3}\fi}%
                 \fi%

                \endgroup\global\sidecapfalse}
                
\long\def\@figuremakecaption#1#2{\ifsidecap\else\vspace{\abovecaptionskip}\fi%
                                 \begingroup%
                                 \small
                                  \ifsidecap%
                                    \removelastskip\nointerlineskip%
                                    \captionwidth\textwidth%
                                    \advance\captionwidth-\@tempdima%
                                    \advance\captionwidth-1pc%gutter space
                                      \hbox to \textwidth{\hfill%
                                                \vbox to \tempdimb{\ifthenelse{\equal{\@fps}{!t}}{}{\vfill}%%%%checking whether figure is on top
                                                \hsize\captionwidth%
                                                {\raggedright%
                                                    \leavevmode\raggedright\textbf{#1:}\enspace#2\vphantom{pjQ}\par
                                                    \ifthenelse{\equal{\@fps}{!t}}{\vfill}{}
                                                    }}%
                                        }%
                                    \else%
                                        \raggedright\textbf{#1:}\enspace#2\vphantom{pjQ}\par
                                    \fi%
                                    \endgroup}                
\makeatother


\begin{document}


For measuring time, the horizontal gnomon is inserted into the hole above the scale meant for the current solar month and the staff turned slowly towards the sun so that the gnomon throws its shadow exactly on the scale below. Where the end of the shadow touches the numbered scale, the number indicates in the forenoon the that have elapsed since the sunrise, and in the afternoon, the number of that are to elapse up to sunset.

\begin{figure}[!t]
\processfigure{{\color{grayten}\rule{0.7\textwidth}{15pc}}}{George Cotton's signature of July 1886 for the replacement
spring in McCabe 360. \copyright\ National Maritime Museum (ZAA0213). Photo
by Jonathan Betts}{}
\end{figure}

\begin{figure}[!b]
\processfigure{{\color{grayten}\rule{0.7\textwidth}{15pc}}}{George Cotton's signature of July 1886 for the replacement
spring in McCabe 360. \copyright\ National Maritime Museum (ZAA0213). Photo
by Jonathan Betts}{}
\end{figure}


Compared with these, the Indian versions are much longer, ranging between 1,100 to 1,550mm. Instead of twelve separate scales for the twelve solar months, they usually have eight scales, employing one common scale for two solar months which are at equal distance from the equinoxes. The scales are not divided by continuous curves, but by straight lines unconnected with those on the adjacent column. In other words, these are cruder imitations of those produced in the Islamic world and in Europe. Obviously the idea of the column dial came from the Islamic world   we cannot identify the exact process of transmission   but the Sanskrit authors merely borrowed the name, not the principle feature, namely marking the hours on the different scales by continuous curves.

The extant specimens of Indian column dials are of three types: those made of metal or ivory, those made of wood on which scales are painted, and those made of timber on which the scales are carved. There exist just two specimens of the first group. The first is an exquisitely crafted steel column dial in the museum of the History of Science, Oxford, 95.6 cm, with all the scale lines, numbers and decorative patterns inlaid in gold (Figure. 2). It is topped with an ornate finial and the other end terminates in a sharply polished blade. It must have been created for some prince in Rajasthan. The other, made of ivory, is also of excellent workmanship, with a beautifully carved finial at the top and an ornate end at






\end{document} 

答案1

我不想处理 MWE 的所有细节,但这里有一个使用 TikZ 的测试来确定浮点数是顶部浮点数还是底部浮点数。请注意,此测试假设\topfraction+\bottomfraction<1

不要忘记运行两次。

\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{lipsum}

\newif\iftopfloat
\newcommand{\checkfloat}{\tikz[remember picture,overlay]{%
  \path (current page text area.north);
  \pgfgetlastxy{\x}{\y}%
  \ifdim \y<\topfraction\textheight \global\topfloattrue   \else \global\topfloatfalse \fi}}
  
\begin{document}
\begin{figure}[t]
\centering
\checkfloat
\iftopfloat Top Float \else Bottom Float \fi
\end{figure}

\begin{figure}[b]
\centering
\checkfloat
\iftopfloat Top Floar \else Bottom Float \fi
\end{figure}

\begin{figure}[t]% not on smae page
\centering
\checkfloat
\iftopfloat Top Float \else Bottom Float \fi
\end{figure}

\begin{figure}[b]% not on same page
\centering
\checkfloat
\iftopfloat Top Floar \else Bottom Float \fi
\end{figure}

\lipsum[1-10]
\end{document}

相关内容