为什么图像没有位于右侧节点的中心?
\usepackage{tikz}
\usepackage{mwe}
\tikzset{
image/.style={
path picture={
\node at (path picture bounding box.center) {
\includegraphics[width=2cm]{example-image}};}}
}
\begin{document}
\begin{tikzpicture}
\tikzstyle{node}=[rectangle, minimum width=2cm, minimum height=1cm, thick, draw =black!100, node distance = 16mm]
\node[node, image] (y_src_i) [label=below:$\phi_i$] { };
\node[node, image] (x_src_i) [right=of y_src_i, label=below:$\phi_j$] { };
\end{tikzpicture}
答案1
首先,你需要这个positioning
库。其次,你必须在-styleanchor=center
中指定image
才能达到所需的效果。
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{mwe}
\tikzset{
image/.style={
path picture={
\node[anchor=center] at (path picture bounding box.center) {
\includegraphics[width=2cm]{example-image}};}},
node/.style={
rectangle, minimum width=2cm, minimum height=1cm, thick, draw =black!100, node distance = 26mm}
}
\begin{document}
\begin{tikzpicture}
\node[node,image] (y_src_i) [label=below:$\phi_i$] {};
\node[node,image] (x_src_i) [right=of y_src_i, label=below:$\phi_j$] {};
\end{tikzpicture}
\end{document}