Tikz 机械图像修复问题

Tikz 机械图像修复问题

这是我的代码:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,positioning}

\begin{document}
\tikzset{spring/.style={thick,decorate,decoration={zigzag,pre length=0.3cm,post
length=0.3cm,segment length=6}},
short spring/.style={thick,decorate,decoration={zigzag,pre length=0.05cm,post
length=0.05cm,segment length=6}},
damper/.style={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},
ground/.style={fill,pattern=north east lines,draw=none,minimum
width=0.75cm,minimum height=0.3cm},
ground_magenta/.style={fill,pattern=north east lines,pattern color=magenta,draw=none,minimum
width=0.75cm,minimum height=0.3cm}}

\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick},font=\sffamily]

%ORIGINAL SYSTEM
\node (m_1) [minimum width=1cm,minimum height=0.8cm]{$m_1$};
\node (m_2)[right of= m_1,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_2$};
\draw [spring] (m_1.east) -- (m_2.west) node[midway,below=1mm,draw=none]{$k_{12}$};
\node (ground1) at (m_1.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground1.south west) -- (ground1.south east); 
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground1.south) -| (m_1.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g1}$} ;


\node (m_3)[right of= m_2,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_3$};
\draw [spring] (m_2.east) -- (m_3.west) node[midway,below=1mm,draw=none]{$k_{23}$};
\node (ground2) at (m_2.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground2.south west) -- (ground2.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground2.south) -| (m_2.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g2}$} ;

\node (m_4)[right of= m_3,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_4$};
\draw [spring] (m_3.east) -- (m_4.west) node[midway,below=1mm,draw=none]{$k_{34}$};
\node (ground3) at (m_3.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground3.south west) -- (ground3.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground3.south) -| (m_3.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g3}$} ;

\node (m_5)[right of= m_4,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_5$};
\draw [spring] (m_4.east) -- (m_5.west) node[midway,below=1mm,draw=none]{$k_{45}$};
\node (ground4) at (m_4.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground4.south west) -- (ground4.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground4.south) -| (m_4.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g4}$} ;

\node (ground5) at (m_5.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground5.south west) -- (ground5.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground5.south) -| (m_5.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g5}$} ;

\node (m_a1)[right of= m_5,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm,yshift=1cm,ultra thick]{$m_{a1}$};
\node (m_a2)[right of= m_a1,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm,ultra thick]{$m_{a2}$};
\draw [spring,ultra thick] (m_a1.east) -- (m_a2.west) node[midway,below=1mm,draw=none]{$k_{a3}$};
\draw [ultra thick,decorate,decoration={zigzag,pre
length=3cm,post length=0.85cm,segment length=6}] (m_4.north) |- (m_a1.north west) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{a1}$} ;
\draw [ultra thick,decorate,decoration={zigzag,pre
length=0.5cm,post length=0.85cm,segment length=6}] (m_5.north) |- (m_a1.south west) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{a2}$} ;

\end{tikzpicture}

\end{document}  

需要修复两件事:

  1. 将 ka1 和 ka2 作为 ka3 放置在相应的弹簧下方。
  2. 将弹簧的锚固定在 ma1 上,我不希望它们位于角落,而是以“美观的方式”位于 ma1 的左侧。
  3. 所有内容的字体都需要是 Times New Roman

在此处输入图片描述

答案1

  1. 要调整标签的位置,您可以使用xshiftyshift

  2. 您还可以使用和 调整(m_a1.north west)和的坐标。它们使用方括号括起来,例如。(m_a1.south west)xshiftyshift([yshift=-1mm]m_a1.north west)

  3. 对于 Times New Roman 风格的字体,我建议使用newtx

在此处输入图片描述

\documentclass[margin=1cm]{standalone}
\usepackage{tikz}
\usepackage{newtxtext,newtxmath}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,positioning}

\begin{document}
\tikzset{spring/.style={thick,decorate,decoration={zigzag,pre length=0.3cm,post
length=0.3cm,segment length=6}},
short spring/.style={thick,decorate,decoration={zigzag,pre length=0.05cm,post
length=0.05cm,segment length=6}},
damper/.style={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},
ground/.style={fill,pattern=north east lines,draw=none,minimum
width=0.75cm,minimum height=0.3cm},
ground_magenta/.style={fill,pattern=north east lines,pattern color=magenta,draw=none,minimum
width=0.75cm,minimum height=0.3cm}}

\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick},font=\sffamily]

%ORIGINAL SYSTEM
\node (m_1) [minimum width=1cm,minimum height=0.8cm]{$m_1$};
\node (m_2)[right of= m_1,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_2$};
\draw [spring] (m_1.east) -- (m_2.west) node[midway,below=1mm,draw=none]{$k_{12}$};
\node (ground1) at (m_1.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground1.south west) -- (ground1.south east); 
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground1.south) -| (m_1.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g1}$} ;


\node (m_3)[right of= m_2,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_3$};
\draw [spring] (m_2.east) -- (m_3.west) node[midway,below=1mm,draw=none]{$k_{23}$};
\node (ground2) at (m_2.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground2.south west) -- (ground2.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground2.south) -| (m_2.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g2}$} ;

\node (m_4)[right of= m_3,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_4$};
\draw [spring] (m_3.east) -- (m_4.west) node[midway,below=1mm,draw=none]{$k_{34}$};
\node (ground3) at (m_3.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground3.south west) -- (ground3.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground3.south) -| (m_3.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g3}$} ;

