Sujet : Re: [LaTeX][PGF/TikZ] Undefined control sequence error for PGF intersections.
De : ud.usenetcorrespondence (at) *nospam* web.de (Ulrich D i e z)
Groupes : comp.text.texDate : 02. Sep 2024, 05:25:49
Autres entêtes
Message-ID : <vb3eoe$20hc7$1@solani.org>
References : 1
User-Agent : Mozilla/5.0 (X11; Linux i686 on x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0
Annada Behera wrote:
Consider this minimal working example. I have two functions, f(x) = x
and g(x) = x+sin(x). I want to draw them with PGF and at the intersection
points, I want put black dots. Here is the TikZ code,
I just realized that inside TikZ-paths you can use \pgfextra{...}
for having LaTeX carry out arbitrary LaTeX code.
You can use this for making \t a global macro:
%\errorcontextlines=10000
\documentclass{standalone}
\usepackage{tikz, amsmath}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
% Plots
\draw[very thick, smooth, samples=20, domain=-6.28:6.28]
[red, name path=line] (0,0) plot (\x, \x);
\draw[very thick, smooth, samples=20, domain=-6.28:6.28]
[blue, name path=sine] (0,0) plot (\x, {\x + sin(\x r)});
% Draw the dots and use \pgfextra for globally saving \t:
\fill [name intersections={of=line and sine, name=i, total=\t},
fill=green, draw=black, thin]
foreach \n in {1,...,\t} {(i-\n) circle (2pt)}
\pgfextra{\global\let\t\t};
% Draw dashed lines
\foreach \n in {1,...,\t} {
\draw[dashed] ({i-\n}) -- (0,0 -| {i-\n});
}
% Axes
\draw [<->](-6.28, 0) -- (6.28, 0);
\draw [<->](0, -6.28) -- (0, 6.28);
\end{tikzpicture}
\end{document}
Sincerely
Ulrich