在 tikz 上编写 latex 代码

在 tikz 上编写 latex 代码

可以LaTeX在上面写代码tikz吗?让我举个例子来解释一下:我想用乳胶代码创建一个单位圆(这部分已经完成了),用一个单独的文本$\sin²+\cos²=1$ or $\tan(x)=\frac{\sin(x)}{\cos(x)}$来解释所有这些,在单位圆的右边,我认为它正在使用

\begin{tikzpicture}

% Unit circle drawing part

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

\end{tikzpicture}

但是,当我LaTeX使用$\cos²+\sin²=1$etc 发布代码时,它不会形成不同的行或空格。如果所有这些都可能,我该如何创建新行?我尝试了上面的方法,使用double \for new line 或$$code$$for new line,但它也不起作用。帮忙吗?

这是代码

,特克斯

\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}

答案1

在此处输入图片描述

至少有两种可能性。第一种是你一直在尝试的,所需的文本是 的内容node。第二种将使用minipage左侧有图形、右侧有文本的环境。

我遵循了第一个解决方案并遵守了您的代码,但为了清晰起见改变了角度。

代码

\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}

相关内容