Trying to draw a mechanical system of two coupled pendulums, I used the code:
\documentclass[11pt]{article}
\usepackage{tikz,pgfplots}
\usetikzlibrary{intersections,calc,patterns,angles,quotes,}
\pgfplotsset{compat=1.11}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{
decorations.markings,
decorations.pathmorphing,
decorations.pathreplacing,
calc,
patterns,
positioning
}
\tikzset{
spring/.style={thick,decorate,decoration={zigzag,pre length=0.3cm,post length=0.3cm,segment length=6}},
blank/.style={draw=none,fill=none,pos=0.5},
ground/.style={fill,pattern=north east lines,draw=none,minimum width=0.5cm,minimum height=0.3cm},
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=10pt,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,-3pt)$) -- ($(dmp.north)+(0,3pt)$);
}
}, decorate
},
box/.style={draw,thick,minimum width=1cm, minimum height=1cm}
}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=0cm]
\node (wall) [ground, minimum width=4cm] {};
\draw (wall.south east) -- (wall.south west);
\pgfmathsetmacro{\myAngle}{30}
\coordinate (pivot1) at (-1,-0.16);
\draw[thick,-] (pivot1) -- ++ (0,-4)
node (bob1) [draw,fill=gray!40,circle,minimum size=6pt,inner sep=6pt]{$$}
node (resort1) [midway,left]{$$};
\coordinate (pivot2) at (1,-0.16);
\draw[thick,-] (pivot2) -- ++ (0,-4)
node (bob2) [draw,fill=gray!40,circle,minimum size=6pt,inner sep=6pt]{$$}
node (resort2) [midway,right]{$$};
\draw[spring] (resort1) -- (resort2) node[blank,above,yshift=0mm] {$ $};
\draw[decorate,decoration={brace,amplitude=.3cm}] (pivot2.west) -- (resort2.west) node[blank,right] {$l$};
\draw[decorate,decoration={brace,mirror,amplitude=.7cm}] (pivot1.east) to ($(bob1)+(0.02,0.475)$) node[blank,left,xshift=-1.65cm,yshift=-1.9cm] {$L$};
\end{tikzpicture}
\end{figure}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=0cm]
\node (wall) [ground, minimum width=4cm] {};
\draw (wall.south east) -- (wall.south west);
\pgfmathsetmacro{\myAngle}{30}
\coordinate (pivot1) at (-1,-0.16);
\draw[thick,densely dotted,-] (pivot1) -- ++ (0,-1) node (vertical1) [black,below]{$ $};
\draw[thick] (pivot1) -- ++ (270+\myAngle:4cm)
node (bob1) [draw,fill=gray!40,circle,minimum size=6pt,inner sep=6pt]{$ $}
node (spring1) [midway,left]{$$};
\pic [draw, -,"$\theta_1$", angle eccentricity=1.5] {angle = vertical1--pivot1--bob1};
\coordinate (pivot2) at (1,-0.16);
\draw[thick,densely dotted,-] (pivot2) -- ++ (0,-1) node (vertical2) [black,below]{$ $};
\draw[thick] (pivot2) -- ++(270+\myAngle:4cm)
node (bob2) [draw,fill=gray!40,circle,minimum size=6pt,inner sep=6pt]{$ $}
node (spring2) [midway,right]{$$};
\pic [draw, -,font=\small, "$\theta_2$", angle eccentricity=1.5] {angle = vertical2--pivot2--bob2};
\draw[spring] (spring1) -- (spring2) node[blank,above,xshift=-4mm,yshift=0mm] {$ $};
\draw [thick,densely dotted,extended line, name path=A] (spring1) -- (spring2);
\draw [thick,densely dotted,extended line,name path=E] ($(spring1)!1cm!(spring2)$) -- ($(spring1)!-.88cm!(spring2)$);
\draw [thick,densely dotted,extended line, name path=B] ($(spring1)!(pivot1)!(spring2)$) -- (pivot1);
\draw [thick,densely dotted,extended line, name path=C] ($(spring1)!(pivot2)!(spring2)$) -- (pivot2);
\draw[decorate,decoration={brace,amplitude=.3cm}] (pivot1.east) -- (spring1.east) node[blank,right] {$l$};
\node[name intersections={of= E and B}] (P1) at (intersection-1) {$ $};
\node[name intersections={of= A and C}] (P2) at (intersection-1) {$ $};
\draw[decorate,decoration={brace,mirror,amplitude=.25cm}] ($(P1)-(0,0)$) to ($(spring1)+(0.15,0)$) node[blank,below,xshift=-0.5cm,yshift=-2.1cm] {$x$};
\draw[decorate,decoration={brace,amplitude=.25cm}] (spring2) to ($(P2)+(0,0)$) node[blank,below,xshift=1.5cm,yshift=-2.1cm] {$y$};
\draw[decorate,decoration={brace,amplitude=.7cm}] (pivot2.east) to ($(bob2)+(-0.25,0.4)$) node[blank,left,xshift=2.95cm,yshift=-1.3cm] {$L$};
\end{tikzpicture}
\end{figure}
\end{document}
and the output is:
There are some issues in these figures.
- The second figure is not centered like the first one.
- The braces over the length
Lof the strings does not connect correctly the pivots and the bobs. - The caption of the braces over the length
lof the segment connecting the pivots and the points where the spring is attached is not positioned correctly. - I wonder if there a way to set automatically the ends of the braces denoted as
xandy.
How could I fix them?


tikzpicture. (The second one is centered, but the figure as a whole is centered, and it's wider than the first one because of the pendulum going out right.) – Torbjørn T. Jul 04 '20 at 10:01bob? Because you've explicitly told TikZ not to do that with the coordinate calculations such as($(bob2)+(-0.25,0.4)$). – Torbjørn T. Jul 04 '20 at 10:06\path (-8,0) (8,0);to each tikzpicture. – John Kormylo Jul 04 '20 at 14:48