How can I put two boxes right next to each other that have the exact same size?

enter image description here

Small variation of @SebGlav abswer:

\documentclass[border=3mm]{standalone}
%\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}

    \begin{tikzpicture}[
node distance = 0pt,
square/.style = {draw=blue!60, fill=blue!5, very thick, 
                 minimum height=1.2em, minimum width=3em, % <---
                 outer sep=0pt},                          % <---
    ]
%Nodes
\node[square]   (maintopic) {2};
\node[square, right=of maintopic] (mynode) {123};
\end{tikzpicture}
\end{document}

Play with positioning abilities and nodes anchor:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning} 

\begin{document}
    

    \begin{tikzpicture}[
        squarednode/.style={rectangle, draw=blue!60, fill=blue!5, very thick, minimum width=\nodewidth},
        ]
        
        \def\nodewidth{5mm}

        \node[squarednode]      (maintopic)                              {2};
        \node[squarednode]      (mynode)            [right= 0.5*\nodewidth of maintopic.center,anchor=west] {123};
        
        \def\nodewidth{10mm}

        \node[squarednode,below=1cm of maintopic.center]      (maintopic2)                              {2};
        \node[squarednode]      (mynode2)            [right= 0.5*\nodewidth of maintopic2.center,anchor=west] {123};
    
    \end{tikzpicture}
\end{document}

nodes without space between them


If you want square nodes, use geometry.shape regular polyogon:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}

\begin{document}

\begin{tikzpicture}[
    squarednode/.style={regular polygon, regular polygon sides=4, 
    draw=blue!60, fill=blue!5, very thick, minimum size=15mm, inner sep=0pt},
    ]
    %Nodes
    \node[squarednode](maintopic) {2};
    \node[squarednode, anchor=west](mynode) at (maintopic.east)  {123};
    %Connections (which ones? they are close together...
    \draw[] (maintopic) (mynode);
\end{tikzpicture}
\end{document}

enter image description here

BTW, there is no such a key as exact size.

To set the color you can pass an argument to a style:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes.geometric}

\begin{document}

\begin{tikzpicture}[
    squarednode/.style={regular polygon, regular polygon sides=4,
    draw=#1!60, fill=#1!5, very thick, minimum size=15mm, inner sep=0pt},
    squarednode/.default=blue,
    ]
    %Nodes
    \node[squarednode=red](maintopic) {2};
    \node[squarednode, anchor=west](mynode) at (maintopic.east)  {123};
    %Connections (which ones? they are close together...
    \draw[] (maintopic) (mynode);
\end{tikzpicture}
\end{document}

enter image description here

Tags:

Tikz Pgf