将绘制的 tikzpicture 放置在方程式数组旁边

将绘制的 tikzpicture 放置在方程式数组旁边

目前我有这个有效的代码:

\documentclass{article}
\usepackage{multirow}
\usepackage{mathtools}
\usepackage{tabu}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{tkz-euclide}


\begin{document}

\(\begin{array}{ll}
\sin \theta = \dfrac{\text{opposite}}{\text{hypotenuse}} & \multirow{3}{*}{22} \\
\cos \theta = \dfrac{\text{adjacent}}{\text{hypotenuse}} & \\
\tan \theta = \dfrac{\text{opposite}}{\text{adjacent}} &
\end{array}\)

\begin{tikzpicture}
\coordinate (O) at (0,0);
\coordinate (A) at (3,0);
\coordinate (B) at (3,2);

\draw (O)--(A)--(B)--cycle;

\tkzLabelSegment[below=2pt](O,A){\textit{adjacent}}
\tkzLabelSegment[right=2pt](A,B){\textit{opposite}}
\tkzLabelSegment[above left=2pt](O,B){\textit{hypotenuse}}

\tkzMarkRightAngle[fill=none,size=0.3,opacity=.4](O,A,B)% square angle here
\tkzMarkAngle[fill=none,size=0.5,opacity=.4](A,O,B)
\tkzLabelAngle[pos = 0.8](A,O,B){\(\theta\)}

\end{tikzpicture}

\end{document}

图片 2

但是,我希望它们将三角形与方程式的右侧对齐。我尝试使用多行,如图所示22。但是,如果我复制tikzpicture并替换22,代码将无法编译。

我还应该使用什么方法?

答案1

看到您正在使用内联数学(\( .. \)),您需要做的就是删除\)和之间的空行\begin{tikzpicture}

这是一个略有不同的变体,使用aligned而不是array,并修改 的基线,以tikzpicture实现更好的垂直对齐。

在此处输入图片描述

\documentclass{article}
\usepackage{mathtools}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}

\(\begin{aligned}
\sin \theta &= \dfrac{\text{opposite}}{\text{hypotenuse}}  \\
\cos \theta &= \dfrac{\text{adjacent}}{\text{hypotenuse}}  \\
\tan \theta &= \dfrac{\text{opposite}}{\text{adjacent}} 
\end{aligned}\)\qquad
\begin{tikzpicture}[baseline=4ex]
\coordinate (O) at (0,0);
\coordinate (A) at (3,0);
\coordinate (B) at (3,2);

\draw (O)--(A)--(B)--cycle;

\tkzLabelSegment[below=2pt](O,A){\textit{adjacent}}
\tkzLabelSegment[right=2pt](A,B){\textit{opposite}}
\tkzLabelSegment[above left=2pt](O,B){\textit{hypotenuse}}

\tkzMarkRightAngle[fill=none,size=0.3,opacity=.4](O,A,B)% square angle here
\tkzMarkAngle[fill=none,size=0.5,opacity=.4](A,O,B)
\tkzLabelAngle[pos = 0.8](A,O,B){\(\theta\)}
\end{tikzpicture}

\end{document}

答案2

我有个想法,因为这些方程很重要,所以你会希望给它们编号。说实话,它看起来很丑,有点混乱,但它表明你也可以用它来解决它minipage

\documentclass{article}
\usepackage{amsmath}
%%
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
%%
\begin{document}
\noindent
Clearly
\begin{equation}
  \tan\theta=\frac{\sin\theta}{\cos\theta}
\end{equation}
where
\newline
\begin{minipage}[c]{0.5\linewidth}
  \begin{align}
    \sin \theta &= \dfrac{\text{opposite}}{\text{hypotenuse}}\\
    \cos \theta &= \dfrac{\text{adjacent}}{\text{hypotenuse}}\\
    \tan \theta &= \dfrac{\text{opposite}}{\text{adjacent}}
  \end{align}
\end{minipage}\hfil
\begin{minipage}[c]{0.3\linewidth}
  \begin{tikzpicture}
    \coordinate (O) at (0,0);
    \coordinate (A) at (3,0);
    \coordinate (B) at (3,2);
    % 
    \draw (O)--(A)--(B)--cycle;
    % 
    \tkzLabelSegment[below=2pt](O,A){\textit{adjacent}}
    \tkzLabelSegment[right=2pt](A,B){\textit{opposite}}
    \tkzLabelSegment[above left=2pt](O,B){\textit{hypotenuse}}
    % 
    \tkzMarkRightAngle[fill=none,size=0.3,opacity=.4](O,A,B)% square angle here
    \tkzMarkAngle[fill=none,size=0.5,opacity=.4](A,O,B)
    \tkzLabelAngle[pos = 0.8](A,O,B){\(\theta\)}
  \end{tikzpicture}
\end{minipage}
\newline
Text

\end{document}

在此处输入图片描述

答案3

图片的边界框太大,因为它延伸到“相邻”一词下方太远。我发现通过 1ex 进行校正似乎足够了(也许 TikZ 有更好的方法,当然修复基线是不行的,因为图片的尺寸不会改变。

您可以使用alignedadjustbox在其旁边包含图片,并使用上述校正并垂直居中。

\documentclass{article}
\usepackage{mathtools}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{adjustbox}

\usepackage{lipsum} % just for the example

\begin{document}

\lipsum*[2]
\[ % display the thing
\begin{aligned}
\sin \theta &= \dfrac{\text{opposite}}{\text{hypotenuse}} \\[1ex]
\cos \theta &= \dfrac{\text{adjacent}}{\text{hypotenuse}} \\[1ex]
\tan \theta &= \dfrac{\text{opposite}}{\text{adjacent}}
\end{aligned}
\qquad\qquad
\begin{adjustbox}{valign=c,trim=0 1ex 0 0}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\coordinate (A) at (3,0);
\coordinate (B) at (3,2);
\draw (O)--(A)--(B)--cycle;
\tkzLabelSegment[below=2pt](O,A){\textit{adjacent}}
\tkzLabelSegment[right=2pt](A,B){\textit{opposite}}
\tkzLabelSegment[above left=2pt](O,B){\textit{hypotenuse}}
\tkzMarkRightAngle[fill=none,size=0.3,opacity=.4](O,A,B)% square angle here
\tkzMarkAngle[fill=none,size=0.5,opacity=.4](A,O,B)
\tkzLabelAngle[pos = 0.8](A,O,B){\(\theta\)}
\end{tikzpicture}
\end{adjustbox}
\]

\end{document}

在此处输入图片描述

相关内容