\documentclass[12pt,a4paper,twoside]{report} \usepackage[english,greek]{babel} \usepackage[iso-8859-7]{inputenc} \usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsxtra}
\usepackage{mathtools}
\usepackage{textgreek}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{xcolor}
\usepackage{calc}
\usepackage{tikz-feynman}
\usepackage{pgfplots}
\usetikzlibrary{arrows,shapes,positioning,snakes}
\tikzstyle arrowstyle=[scale=1]
\usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,matrix}
\usetikzlibrary{decorations.pathmorphing,patterns}
\usetikzlibrary{calc,patterns,decorations.markings}
\usetikzlibrary{positioning}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{shapes.geometric}
\begin{figure}[!h]
\centering
\begin{tikzpicture}\node [] at(0,5){
\begin{tikzpicture}
\tikzstyle{spring}=[double,decorate,decoration={pre=lineto,pre length=0.3cm, ,post=curveto,post length=0.3cm,aspect=0, segment length=1mm, amplitude=2.2mm,coil}]
\tikzstyle{platform1}=[fill,pattern=north east lines,draw=none,minimum width=2cm,minimum height=0.3cm]
\coordinate (topspring) at (0,0);
\coordinate (bottomspring) at (0,-2cm);
\draw [spring] (bottomspring) -- (topspring) node[draw=none,pos=.5,left=.25cm] (spring){$k$};
\draw[thick,-](-1,0)--(1,0);
\node [platform1,anchor=south] at (0,0) {};
\end{tikzpicture}};\end{tikzpicture}
\begin{tikzpicture}
\tikzstyle{spring}=[double,decorate,decoration={pre=lineto,pre length=0.3cm, ,post=curveto,post length=0.3cm,aspect=0, segment length=2mm, amplitude=2.2mm,coil}]
\tikzstyle{platform1}=[fill,pattern=north east lines,draw=none,minimum width=2cm,minimum height=0.3cm]
\coordinate (topspring) at (0,0);
\coordinate (bottomspring) at (0,-4cm);
\draw [spring] (bottomspring) -- (topspring) node[draw=none,pos=.5,left=.25cm] (spring){$k$};
\draw[thick,-](-1,0)--(1,0);
\draw[thick,fill=gray!40,rounded corners] (-0.4,-4) rectangle (0.4,-4.7)node at (0,-4.35)[font=\small]{$m_1$};
\node [platform1,anchor=south] at (0,0) {};
\shade[ball color=white] (0,-5.5) circle (0.25)node at (0,-5.5)[font=\small]{$m$};
\draw[thick,-stealth'](0.4,-5.8)--(0.4,-5.2)node[right,pos=0.5][font=\small]{$\vec v_2$};
\draw[thick,-stealth',violet](1,-1)--(1,-2)node[right,pos=0.5][font=\small]{$(+)$};
\end{tikzpicture}
\begin{tikzpicture}
\tikzstyle{spring}=[double,decorate,decoration={pre=lineto,pre length=0.3cm, ,post=curveto,post length=0.3cm,aspect=0, segment length=2mm, amplitude=2.2mm,coil}]
\tikzstyle{platform1}=[fill,pattern=north east lines,draw=none,minimum width=2cm,minimum height=0.3cm]
\coordinate (topspring) at (0,0);
\coordinate (bottomspring) at (0,-4cm);
\draw [spring] (bottomspring) -- (topspring) node[draw=none,pos=.5,left=.25cm] (spring){$k$};
\draw[thick,-](-1,0)--(1,0);
\draw[thick,fill=gray!40,rounded corners] (-0.4,-4) rectangle (0.4,-4.7);
\node [platform1,anchor=south] at (0,0) {};
\shade[ball color=white] (0,-4.35) circle (0.25);
\draw[thick,-stealth'](0.55,-4.5)--(0.55,-3.8)node[right,pos=0.5][font=\small]{$\vec v_{\kappa}$};
\end{tikzpicture}
\end{figure}
\end{document}
答案1
解决方案的主要部分是使用baseline={(topspring)}
这三个tikzpicture
选项将它们对齐到相同的坐标。
但是,您还应该做一些其他的事情:
- 不要嵌套
tikzpicture
。在这种情况下,不支持且没有必要。 - 使用
\tikzset
而不是\tikzstyle
,后者已被弃用。此外,由于您重复使用了一些样式,因此您可以\tikzset
在范围之外定义,然后根据需要更改相关样式。 - 删除所有不必要的库和包,尽量不要多次加载,并考虑哪些包已经加载了东西(例如,
pgfplots
loadstikz
和tikz
loadsxcolor
)。
上述的一个最小工作示例是:
\documentclass[12pt, a4paper, twoside]{report}
\usepackage{tikz}
\usetikzlibrary{patterns, decorations.pathmorphing, arrows}
\tikzset{
spring/.style={
double,
decorate,
decoration={
pre=lineto,
pre length=0.3cm,
post=curveto,
post length=0.3cm,
aspect=0,
segment length=1mm,
amplitude=2.2mm,
coil
}
},
platform1/.style={
fill,
pattern=north east lines,
draw=none,
minimum width=2cm,
minimum height=0.3cm
}
}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}[baseline={(topspring)}]
\coordinate (topspring) at (0,0);
\coordinate (bottomspring) at (0,-2cm);
\draw [spring] (bottomspring) -- (topspring)
node[draw=none, pos=.5, left=.25cm] (spring) {$k$};
\draw[thick] (-1,0) -- (1,0);
\node[platform1, anchor=south] at (0,0) {};
\end{tikzpicture}
\begin{tikzpicture}[baseline={(topspring)}, spring/.append style={segment length=2mm}]
\coordinate (topspring) at (0,0);
\coordinate (bottomspring) at (0,-4cm);
\draw [spring] (bottomspring) -- (topspring)
node[draw=none, pos=.5, left=.25cm] (spring) {$k$};
\draw[thick] (-1,0) -- (1,0);
\draw[thick, fill=gray!40, rounded corners] (-0.4,-4) rectangle (0.4,-4.7)
node at (0,-4.35) [font=\small] {$m_1$};
\node[platform1, anchor=south] at (0,0) {};
\shade[ball color=white] (0,-5.5) circle (0.25)
node at (0,-5.5) [font=\small] {$m$};
\draw[thick, -stealth'] (0.4,-5.8) -- (0.4,-5.2)
node[right, pos=0.5, font=\small] {$\vec v_2$};
\draw[thick, -stealth', violet] (1,-1) -- (1,-2)
node[right, pos=0.5, font=\small] {$(+)$};
\end{tikzpicture}
\begin{tikzpicture}[baseline={(topspring)}, spring/.append style={segment length=2mm}]
\coordinate (topspring) at (0,0);
\coordinate (bottomspring) at (0,-4cm);
\draw [spring] (bottomspring) -- (topspring)
node[draw=none, pos=.5, left=.25cm] (spring) {$k$};
\draw[thick] (-1,0) -- (1,0);
\draw[thick, fill=gray!40, rounded corners] (-0.4,-4) rectangle (0.4,-4.7);
\node[platform1, anchor=south] at (0,0) {};
\shade[ball color=white] (0,-4.35) circle (0.25);
\draw[thick, -stealth'] (0.55,-4.5) -- (0.55,-3.8)
node[right, pos=0.5, font=\small] {$\vec v_{\kappa}$};
\end{tikzpicture}
\end{figure}
\end{document}