0

I was looking at the tikz/pgf manual (section 22.5), and they have the code

% !!! never ever omit these lines of code !!!
\documentclass[10pt,border=3mm,tikz]{standalone}

\begin{document}

% ... posted code fragment begins \begin{tikzpicture}[domain=0:4] \draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9); \draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$}; \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$}; \draw[color=red] plot (\x,\x) node[right] {$f(x) =x$}; % \x r means to convert '\x' from degrees to _r_adians: \draw[color=blue] plot (\x,{sin(\x r)}) node[right] {$f(x) = \sin x$}; \draw[color=orange] plot (\x,{0.05*exp(\x)}) node[right] {$f(x) = \frac{1}{20} \mathrm e^x$}; \end{tikzpicture} % ... end of posted code fragment

% !!! never ever omit these lines of code !!! \end{document}

But if I try to move the node of say $f(x) = \sin x$ to 80% of the way along the curve, I would think that

        \draw[color=blue] plot (\x,{sin(\x r)}) node[pos=.8] {$f(x) = \sin x$};

should work but it doesn't. I assume this is an issue with plot no knowing things, but is there any solution that doesn't involve me just declaring a node manually in space?

Current result:

current

MS-SPO
  • 11,519
D.J.
  • 159
  • 3
    Actually, it shouldn't work, if I read the manual correctly. The pos parameter isn't implemented for the plot operation. Related: https://tex.stackexchange.com/questions/172842 https://tex.stackexchange.com/questions/437732 – Torbjørn T. Jul 25 '18 at 02:18
  • 3
    You have all data. At pos=0.8 the coordinate is (3.2,{sin(3.2 r)}). –  Jul 25 '18 at 05:44
  • @torbjørn-t Thank you for those references. The workaround in the 2nd link using decoration is very nice. – D.J. Jul 25 '18 at 13:32
  • @marmot Yes, though I know the point, I was just looking to avoid declaring the node manually. – D.J. Jul 25 '18 at 13:32
  • Essentially the same workaround is used in the accepted answer in the first link, where one of the other answers show that with pgfplots plots the pos parameter works. – Torbjørn T. Jul 25 '18 at 13:35
  • 1
    @marmot I did refer to https://tex.stackexchange.com/a/437754/ above ... – Torbjørn T. Jul 25 '18 at 20:47

1 Answers1

1

Here's a simple solution: shift the node away (135deg, 1.5cm) from its position:

... node[right,shift=(135:1.5)] {$f(x) = \sin x$};

It may be less nice than using a pos-parameter, and it requires some guessing, trial&error, but it's still nice, simple, effective.

result

\documentclass[10pt,border=3mm,tikz]{standalone}

\begin{document} \begin{tikzpicture}[domain=0:4] \draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9); \draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$}; \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$}; \draw[color=red] plot (\x,\x) node[right] {$f(x) =x$}; % \x r means to convert '\x' from degrees to _r_adians: % NEW: shift last node towards the upper left of its last position \draw[color=blue] plot (\x,{sin(\x r)}) node[right,shift=(135:1.5)] {$f(x) = \sin x$}; \draw[color=orange] plot (\x,{0.05*exp(\x)}) node[right] {$f(x) = \frac{1}{20} \mathrm e^x$}; \end{tikzpicture} \end{document}

MS-SPO
  • 11,519