仅为局部图形提供绝对定位

仅为局部图形提供绝对定位

我尝试overpic仅对单个图形使用绝对定位。\usepackage[abs]{overpic}设置所有图形的绝对定位。有没有办法overpic只为本地环境定义它?或者有没有办法加载绝对和相对版本overpic并以不同方式调用它们?

答案1

正如我在 6 个月前的评论中所建议的那样,\stackinset该包的宏提供了此功能。如果您想要相对于本地图形进行定位,stackengine您可以考虑将其作为替代方案。overpic

\documentclass{article}
\usepackage{stackengine}
\usepackage{graphicx}
\usepackage{xcolor}
\begin{document}
\stackinset{l}{0.2cm}{t}{0.2cm}{\colorbox{white}{blackbird in the snow}}{%
\stackinset{r}{0.5cm}{t}{0.5cm}{\includegraphics[width=3cm]{blackbird.jpg}}{%
\includegraphics[width=\textwidth]{snow.jpg}%
}}
\end{document}

在此处输入图片描述

答案2

绝对和相对定位的选项仅在运行时进行评估。但这可以变得更加灵活。

以下示例定义了可在 的可选参数 中使用的键abspercentpermille。后一个选项允许指定除数( )或 1000 ( )以外的其他除数。该数字必须是正整数。rel=<number>\begin{overpic}[...]percentpermille

该示例基于包overpic的示例overpic-abs.pdfoverpic-rel.pdfgolfer.eps来自的例子Ghostscript

\documentclass{article}
\usepackage{overpic}

\makeatletter
\newcommand\OVP@calc@tmp{%
  \setlength{\unitlength}{\@tempdima}%
  \divide\@tempcnta by \unitlength
  \divide\@tempcntb by \unitlength
  \ifnum\count@=\z@\count@=10\fi
}%
\let\OVP@calc@abs=\OVP@calc@tmp

\renewcommand\OVP@calc@tmp{%  
  \ifnum\@tempcnta>\@tempcntb
    \divide\@tempcnta by \OVP@scale
    \setlength\unitlength{\@tempcnta sp}% 
    \@tempcnta=\OVP@scale
    \divide\@tempcntb by \unitlength
  \else
    \divide\@tempcntb by \OVP@scale
    \setlength\unitlength{\@tempcntb sp}%  
    \@tempcntb=\OVP@scale
    \divide\@tempcnta by \unitlength
  \fi
  \ifnum\count@=\z@
    \count@=\OVP@scale\divide\count@ by 10 %
  \fi
}%
\let\OVP@calc@rel\OVP@calc@tmp

\define@key{Gin}{abs}[]{%
  \let\OVP@calc\OVP@calc@abs
}
\define@key{Gin}{percent}[]{%
  \setkeys{Gin}{rel=100}%
}
\define@key{Gin}{permille}[]{%
  \setkeys{Gin}{rel=\@m}%
}
\define@key{Gin}{rel}{%
  \renewcommand{\OVP@scale}{#1}%
  \ifnum\OVP@scale>\z@
    \let\OVP@calc\OVP@calc@rel
  \else
    \PackageError{overpic}{Invalid number for option `rel'}\@ehc
  \fi
}
\makeatother

\begin{document}
  \begin{overpic}[
    scale=.25,
  ]{golfer.eps}
    \put(5,45){\huge \LaTeX}
    \put(55,10){\includegraphics[scale=.07]{golfer.eps}}
  \end{overpic}

  \begin{overpic}[
    scale=.25,
    rel=20,
  ]{golfer.eps}
    \put(1,9){\huge \LaTeX}
    \put(11,2){\includegraphics[scale=.07]{golfer.eps}}
  \end{overpic}

  \begin{overpic}[
    scale=.25,
    unit=1mm,
    abs,
  ]{golfer.eps}
    \put(3,28){\huge \LaTeX}
    \put(34,5){\includegraphics[scale=.07]{golfer.eps}}
  \end{overpic}
\end{document}

结果

答案3

版本 1.0 已实现此缺失的功能。

相关内容