\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)}
3 つの すべてをオプションとして使用して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}