\node (m_5)[right of= m_4,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_5$};
\draw [spring] (m_4.east) -- (m_5.west) node[midway,below=1mm,draw=none]{$k_{45}$};
\node (ground4) at (m_4.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground4.south west) -- (ground4.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground4.south) -| (m_4.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g4}$} ;

\node (ground5) at (m_5.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground5.south west) -- (ground5.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground5.south) -| (m_5.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g5}$} ;

\node (m_a1)[right of= m_5,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm,yshift=1cm,ultra thick]{$m_{a1}$};
\node (m_a2)[right of= m_a1,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm,ultra thick]{$m_{a2}$};
\draw [spring,ultra thick] (m_a1.east) -- (m_a2.west) node[midway,below=1mm,draw=none]{$k_{a3}$};
\draw [ultra thick,decorate,decoration={zigzag,pre
length=3cm,post length=0.85cm,segment length=6}] (m_4.north) |- ([yshift=-1.5mm]m_a1.north west) node[midway,above=2mm,xshift=28mm,draw=none]{$k_{a1}$} ;
\draw [ultra thick,decorate,decoration={zigzag,pre
length=0.8cm,post length=0.65cm,segment length=6}] (m_5.north) |- ([yshift=1.5mm]m_a1.south west) node[midway,below=1mm,xshift=9mm,draw=none]{$k_{a2}$} ;

\end{tikzpicture}

\end{document}  

答案2

与 Milo 的精彩回答略有不同。

  1. midway结合-|有点棘手,因为这将是扭结的坐标。pos=0.75位于垂直拉伸的中间,也pos=0.25位于水平拉伸的中间。因此,我建议只是玩玩,pos=...而不是添加太多xshifts。
  2. north west对应于135。如果你改用145,则你的位置略低于西北。
  3. 抱歉,我不是字体专家。

这是代码。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,decorations.markings,positioning}

\begin{document}
\tikzset{spring/.style={thick,decorate,decoration={zigzag,pre length=0.3cm,post
length=0.3cm,segment length=6}},
short spring/.style={thick,decorate,decoration={zigzag,pre length=0.05cm,post
length=0.05cm,segment length=6}},
damper/.style={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},
ground/.style={fill,pattern=north east lines,draw=none,minimum
width=0.75cm,minimum height=0.3cm},
ground_magenta/.style={fill,pattern=north east lines,pattern color=magenta,draw=none,minimum
width=0.75cm,minimum height=0.3cm}}

\begin{tikzpicture}[every node/.style={draw,outer sep=0pt,thick},font=\sffamily]

%ORIGINAL SYSTEM
\node (m_1) [minimum width=1cm,minimum height=0.8cm]{$m_1$};
\node (m_2)[right of= m_1,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_2$};
\draw [spring] (m_1.east) -- (m_2.west) node[midway,below=1mm,draw=none]{$k_{12}$};
\node (ground1) at (m_1.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground1.south west) -- (ground1.south east); 
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground1.south) -| (m_1.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g1}$} ;


\node (m_3)[right of= m_2,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_3$};
\draw [spring] (m_2.east) -- (m_3.west) node[midway,below=1mm,draw=none]{$k_{23}$};
\node (ground2) at (m_2.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground2.south west) -- (ground2.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground2.south) -| (m_2.south) node[midway,below=1mm,xshift=-3mm,draw=none]{$k_{g2}$} ;

\node (m_4)[right of= m_3,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_4$};
\draw [spring] (m_3.east) -- (m_4.west) node[midway,below=1mm,draw=none]{$k_{34}$};
\node (ground3) at (m_3.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground3.south west) -- (ground3.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground3.south) -|
(m_3.south) node[midway,below=2pt,xshift=-3mm,draw=none]{$k_{g3}$} ;

\node (m_5)[right of= m_4,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm]{$m_5$};
\draw [spring] (m_4.east) -- (m_5.west) node[midway,below=2pt,draw=none]{$k_{45}$};
\node (ground4) at (m_4.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground4.south west) -- (ground4.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground4.south) -|
(m_4.south) node[midway,below=2pt,xshift=-3mm,draw=none]{$k_{g4}$} ;

\node (ground5) at (m_5.south west) [ground,yshift=-0.8cm,xshift=-0.5cm,rotate=90,anchor=north] {};
\draw (ground5.south west) -- (ground5.south east);
\draw [thick,decorate,decoration={zigzag,pre
length=0.1cm,post length=0.85cm,segment length=6}] (ground5.south) -|
(m_5.south) node[midway,below=2pt,xshift=-3mm,draw=none]{$k_{g5}$} ;

\node (m_a1)[right of= m_5,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm,yshift=1cm,ultra thick]{$m_{a1}$};
\node (m_a2)[right of= m_a1,node distance=2.5cm,minimum width=1cm,minimum height=0.8cm,ultra thick]{$m_{a2}$};
\draw [spring,ultra thick] (m_a1.east) -- (m_a2.west) node[midway,below=2pt,draw=none]{$k_{a3}$};
\draw [ultra thick,decorate,decoration={zigzag,pre
length=3cm,post length=0.85cm,segment length=6}] (m_4.north) |- (m_a1.145)
node[pos=0.8,below=2pt,draw=none]{$k_{a1}$} ;
\draw [ultra thick,decorate,decoration={zigzag,pre
length=0.5cm,post length=0.85cm,segment length=6}] (m_5.north) |- (m_a1.215) 
node[pos=0.7,below=2pt,draw=none]{$k_{a2}$} ;

\end{tikzpicture}

\end{document}  

在此处输入图片描述

相关内容