Manim-在方程式中对齐项

问题描述 投票:-1回答:2

我有一个简单的Manim场景,可以解决等式2x-3 = -7。我想在每个步骤之间保持2x垂直对齐(因为等号已对齐)。能做到吗?

class BasicEquationsSimple(Scene):
    def construct(self):
        equation0 = TexMobject("2x - 3", "=", "{-7}")
        equation1 = TexMobject("2x", "=", "{-4}").next_to(equation0, DOWN)
        equation2 = TexMobject("x", "=", "{-2}").next_to(equation1, DOWN)

        eq0 = equation0.get_part_by_tex('=')
        eq1 = equation1.get_part_by_tex('=').align_to(eq0, LEFT)
        eq2 = equation2.get_part_by_tex('=').align_to(eq1, LEFT)

        equation0.get_part_by_tex('2x - 3').next_to(eq0, LEFT)
        equation0.get_part_by_tex('{-7}').next_to(eq0, RIGHT)
        equation1.get_part_by_tex('2x').next_to(eq1,LEFT)
        equation1.get_part_by_tex('{-4}').next_to(eq1, RIGHT)
        equation2.get_part_by_tex('x').next_to(eq2, LEFT)
        equation2.get_part_by_tex('{-2}').next_to(eq2, RIGHT)

        self.play(Write(equation0,run_time=3))
        self.play(Write(equation1))
        self.play(Write(equation2))

Manim scene

latex manim
2个回答
1
投票

这不是最好的解决方案,但是可以使用...

from manimlib.imports import *

class BasicEquationsSimple(Scene):
    def construct(self):
        equation0 = TexMobject("2x - 3", "=", "{-7}")
        equation1 = TexMobject("2x", "=", "{-4}").next_to(equation0, DOWN)
        equation2 = TexMobject("x", "=", "{-2}").next_to(equation1, DOWN)

        eq0 = equation0.get_part_by_tex('=')
        eq1 = equation1.get_part_by_tex('=').align_to(eq0, LEFT)
        eq2 = equation2.get_part_by_tex('=').align_to(eq1, LEFT)

        equation0.get_part_by_tex('2x - 3').next_to(eq0, LEFT)
        equation0.get_part_by_tex('{-7}').next_to(eq0, RIGHT)
        equation1.get_part_by_tex('2x').next_to(eq1, LEFT)
        equation1.get_part_by_tex('{-4}').next_to(eq1, RIGHT)
        equation2.get_part_by_tex('x').next_to(eq2, LEFT)
        equation2.get_part_by_tex('{-2}').next_to(eq2, RIGHT)

        equation1.get_part_by_tex('2x').move_to((1.15*LEFT)+(0.6*DOWN))
        equation2.get_part_by_tex('x').move_to((1.05*LEFT)+(1.2*DOWN))

        self.play(Write(equation0,run_time=3))
        self.play(Write(equation1))
        self.play(Write(equation2))

我希望这会有所帮助!


0
投票

这就是我最终要去的。

eq = 
[
[TexMobject("{2x}"),TexMobject("{-}"),TexMobject("{4}"),TexMobject("{=}"),TexMobject("{-3}")],
[TexMobject("{2x}"),"","",TexMobject("{=}"),TexMobject("{1}")],
[TexMobject("{x}"),"","",TexMobject("{=}"),TexMobject("{1 \\over 2}")]
]

lines = len(eq)
rails = len(eq[1])

for i in range(lines):
   for j in range(rails):
      if(eq[i][j] != ""):
         eq[i][j].move_to([j-0.5*rails+0.5,-i+0.5*lines-0.5,0])

© www.soinside.com 2019 - 2024. All rights reserved.