\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
동일한 좌표에 정렬하는 것입니다.
하지만 다음과 같은 다른 작업도 수행해야 합니다.
- s를 중첩하지 마십시오
tikzpicture
. 이 경우에는 지원되지 않으며 필요하지도 않습니다. \tikzset
대신 사용하세요\tikzstyle
. 후자는 더 이상 사용되지 않습니다. 또한 몇 가지 스타일을 재사용하므로\tikzset
범위 외부에서 정의하고 필요에 따라 관련 스타일을 변경할 수도 있습니다.- 불필요한 라이브러리와 패키지를 모두 제거하고, 항목을 여러 번 로드하지 않도록 하고, 어떤 패키지가 이미 항목을 로드하는지 생각해 보세요(예:
pgfplots
loadtikz
및tikz
loadxcolor
).
위의 최소한의 작업 예는 다음과 같습니다.
\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}