6

As you can see, the Greek letter theta which is expected to be just below the curved stroke instead takes on a completely unexpected position. What could it be due to?

\documentclass[14pt]{article}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{snakes}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.arrows}
\usepackage{xcolor}
\definecolor{ocra}{rgb}{0.72,0.53,0.04}
\definecolor{verde}{HTML}{00C200}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[thick]
   \draw[gray,snake=coil,segment length=3pt] (-0.5,3.5) -- (0.75,5) node [midway, right,yshift=3px] (sx) {};
   \draw[gray,snake=coil,segment length=3pt] (0.75,5)-- (2,3.5)     node [midway, left,yshift=3px]  (dx){};
   \node[circle,draw=blue,fill=blue!25,scale=0.75,minimum size=0.1cm] at (-0.5,3.5) (A) {\textcolor{blue}{A}};
   \node[circle,draw=red,fill=red!25,scale=0.75,minimum size=0.1cm] at (0.75,5) (B) {\textcolor{red}{B}};
   \node[circle,draw=ocra,fill=ocra!25,scale=0.75,minimum size=0.1cm] at (2,3.5) (C) {\textcolor{ocra}{C}};
   
   \node[xshift=0.5cm,yshift=-0.5cm] at (A) (a) {};
   \draw[->] (a) -- ++ (-1,0);
   
   \node[xshift=-0.5cm,yshift=-0.5cm] at (C) (c) {};
   \draw[->] (c) -- ++ (1,0);
   \draw[] (sx) to [in=255,out=-75] (dx) node [midway,below] (theta) {$\theta$};;
   
   \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

1
  • BTW, 14pt is a useless option: the article class only knows 10pt (default), 11pt and 12pt. If you're looking for a 14 points text, consider the extsizes classes, e.g. extarticle. Commented May 23 at 9:07

4 Answers 4

11

What you are encountering is the behaviour of nodes with to paths. A to path is a special path that might be built out of quite complicated instructions. When TikZ encounters a to path, therefore, it packages up various pieces of information to pass off to the construction code. In particular, it records the starting coordinate, the target (end) coordinate, and any nodes that are meant to be placed along the curve. The to path then constructs the curve and hands control back to TikZ.

Key to this is how TikZ knows which nodes should lie along the curve. They have to be defined before the target coordinate. Any nodes after that are constructed outside the to curve and so aren't privy to any information relating to that curve. This becomes a problem when using positioning keys such as midway (which is an alias for pos=.5) since there is not a path that this is "midway" along. The node's position then defaults to (0,0) which, because of how your diagram is constructed, is a long way from the diagram itself.

So to fix your issue, you need to put the theta node declaration before the target coordinate, (dx).

Here's a simplified version showing the problem and its solution.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/718033/86}

\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\draw (0,0) circle[radius=3mm];
\draw (0,2) to node[midway] {A} +(1,0) ;
\draw (0,1) to +(1,0) node[midway] {B} ;
   
\end{tikzpicture}

\end{document}

A picture showing the difference when node declarations are before or after the target coordinate in a to path.  It has two lines, one with an 'A' in the middle and one with a 'B' not in the middle but at the origin of the picture.

1
  • Thank you for this insight.
    – AndréC
    Commented May 15 at 22:01
7

I've simplified the code by creating a style my node and using the angles library. I've eliminated superfluous code by using only A, B and C nodes.

\documentclass[14pt]{article}

\usepackage{tikz}
\usetikzlibrary{arrows,snakes,decorations.markings}
\usetikzlibrary{shapes.arrows,angles}
\usepackage{xcolor}
\definecolor{ocra}{rgb}{0.72,0.53,0.04}
\definecolor{verde}{HTML}{00C200}

