到目前为止,我尝试使用看起来可以接受的 minipage,但出于实用性考虑,我希望整个图片都在同一个 tikz 环境中绘制,但我在元素的定位方面遇到了麻烦。
我怎样才能画出与图片中心等距离的两个物体并在那里贴上标签{$\mathrm{k}_{\mathrm{eq}_1}\left[ x_2\left(t\right)-x_1\left(t\right)\right]$}
?
这是我的 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}
答案1
这是一个选项:只需用范围替换图片环境即可移动它们。
\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}]
\begin{scope}[xshift=-4cm] % <- added
\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}
为了完整起见,这里有一个“最小损害”的解决方案。
\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}
请注意,在两个版本中我都必须重命名节点以使节点名称唯一。