![使用 \node 定位图像与页面之间的相对位置](https://linux22.com/image/444706/%E4%BD%BF%E7%94%A8%20%5Cnode%20%E5%AE%9A%E4%BD%8D%E5%9B%BE%E5%83%8F%E4%B8%8E%E9%A1%B5%E9%9D%A2%E4%B9%8B%E9%97%B4%E7%9A%84%E7%9B%B8%E5%AF%B9%E4%BD%8D%E7%BD%AE.png)
在下面的代码中,我尝试将瓶子的高度与卡片盒的高度相同,以便瓶子图像的右侧位于页面的右侧。我尝试做类似的事情:
\node at (0,\textwidth) (bottle) [anchor=north east]
{\includegraphics[height=4cm]{bottle_water}};
但这并没有将图像放置在正确的高度。
\begin{document}
\begin{center} \huge
english - french \\
\end{center}
\begin{tikzpicture}
\node at (0,0) (cardbox) [inner sep=0pt]
{\includegraphics[height=4cm]{cardboard}};
\draw[anchor=north west, text width=3cm, inner sep=0.3cm,outer sep=0.3cm]
(cardbox.east) node[draw] (this) {This is a box \\ Ceci est une boîte}
(cardbox.south west) node[draw] (that) {That's a bottle \\ Celà est une bouteille};
\node at (cardbox.east) (bottle) [anchor=north east]
{\includegraphics[height=4cm]{bottle_water}};
\end{tikzpicture}
\end{document}
答案1
像这样?
\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{graphicx}
\begin{document}
\begin{center} \huge
english - french \\
\end{center}
\noindent\begin{tikzpicture}[
node distance = 3mm,
box/.style = {inner sep=0pt},
lbl/.style = {draw,text width=34mm}
]
\setkeys{Gin}{height=4cm}
\path (0,0) node (cardbox) [box, right] {\includegraphics{albIe7h}}
(\linewidth,0) node (botle) [box, left] {\includegraphics{A2eDdiT}};
\node[lbl, right=of cardbox] {This is a box \\ Ceci est une boîte};
\node[lbl, left =of botle] {That's a bottle \\ Celà est une bouteille};
\end{tikzpicture}
\end{document}
附录(1): 您的问题和评论(不幸的是)对我来说不是很清楚。现在我猜你喜欢以下内容:
如果这不是你想要的,请提供一个草图,说明图像和框中的节点应如何在图像中定位
\documentclass{article}
\usepackage{geometry}
\usepackage{dingbat}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{graphicx}
\begin{document}
\begin{center} \huge
english - french \\
\end{center}
\noindent\begin{tikzpicture}[
node distance = 5mm and 22 mm,
box/.style = {inner sep=0pt},
lbl/.style = {draw,text width=34mm}
]
\setkeys{Gin}{height=4cm}
\path (0,0) node (cardbox) [box, right] {\includegraphics{jpg/albIe7h}}
(\linewidth,0) node (botle) [box, left] {\includegraphics{jpg/A2eDdiT}};
%
\node (lbl-1) [lbl, above right=of cardbox.east] {This is a box \\ Ceci est une boîte};
\node (lbl-2) [lbl, below right=of cardbox.east] {That's a bottle \\ Celà est une bouteille};
%
\node[left =2mm of lbl-1,font=\huge] {\rightpointleft};
\node[right=2mm of lbl-2,font=\huge] {\leftpointright};
\end{tikzpicture}
\end{document}
附录(2):
这个建议完全是基于个人意见的。我会使用callout
形状和指向节点的指针,并加上注释。虽然花哨但清晰,代码也更简单:
\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning,
shapes.callouts
}
\usepackage{graphicx}
\begin{document}
\noindent\begin{tikzpicture}[
node distance = 8mm and 13 mm,
box/.style = {inner sep=0pt},
note/.style = {rectangle callout, callout relative pointer={(#1)},
callout pointer width=4mm,
draw, ultra thick, rounded corners,
text width=41mm, inner sep=3mm, font=\large}
]
\setkeys{Gin}{height=4cm}
\path (0,0) node (cardbox) [box, right] {\includegraphics{jpg/albIe7h}}
(\linewidth,0) node (botle) [box, left] {\includegraphics{jpg/A2eDdiT}};
\node (n1) [note={-9mm,1mm},
right=of cardbox.east]
{This is a box\\ Ceci est une boîte};
\node (n2) [note={17mm,2mm},
below=of n1]
{That's a bottle\\ Celà est une bouteille};
\end{tikzpicture}
\end{document}