0

Is it possible to write LaTeX codes on tikz? Let me clarify this with an example: i want to create the unit circle (this part is done) with a separated text with latex code with stuff like $\sin²+\cos²=1$ or $\tan(x)=\frac{\sin(x)}{\cos(x)}$ combined with text to explain all that, at the right of the unit circle, i think that it is using

\begin{tikzpicture}

% Unit circle drawing part

%Text
\node[right] (1,0) {the latex code}

\end{tikzpicture}

BUT, when i post the LaTeX code with the $\cos²+\sin²=1$ etc, it does not form a different line or space. How can i create new lines if all this is possible? I've tried with the thing above, using double \ for new line or $$code$$ for new line but it does not work either. Help?

this is the code

,tex

\begin{tikzpicture}[scale=5]

\draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
\filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm) arc
(0:30:3mm) -- cycle;
\draw[->] (-1.5,0) -- (1.5,0) coordinate (x axis);
\draw[->] (0,-1.5) -- (0,1.5) coordinate (y axis);
\draw (0,0) circle (1cm);
\draw[very thick,red]
(30:1cm) -- node[anchor=east,fill=white] {$\sin \alpha$} (30:1cm |- x axis);
\draw[very thick,blue]
(30:1cm |- x axis) -- node[below=2pt,fill=white] {$\cos \alpha$} (0,0);
\draw[very thick,orange] (1,0) -- node [right=1pt,fill=white]
{$\tan \alpha \color{black}=
\frac{{\color{red}\sin \alpha}}{\color{blue}\cos \alpha}$}
(intersection of 0,0--30:1cm and 1,0--1,1) coordinate (t);
\draw (0,0) -- (t);
\filldraw (15:2mm) node[green!50!black] {$\alpha$};
\foreach \x/\xtext in {-1, -0.5/-\frac{1}{2}, 1}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north,fill=white] {$\xtext$};
\foreach \y/\ytext in {-1, -0.5/-\frac{1}{2}, 0.5/\frac{1}{2}, 1}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east,fill=white] {$\ytext$};
\node[draw, align=right] at (2.7,0) {The $\color{green}\text{angle }\alpha$\\ is $30^{\circ}$ in the example  ($\frac{\pi}{6}$ in radians). \\ The $\color{red}{\text{sine of }\alpha}$ , which is the height\\ of the red line is\\  ${\color{red}{\sin \alpha}}=\frac12$ \\ By the Pythagoream Theorem,\\ we have \\ ${\color{blue}\cos^2 \alpha}+{\color{red}\sin^2 \alpha}=1$. \\ Thus the length of the blue line, \\ which is the$\color{blue}{\text{cosine of }\alpha}$,\\ must be\\ ${\color{blue}\cos \alpha}=\sqrt{1-\frac14}=\frac{1}{2}\sqrt{3}$\\ This shows that $\color{yellow}{\tan \alpha}$, \\ which is the height of the orange line is \\  ${\color{yellow}{\tan \alpha}}=\frac{{\color{red}{\sin \alpha}}}{\color{blue}{\cos \alpha}}=\frac{1}{\sqrt{3}}$}; \end{tikzpicture}
11
  • 2
    Welcome to TeX.SE! Partial answer: line breaks in TikZ nodes is answered here.
    – snwflk
    Sep 15, 2020 at 16:30
  • 1
    could you upload the code showing the problem
    – js bibra
    Sep 16, 2020 at 5:03
  • yes but it has 1700 characters and it does not let me :(
    – Al3dium GD
    Sep 19, 2020 at 16:24
  • Did you try posting the code in a comment? Don't do that, you can edit your question, and add the code in the question. There should be an edit link above the comments. The general answer to line breaking in TikZ nodes is however found in the link posted by snwflk, so please look at that if you haven't already. Sep 19, 2020 at 16:40
  • i did looked at that but i don't understand how it is related to what i want, let me edit the code then
    – Al3dium GD
    Sep 19, 2020 at 16:46

1 Answer 1

1

enter image description here

There are at least two possibilities. The first is the one you have been trying, the desired text being the content of a node. The second would use the minipage environment having the drawing on the left and the text on the right.

I followed the first solution sticking to your code, but changed the angle for clarity reasons.

The code

\documentclass[11pt, margin=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary[calc, math]

\begin{document}

\tikzmath{ real \a; \a=60; }
\begin{tikzpicture}[scale=2.5, every node/.style={scale=.9}]
  \draw[step=.5, gray!80!blue!40, very thin] (-1.4, -1.4) grid (1.4, 1.4);
  %% axes
  \draw[gray, thin, ->] (-1.5, 0) -- (1.5, 0) coordinate (x axis);
  \draw[gray, thin, ->] (0, -1.5) -- (0, 1.5) coordinate (y axis);
  \foreach \x/\pos/\xtext in {-1/below left/-1,
    -.5/below left/-\frac{1}{2}, 1/below right/1}{%
    \draw[thick] (\x , 1pt) -- ++(0, -2pt) node[\pos] {$\xtext$};
  }
  \foreach \y/\pos/\ytext in {-1/below left/-1,
    .5/above left/\frac{1}{2}, 1/above left/1}{%
    \draw[thick] (1pt, \y) -- ++(-2pt, 0) node[\pos] {$\ytext$};
  }

  %% circle and trigonometry
  \draw[thin] (0, 0) circle (1);
  \filldraw[draw=green!50!black, fill=green!20]
  (0, 0) -- (.3, 0) arc (0: \a: .3)
  node[pos=.5, anchor=south west, green!50!black, inner sep=2pt]
  {$\alpha$} -- cycle;
  
  \draw[very thick, red]
  (\a:1) -- (\a:1 |- x axis) node[pos=.5, anchor=west] {$\sin\alpha$} ;
  \draw[very thick, blue]
  (0, 0) -- (\a:1 |- x axis) node[pos=.5, anchor=north] {$\cos\alpha$};
  \draw[thick]
  (0, 0) -- (intersection of 0, 0--\a:1 and 1, 0--1, 1) coordinate (T);
  \draw[very thick, magenta]
  (1, 0) -- (T) node [pos=.5, anchor=west] {$\tan\alpha \color{black}=
    \frac{{\color{red}\sin\alpha}}{\color{blue}\cos\alpha}$};

  \path (2, .9)
  node[anchor=north west, align=left, text width=6.1cm] 
  {The {\color{green!50!black}angle} $\alpha$ is $60^{\circ}$ in the
    example ($\frac{\pi}{3}$ in radians).  \\
    The {\color{blue}cosine of} $\alpha$, which is the length of the
    blue line, is ${\color{blue}\cos\alpha}=\frac{1}{2}$. \\
    By Pythagoras' Theorem,
    ${\color{blue}\cos^2\alpha}+{\color{red}\sin^2\alpha}=1$.  Thus the
    length of the red line, which is {\color{red}sine of} $\alpha$,
    equals
    ${\color{red}\sin\alpha}=\sqrt{1-\frac{1}{4}}=\frac{\sqrt{3}}{2}$. \\
    Hence $\color{magenta}\tan\alpha$,  which is the length of the
    magenta line, equals  
    $\frac{\color{red}\sin\alpha}{\color{blue}\cos\alpha}=\sqrt{3}$.
  };
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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