# Positioning in a mechanical diagram using tikz

I am trying to do a mechanical diagram similar to this one so far I made an attempt using minipage that looks aceptable but for practicality I would like that the whole picture were draw in the same tikz environment but I am having trouble with the positioning of the elements.

How can I draw both massess equally distanced from the center of the picture and put there the label {$\mathrm{k}_{\mathrm{eq}_1}\left[ x_2\left(t\right)-x_1\left(t\right)\right]$}?

Here is my MWE

\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
\tikzstyle{damper}=[thick,decoration={markings,
mark connection node=dmp,
mark=at position 0.5 with
{
\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
\draw [thick] ($(dmp.north east)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate]
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm,inner sep=0pt,outer sep=0pt]
\begin{document}
\begin{minipage}{0.5\textwidth}
%\vspace*{-10cm}
\begin{center}
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
\node [outer sep=0pt, thick] (M3) [minimum width=1cm, minimum height=2cm] {};
\node [draw, outer sep=0pt, thick] (M2) [minimum width=1cm, minimum height=2cm, xshift =2cm] {$\mathrm{m}_2$};
\node [outer sep=0pt, thick] (M1) [minimum width=1cm, minimum height=2cm, xshift =4cm] {};

\draw [-latex,ultra thick]  (M3.east)-- (M2.west)node [midway,above,xshift=-0.5cm] {$\mathrm{k}_{\mathrm{eq}_2}x_2\left( t\right)$};

\draw [-latex,ultra thick]  (M1.west)-- (M2.east)node [midway,above,xshift=1.3cm] {$\mathrm{k}_{\mathrm{eq}_1}\left[ x_2\left(t\right)-x_1\left(t\right)\right]$};
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{minipage}{0.5\textwidth}
%\vspace*{-10cm}
\begin{center}
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
\node [outer sep=0pt, thick] (M2) [minimum width=1cm, minimum height=2cm] {};
\node [draw, outer sep=0pt, thick] (M1) [minimum width=1cm, minimum height=2cm, xshift =2cm] {$\mathrm{m}_1$};
\node [outer sep=0pt, thick] (M3) [minimum width=1cm, minimum height=2cm,xshift=4cm] {};
\draw [-latex,ultra thick]  (M2.east)-- (M1.west)node [midway,above,xshift=-1cm] {};
\end{tikzpicture}
\end{center}
\end{minipage}

\end{document}


This is one option: Just replace the picture environments by scopes to move them around.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
\tikzstyle{damper}=[thick,decoration={markings,
mark connection node=dmp,
mark=at position 0.5 with
{
\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
\draw [thick] ($(dmp.north east)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate]
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm,inner sep=0pt,outer sep=0pt]

\begin{document}
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3}]
\node [outer sep=0pt, thick] (LM3) [minimum width=1cm, minimum height=2cm] {};
\node [draw, outer sep=0pt, thick] (LM2) [minimum width=1cm, minimum height=2cm, xshift =2cm] {$\mathrm{m}_2$};
\node [outer sep=0pt, thick] (LM1) [minimum width=1cm, minimum height=2cm, xshift =4cm] {};

\draw [-latex,ultra thick]  (LM3.east)-- (LM2.west)node [midway,above,xshift=-0.5cm] {$\mathrm{k}_{\mathrm{eq}_2}x_2\left( t\right)$};

\draw [-latex,ultra thick]  (LM1.west)-- (LM2.east)node [midway,above,xshift=1.3cm] {$\mathrm{k}_{\mathrm{eq}_1}\left[ x_2\left(t\right)-x_1\left(t\right)\right]$};
\end{scope}
\begin{scope}[xshift=4cm]
\node [outer sep=0pt, thick] (RM2) [minimum width=1cm, minimum height=2cm] {};
\node [draw, outer sep=0pt, thick] (RM1) [minimum width=1cm, minimum height=2cm, xshift =2cm] {$\mathrm{m}_1$};
\node [outer sep=0pt, thick] (RM3) [minimum width=1cm, minimum height=2cm,xshift=4cm] {};
\draw [-latex,ultra thick]  (RM2.east)-- (RM1.west)node [midway,above,xshift=-1cm] {};
\end{scope}
\path (LM3) -- (RM3) node[midway]{$\mathrm{k}_{\mathrm{eq}_1}\left[ x_2\left(t\right)-x_1\left(t\right)\right]$};
\end{tikzpicture}
\end{document} And for completeness, here is a "minimal damage" solution.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings}
\tikzstyle{spring}=[thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}]
\tikzstyle{damper}=[thick,decoration={markings,
mark connection node=dmp,
mark=at position 0.5 with
{
\node (dmp) [thick,inner sep=0pt,transform shape,rotate=-90,minimum width=15pt,minimum height=3pt,draw=none] {};
\draw [thick] ($(dmp.north east)+(2pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
\draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
}
}, decorate]
\tikzstyle{ground}=[fill,pattern=north east lines,draw=none,minimum width=0.75cm,minimum height=0.3cm,inner sep=0pt,outer sep=0pt]
\begin{document}
\begin{minipage}{0.4\textwidth}
%\vspace*{-10cm}
\begin{center}
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3},remember
picture]
\node [outer sep=0pt, thick] (LM3) [minimum width=1cm, minimum height=2cm] {};
\node [draw, outer sep=0pt, thick] (LM2) [minimum width=1cm, minimum height=2cm, xshift =2cm] {$\mathrm{m}_2$};
\node [outer sep=0pt, thick] (LM1) [minimum width=1cm, minimum height=2cm, xshift =4cm] {};

\draw [-latex,ultra thick]  (LM3.east)-- (LM2.west)node [midway,above,xshift=-0.5cm] {$\mathrm{k}_{\mathrm{eq}_2}x_2\left( t\right)$};

\draw [-latex,ultra thick]  (LM1.west)-- (LM2.east)node [midway,above,xshift=1.3cm] {$\mathrm{k}_{\mathrm{eq}_1}\left[ x_2\left(t\right)-x_1\left(t\right)\right]$};
\end{tikzpicture}
\end{center}
\end{minipage}\hspace*{0.2\textwidth}
\begin{minipage}{0.4\textwidth}
%\vspace*{-10cm}
\begin{center}
\begin{tikzpicture}[scale=1.1, every node/.style={scale=1.3},remember
picture]
\node [outer sep=0pt, thick] (RM2) [minimum width=1cm, minimum height=2cm] {};
\node [draw, outer sep=0pt, thick] (RM1) [minimum width=1cm, minimum height=2cm, xshift =2cm] {$\mathrm{m}_1$};
\node [outer sep=0pt, thick] (RM3) [minimum width=1cm, minimum height=2cm,xshift=4cm] {};
\draw [-latex,ultra thick]  (RM2.east)-- (RM1.west)node [midway,above,xshift=-1cm] {};
\end{tikzpicture}
\end{center}
\end{minipage}
\begin{tikzpicture}[remember picture,overlay]
\path (LM3) -- (RM3) node[midway]{$\mathrm{k}_{\mathrm{eq}_1}\left[ x_2\left(t\right)-x_1\left(t\right)\right]$};
\end{tikzpicture}
\end{document} Note that in both versions I had to rename the nodes in order to make the node names unique.