我正在尝试通过使用来自动缩小行数wrapfig.sty
,我的代码如下:
\documentclass{book}
\usepackage{graphicx}
\usepackage{wrapfig}
\graphicspath{{./Images/}}
\begin{document}
\makeatletter
\newbox\figbox%
\newdimen\figdimen%
\newdimen\fightdimen%
\newcommand{\figcheck}[4][tbp]{%
\setbox\figbox=\hbox{#3}%
\figdimen=\wd\figbox%
\fightdimen=\ht\figbox%
\divide\fightdimen by \strip@pt\baselineskip%
\ifdim\figdimen=27pc%
\begin{wrapfigure}[\strip@pt\fightdimen]{r}{\figdimen}%
#2\par
#3
\end{wrapfigure}\fi}
\makeatother
\figcheck{\caption{Priority health
issues}}{\includegraphics[width=27pc]{fig13a-torus.pdf}}{}
Health is, to a large extent, the result of people's decisions about
health behaviours (such as regular participation in physical
activity) and their everyday experiences as they interact and respond to the social, physical and cultural environments in which they live. However, an individual's level of health is determined by a broader range of factors and not just their health-related decisions. Sociocultural, socioeconomic and environmental factors play a significant role in the achievement of good health. Some factors have the potential for change, such as individuals choosing not to smoke, or governments making roads safer. Other factors, such as an individual's genetic makeup, are generally not modifiable.
\end{document}
上述代码运行良好,根据 wrapfig 包,我们需要给出窄线的数量作为四舍五入的值,即 2 或 3 等,它不会接受小数值,小数值会按原样打印,请参阅屏幕截图以供参考:
请建议如何自动修复它。
答案1
以下代码不打印高度(这是由 引起的\strip@pt
),并且只在 的可选参数中使用整数wrapfig
。但是,没有必要进行此计算,因为wrapfig
如果您不指定行,它本身就会进行计算。此外,它不考虑引入的额外空格wrapfig
。
\documentclass{book}
\usepackage{graphicx}
\usepackage{wrapfig}
\begin{document}
\makeatletter
\newbox\figbox
\newdimen\figdimen
\newdimen\fightdimen
\newcommand{\figcheck}[4][tbp]{%
\setbox\figbox=\hbox{#3}%
\figdimen=\wd\figbox
\fightdimen=\ht\figbox
\ifdim\figdimen=27pc
\begin{wrapfigure}[\numexpr\fightdimen/\baselineskip\relax]{r}{\figdimen}%
#2\par
#3
\end{wrapfigure}%
\fi}
\makeatother
\figcheck
{\caption{Priority health issues}}
{\includegraphics[width=27pc]{example-image}}{}
Health is, to a large extent, the result of people's decisions about
health behaviours (such as regular participation in physical
activity) and their everyday experiences as they interact and respond to the social, physical and cultural environments in which they live. However, an individual's level of health is determined by a broader range of factors and not just their health-related decisions. Sociocultural, socioeconomic and environmental factors play a significant role in the achievement of good health. Some factors have the potential for change, such as individuals choosing not to smoke, or governments making roads safer. Other factors, such as an individual's genetic makeup, are generally not modifiable.
\end{document}