我希望能够=
在三角形内画一个白色,能够旋转天平和方程,并将方程对称放置但又不要太靠近边缘。这对我来说相当困难。
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{center}
$2+2$ \hfill $4$
\begin{tikzpicture}
\draw[red!50!blue!70!white,ultra thick](-5.4,1) -- (5.4,1);
\fill[red!50!blue!70!white] (0,0.98) -- (-0.4,0) -- (0.4,0);
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
答案1
quick generating command
请参阅本篇文章末尾的更新。
barycentric
利用 提供的坐标系可以轻松找到三角形的中心TikZ
。
定义三角形的三个角节点并说
\node[color=white] at (barycentric cs:A=1,B=1,C=1) {=};
为了使用加权顶点(这里所有顶点都具有相同的权重,这对应于三角形的真实重心)。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{frame}
\begin{center}
$2+2$ \hfill $4$
\begin{tikzpicture}
\coordinate (A) at (0,0.98);
\coordinate (B) at (-0.4,0);
\coordinate (C) at (0.4,0);
\draw[red!50!blue!70!white,ultra thick](-5.4,1) -- (5.4,1);
\fill[red!50!blue!70!white] (A) -- (B) -- (C);
\node[color=white] at (barycentric cs:A=1,B=1,C=1) {=};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
更新
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{frame}
\begin{center}
\begin{tikzpicture}
\def\winkel{20}
\coordinate (A) at (0,0.98);
\coordinate (B) at (-0.4,0);
\coordinate (C) at (0.4,0);
\coordinate (rodleft) at (-5.4,1);
\coordinate (rodright) at (5.4,1);
\coordinate (balancetop) at (0,1);
\coordinate (rotatedleft) at ($(balancetop)-(\winkel:5)$);
\coordinate (rotatedright) at ($(balancetop)+(\winkel:5)$);
\draw[red!50!blue!70!white,ultra thick] (balancetop) -- (rotatedleft);
\draw[red!50!blue!70!white,ultra thick] (balancetop) -- (rotatedright);
\node[rotate=\winkel,above right] (LHS) at ($(rotatedleft) + (\winkel:1)$) {$2+2$};
\node[rotate=\winkel,above left] (RHS) at ($(rotatedright) - (\winkel:1)$) {$3$};
\fill[red!50!blue!70!white] (A) -- (B) -- (C);
\node[font=\large,color=white] at (barycentric cs:A=1,B=1,C=1) {$\neq$};
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
第二次更新
宏\equationbalance
检查参数#3
并#4
打印=
或\neq
,但是,仍然必须指定角度。我发现根据#3
或的值来计算角度没什么用#4
(从物理学的角度来看:如果刻度的两侧的值不相等,角度无论如何都不会是恒定的)
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
% First opt arg: angle
% 2nd arg: inward shift of the labels
% 3rd arg: left hand label
% 4th arg: right hand label
\newcommand{\equationbalance}[4][0]{%
\begin{tikzpicture}
\def\winkel{#1}
\coordinate (A) at (0,0.98);
\coordinate (B) at (-0.4,0);
\coordinate (C) at (0.4,0);
\coordinate (rodleft) at (-5.4,1);
\coordinate (rodright) at (5.4,1);
\coordinate (balancetop) at (0,1);
\coordinate (rotatedleft) at ($(balancetop)-(\winkel:5)$);
\coordinate (rotatedright) at ($(balancetop)+(\winkel:5)$);
\draw[red!50!blue!70!white,ultra thick] (balancetop) -- (rotatedleft);
\draw[red!50!blue!70!white,ultra thick] (balancetop) -- (rotatedright);
\node[rotate=\winkel,above right] (LHS) at ($(rotatedleft) + (\winkel:#2)$) {$#3$};
\node[rotate=\winkel,above left] (RHS) at ($(rotatedright) - (\winkel:#2)$) {$#4$};
\fill[red!50!blue!70!white] (A) -- (B) -- (C);
% Works for simple integer expressions only
\ifnum\numexpr#3=#4
\node[font=\large,color=white] at (barycentric cs:A=1,B=1,C=1) {$=$};
\else
\node[font=\large,color=white] at (barycentric cs:A=1,B=1,C=1) {$\neq$};
\fi
\end{tikzpicture}%
}
\begin{document}
\begin{frame}
\begin{center}
\equationbalance[10]{1.5}{2+2}{3}
\end{center}
\end{frame}
\end{document}
答案2
有了新的TABcline
选项tabstackengine
( 2018/03/05 (V2.10)
),这变成了一个很好的练习。支持宏\balanceindent
和\lever
分别控制从杠杆末端到杠杆到支点的文本缩进。杠杆厚度由\fboxrule
在主宏内部本地定义的控制。主程序是
\balance[fulcrum inset]{left terms}{right terms}
默认的支点插入是?
。如果设置为>
或<
,杠杆将向适当的方向倾斜。
这是MWE:
\documentclass{article}
\usepackage[TABcline]{tabstackengine}
\usepackage{graphicx}
\newcommand\Leqtriangle[1][=]{%
\stackengine{2pt}{\Ltriangle}{$\scriptstyle#1\mkern1mu$}{O}{c}{F}{F}{L}}
\newcommand\Ltriangle{\LARGE$\triangle$}
\newcommand\balanceindent{\kern10pt}
\newcommand\lever{\kern7em}
\newcommand\balance[3][?]{{%
\TABbinary\TABstackMath\setstackgap{S}{0pt}\fboxrule=1pt\relax%
\def\bangle{4}% TILT ANGLE
\def\bsign{}%
\ifx>#1\def\bsign{-}\else\ifx<#1\else\def\bangle{0}\fi\fi%
\rotatebox[origin=b]{\bsign\numexpr-\bangle}{%
\tabularShortstack{lcr}{\mathstrut\balanceindent#2 && #3\balanceindent\\%
\TABcline{1-3}\lever &%
\rotatebox[origin=t]{\bsign\numexpr\bangle}{\Leqtriangle[#1]} & \lever}}}}
\begin{document}
\balance[>]{2 + 2(4-3)}{6 - 6/2}
\balance[=]{2 + 2}{4}
\balance[<]{2 + 3}{7}
\balance{y}{42}
\end{document}