[Tex/LaTex] Centering images in a TikZ matrix node

tikz-pgf

I would like to construct a figure using a collection of images/icons as nodes.

I'd like to be able to use matrix, relative positioning and draw arrows between them.

I'm a bit stumped as to why my current solution (see below) displays the images centered at the lower left corner of node boxes, rather than at the center.

I've found that img./style={align=center} solves the problem of centering them horizontally.

Any ideas as on how to align them vertically as well?

Use of pgfdeclareimage and pgfbox are not required, but just a part of my attempt to get it to work.

Code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning} 

\begin{document}
% a bunch of images at 64pxx64px
\pgfdeclareimage{observer}{figures/engineer.png}
\pgfdeclareimage{home}{figures/home.png}
\pgfdeclareimage{user}{figures/user.png}
\pgfdeclareimage{framework}{figures/user.png}

\tikzset{
  % style for inserting images as nodes
  img/.style={
    text width=2cm,
    text height=2cm,
    rectangle,
    align=center,
    draw} % only for debugging..
}

\begin{tikzpicture}
  \matrix[nodes=img, column sep=0.2cm]{
    \node[] (user) {\pgfbox[center,center]{\pgfuseimage{user}}}; &
    \node[ right=of user] (home) {\pgfbox[center,center]{\pgfuseimage{home}}}; &
    \node[ right=of home] (obse) {\pgfbox[center,center]{\pgfuseimage{observer}}}; \\
  };
\end{tikzpicture}
\end{document}

Result:

result

Best Answer

This is one possibility as suggested by Zarko.

\documentclass[tikz,border=4mm]{standalone}
\usetikzlibrary{matrix}
\newcommand{\ing}[1]{\includegraphics[width=2cm]{#1}}
\tikzset{
  % style for inserting images as nodes
  img/.style={
    text width=2cm,
    %text height=2cm,                 %% don't use this
    inner sep=0pt,     %% use this
    outer sep=0pt,     %% and this
    rectangle,
    align=center,
    draw,thick} % only for debugging..
}
\begin{document}
\begin{tikzpicture}
  \matrix[matrix of nodes,nodes=img, column sep=0.2cm]{
    \ing{example-image-a} &
    \ing{example-image-b} &
    \ing{example-image-c} \\
  };
\end{tikzpicture}
\end{document}

enter image description here

Notes:

  1. Don't use text height as it will spoil the show.
  2. Use width value in \ing and text width as you wish.
  3. inner and outer sep with zero value give better look.