\tikzset{my node/.style={circle,draw=#1,fill=#1!25,scale=0.75,minimum size=0.1cm,text=#1},
decoration={snake=coil,segment length=3pt}}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[thick]
   \node[my node=blue] at (-0.5,3.5) (A) {A};
   \node[my node=red]  at (0.75,5) (B) {B};
   \node[my node=ocra]  at (2,3.5) (C) {C};
   \draw[gray,decorate] (A)--(B)--(C); 
   \pic [draw,angle radius=1cm,shorten >=1pt,shorten <=3pt,pic text=$\theta$,angle eccentricity=1.2] {angle = A--B--C};
   \draw[->] (A) ++ (.5,-.75)--++(-1,0);
   \draw[->] (C) ++ (-.5,-.75)--++(1,0);
   
   \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

3
  • 1
    Superbe! Thank you very much! Commented May 15 at 20:58
  • If I want write $\theta_\mathrm{eq}$ as pic text, I added the string pic text options={below=-7px} for a better rendering Commented May 15 at 22:33
  • You can too simply write angle eccentricity=1.25
    – AndréC
    Commented May 16 at 4:25
4

The unexpected placement of the Greek letter theta may be attributed to its positioning as a node midway between two points along the snake curve. To resolve this issue, setting pos=0.5 will precisely position it at the midpoint of the curve.

\documentclass[14pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.pathmorphing}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.arrows}
\usepackage{xcolor}
\definecolor{ocra}{rgb}{0.72,0.53,0.04}
\definecolor{verde}{HTML}{00C200}
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[thick]
   \draw[gray,decorate,decoration={coil,segment length=3pt}] (-0.5,3.5) -- (0.75,5) node [midway, right,yshift=3pt] (sx) {};
   \draw[gray,decorate,decoration={coil,segment length=3pt}] (0.75,5)-- (2,3.5)     node [midway, left,yshift=3pt]  (dx){};
   \node[circle,draw=blue,fill=blue!25,scale=0.75,minimum size=0.1cm] at (-0.5,3.5) (A) {\textcolor{blue}{A}};
   \node[circle,draw=red,fill=red!25,scale=0.75,minimum size=0.1cm] at (0.75,5) (B) {\textcolor{red}{B}};
   \node[circle,draw=ocra,fill=ocra!25,scale=0.75,minimum size=0.1cm] at (2,3.5) (C) {\textcolor{ocra}{C}};
   
   \node[xshift=0.5cm,yshift=-0.5cm] at (A) (a) {};
   \draw[->] (a) -- ++ (-1,0);
   
   \node[xshift=-0.5cm,yshift=-0.5cm] at (C) (c) {};
   \draw[->] (c) -- ++ (1,0);
   \draw[] (sx) to [in=255,out=-75] node [pos=0.5, below] (theta) {$\theta$} (dx);
    \end{tikzpicture}
\end{figure}
\end{document}

enter image description here

2
  • 1
    The key midway is an alias for pos=.5, so replacing midway by pos=.5 doesn't change anything. However, you've inadvertently solved the problem by re-writing the line with the theta node so that it is declared before the target coordinate ((dx)) rather than after, as in the code in the question. See my answer for details. Commented May 15 at 21:24
  • @AndrewStacey I have had only a bit of lucky :-). Thank you very much for your details.
    – Sebastiano
    Commented May 15 at 21:28
2

With use of recent tikz syntax, using tikz libraries angles, arrows.meta, decorations.pathmorphing, quotes and positioning, defining all picture elements styles as the tikzpicture options the MWE, which produce desired result can be:

\documentclass[margin=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles, arrows.meta,
                decorations.pathmorphing,
                quotes,
                positioning}

\begin{document}
    \begin{tikzpicture}[
node distance = 21mm and 7mm,
            > = {Straight Barb[scale=0.8]},
     C/.style = {% C as Circle   
                 circle, draw=#1,fill=#1!30, text=#1,
                 minimum size=1.1em, inner sep=0pt},
     MA/.style = {% MA as My Angle
                  draw, <->, font=\footnotesize,
                  angle radius=11mm,  shorten >=3pt,shorten <=3pt,
                  angle eccentricity=1.2},     
     S/.style = {draw=gray, thick, decorate,
                 decoration={snake, amplitude=2pt, 
                            segment length=4pt, pre length=1pt, post length=1pt},
                },
                        ]
\node (a) [C=red]   {A};
\node (b) [C=blue, below  left=of a] {B};
\node (c) [C=ocra, below right=of a] {C};
%
\draw [S]   (a) -- (b);
\draw [S]   (a) -- (c);
%
\pic [MA, "$\theta$"] {angle = b--a--c};
%
\draw[->] ([sy=-4] b.east) --  ([sy=-4] b.west);
\draw[->] ([sy=-4] c.west) --  ([sy=-4] c.east);
    \end{tikzpicture}
\end{document}

enter image description here

Addendum:
I read your question again and now I'm not sure what is your problem actually. Hence I edited a bit original answer and add a new answer for another possible solution:

\documentclass[margin=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles, arrows.meta,
                decorations.pathmorphing,
                quotes,
                positioning}
\definecolor{ocra}{rgb}{0.72,0.53,0.04}

\begin{document}
    \begin{tikzpicture}[
node distance = 21mm and 7mm,
            > = {Straight Barb[scale=0.8]},
     C/.style = {% C as Circle   
                 circle, draw=#1,fill=#1!30, text=#1,
                 minimum size=1.1em, inner sep=0pt},
    MA/.style = {% MA as My Angle
                  draw, <->, font=\footnotesize,
                  angle radius=11mm,  shorten >=3pt, shorten <=3pt,
                  angle eccentricity=1.2},     
    sy/.style = {yshift=#1mm},
     S/.style = {draw=gray, thick, decorate,
                  decoration={snake, amplitude=2pt, 
                              segment length=4pt, pre length=1pt, post length=1pt},
                },
every edge quotes/.style = {fill=white,font=\footnotesize}]
                        ]
\node (a) [C=red]   {A};
\node (b) [C=blue, below  left=of a] {B};
\node (c) [C=ocra, below right=of a] {C};
%
\draw [S]   (a) -- (b);
\draw [S]   (a) -- (c);
%
\pic [MA, "$\theta$"] {angle = b--a--c};
%
\draw[<->] ([sy=-2] b.south) to ["$\vartheta$"]  ([sy=-2] c.south);
    \end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .