LaTeX在图片上面使用onimage宏包画TikZ(如矩形、文字)的方法

参考链接:

windows - Overlaying TikZ nodes on an image using TikzEdt and onimage.sty - TeX - LaTeX Stack Exchangeicon-default.png?t=L892https://tex.stackexchange.com/questions/229711/overlaying-tikz-nodes-on-an-image-using-tikzedt-and-onimage-stytikz pgf - Simplest way to overlay a text + rectangle label an image? - TeX - LaTeX Stack Exchangeicon-default.png?t=L892https://tex.stackexchange.com/questions/30427/simplest-way-to-overlay-a-text-rectangle-label-an-imagegraphics - Drawing on an image with TikZ - TeX - LaTeX Stack Exchangeicon-default.png?t=L892https://tex.stackexchange.com/questions/9559/drawing-on-an-image-with-tikz首先,onimage 宏包目前尚未发布在 CTAN 上,所以需要从 http://bazaar.launchpad.net/~tex-sx/tex-sx/development/files 下载 onimage.dtx 文件,然后执行

pdflatex onimage.dtx

会编译生成出 onimage 宏包的 STY 文件、PDF 文档等。当前版本为 2021 年 9 月 19 日的版本。将 onimage.sty 文件放在于 TeX 文件同一目录下,在 TeX 文件导言区添加

\usepackage{onimage}

编译即可。其语法为:

\begin{\tikzonimage}[<image options>]{<image file>}[<TikZ options>]

第一个选项参数会被传递到 \includegraphics 中,第二个选项参数和 tikzpicture 环境中的用法一致。例如,如果要在 some_image.jpg 的中央画一个红色的小圆圈,可写为:

\begin{tikzonimage}[width=0.3\textwidth]{some_image.jpg}[color=red]
    \fill (0.5,0.5) circle [radius=2pt];
\end{tikzonimage}

如果要把多个图像包含在一个 tikzpicture 中,同时对每一个图像都改变其坐标系统的尺度,那么可以使用 tikzonnode:

\begin{\tikzonnode}{<node>}[<TikZ options>]

如果要在一个 node 的中央画一个红色的小圆圈并标有文字,可写为:

\begin{tikzpicture}
    \node (A) [text width=2cm] {abc abc abc abc abc abc abc abc abc};
    \begin{tikzonnode}{A}[color=red]
        \fill (0.5,0.5) circle [radius=2pt];
    \end{tikzonnode}
\end{tikzpicture}

例1.

\documentclass{article}
\usepackage{onimage}
\begin{document}
\begin{tikzonimage}{bottle.jpg}
    \draw [orange, line width=5pt] (0.5,0.92) circle [radius=0.75cm];
\end{tikzonimage}
\end{document}

例2.

\documentclass{article}
\usepackage{onimage}
\begin{document}
\begin{tikzonimage}{bottle.jpg}[tsx/show help lines]
    \draw [orange, line width=5pt] (0.5,0.92) circle [radius=0.75cm];
\end{tikzonimage}
\end{document}

 例3.

\begin{document}
\tikzset{
    image label/.style={
        every node/.style={
            fill=black,
            text=white,
            font=\fontfamily{phv}\selectfont\Large\bfseries,
            anchor=south east,
            xshift=-0.2cm,
            yshift=0.2cm,
            at={(1,0)}
        }
    }
}
\begin{tikzonimage}[width=0.5\textwidth]{bottle}[image label]
\node{A};
\end{tikzonimage}
\begin{tikzonimage}[width=0.25\textwidth]{bottle}[image label]
\node{B};
\end{tikzonimage}
\end{document}

 如果不用 onimage 宏包也可以,例如:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
    \node[anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[width=0.9\textwidth]{some_image.jpg}};
    \begin{scope}[x={(image.south east)},y={(image.north west)}]
        \draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
    \end{scope}
\end{tikzpicture}
\end{document}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ayka

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值