我正在尝试将带有圆角的图像定位到屏幕上的特定位置。但是,根据以下帖子,y 轴偏移和移位不会影响命名的节点,我仍然对如何使用++
以及这是否是最好的方法有点困惑。
就拿我现在的情况来说吧:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage[a4paper,top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip [rounded corners=0.7cm] (0,0) rectangle coordinate (centerpoint) (4,4.0cm);
\node [inner sep=0pt] at (centerpoint) {\includegraphics[width=4.0cm]{dogesmall.jpg}};
\draw[line width=0.08cm,rounded corners=0.7cm] (0,0) rectangle (4,4.0cm);
\end{scope}
\end{tikzpicture}
\end{document}
(其中“dogesmall.jpg”是我当前的图像)
这样会将图像放置在左上角,如边距所定义。但是,我想调整tikz图片无需改变边距,如下所示:
我该如何完成这样的任务?
我尝试过这个帖子使用以下命令:
\newcommand\setcoordinates{
\coordinate (centerpoint) at (4,4.0cm);
}
然后通过引用该坐标\coordinate (centerpoint)
并应用shift
变换,但这也不起作用。有什么想法吗?
答案1
欢迎来到 TeX.SE!您是否在寻找overlay
允许您以绝对坐标定位内容的?
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikzpagenodes}
\usepackage[a4paper,top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}
\begin{document}
\begin{tikzpicture}[overlay,remember picture]
\begin{scope}
\clip [rounded corners=0.7cm] (current page text area.north west) coordinate (centerpoint) rectangle ++(4,-4);
\node [inner sep=0pt,anchor=north west] at (centerpoint)
{\includegraphics[width=4.0cm,height=4cm]{example-image-duck}};
\end{scope}
\draw[line width=0.08cm,rounded corners=0.7cm] (centerpoint) rectangle ++(4,-4);
\end{tikzpicture}
\end{document}
如果要将图像放在页面的左上角(而不是文本区域的左上角),请将其替换(current page text area.north west)
为(current page.north west)
。
附录:这是将图片相对于文本中的当前位置进行移动的版本,使用库\tikzmark
自带的进行设置tikzmark
。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikzpagenodes}
\usetikzlibrary{tikzmark}
\usepackage[a4paper,top=3cm, bottom=3cm, left=2cm, right=2cm]{geometry}
\begin{document}
\tikzmark{x}
\begin{tikzpicture}[overlay,remember picture]
\begin{scope}
\clip [rounded corners=0.7cm] ([xshift=-1cm,yshift=2cm]pic cs:x) coordinate (centerpoint) rectangle ++(4,-4);
\node [inner sep=0pt,anchor=north west] at (centerpoint)
{\includegraphics[width=4.0cm,height=4cm]{example-image-duck}};
\end{scope}
\draw[line width=0.08cm,rounded corners=0.7cm] (centerpoint) rectangle ++(4,-4);
\end{tikzpicture}
\end{document}