Manim:如何在其中使用Tex创建带有表格和仅在第一行中有网格的表格?

huangapple go评论67阅读模式
英文:

Manim: How to create a table with Tex in it? and grid only in first line?

问题

以下是翻译好的部分:

第一个问题的代码部分:

我正在为我的毕业论文制作动画但无法插入实数符号以下是代码
```python
from manim import *

class SimpleAnimation(Scene):
    def construct(self):
        table = Table([
            ["oi", "test1"],
            ["test2", "test3"],
            ["test4", "test5"]
            ])
        self.play(Write(table))

第二个问题的代码部分:

另一个问题如何创建一个只在第一行显示网格的表格就像这样但是使用LaTeX
```python
class SimpleAnimation(Scene):
    def construct(self):
        tex = Tex(r"""\begin{tabular}{l l}
            $\mathbb{N}$ & $\ \mathbb{R}$\\
            \hline
            1 & \ 0.156739345...\\
            2 & \ 0.823478901...\\
            3 & \ 0.465809217...\\
            4 & \ 0.156439345...\\
            5 & \ 0.823478903...\\
            $\vdots$ & $\ \vdots$\\
        \end{tabular}""",
                font_size=70)
        self.play(Write(tex))

请注意,您提到的问题中,您尝试使用Tex类来创建表格,但Tex类通常用于渲染LaTeX公式,而不是表格。如果您想要创建表格,可以使用Table类(如第一个问题的代码所示),而不是Tex类。

英文:

I'm making an animation for my Final Paper, and I couldn't insert the symbol of the real numbers, here is the code:

from manim import *

class SimpleAnimation(Scene):
    def construct(self):
        table = Table([
            ["oi", "test1"],
            ["test2", "test3"],
            ["test4", "test5"]
            ])
        self.play(Write(table))

And other question: how do I do a table with the grid only in the first line? like this, but in latex:

class SimpleAnimation(Scene):
    def construct(self):
        tex = Tex(r"""\begin{tabular}{l l}
            $\mathbb{N}$ & $\ \mathbb{R}$\\
            \hline
            1 & \ 0,156739345...\\
            2 & \ 0,823478901...\\
            3 & \ 0,465809217...\\
            4 & \ 0,156439345...\\
            5 & \ 0,823478903...\\
            $\vdots$ & $\ \vdots$\\
        \end{tabular}""",
                font_size=70)
        self.play(Write(tex))

I know that I'm supposed to input a str class, and I'm inserting a Tex class

答案1

得分: 1

你知道Manim中不只有一种Table对象吗?MathTable()会将每个项目呈现为LaTeX字符串。在MobjectTable()中,您可以将任何Manim对象放置在任何位置:

class SimpleAnimation(Scene):
    def construct(self):
        table = MobjectTable([
            [Square(side_length=0.25), Text("test1")],
            [MathTex(r"\pi^3"), Tex("test3")],
            [Tex("test4"), Tex(r"test $5^2$")]
            ])
        self.add(table)

对于您的第二个问题:所以通过“grid”您的意思是您只想要标题后面的一条水平线,没有垂直线吗?

class SimpleAnimation3(Scene):
    def construct(self):
        values = [
            [0.156739345],
            [0.823478901],
            [0.465809217],
            [0.156439345],
            [0.823478903],
        ]
        table = DecimalTable(
            values,
            row_labels=[MathTex(rf"{i}") for i in range(1, 6)],
            col_labels=[MathTex(r"\mathbb{R}")],
            top_left_entry=MathTex(r"\mathbb{N}"),
            element_to_mobject_config={"num_decimal_places": 9, "show_ellipsis": True},
            v_buff=0.3,
        )
        table.remove(*table.get_vertical_lines())
        table.remove(*table.get_horizontal_lines()[1:])
        self.add(table)

欲获取更多和更好的帮助,请访问Discord服务器我在哪里可以找到更多学习Manim的资源?

英文:

Are you aware that there is more than just one type of Table object in Manim? The MathTable() renders every item as a LaTeX string. In the MobjectTable() you can place any Manim object at any position:

class SimpleAnimation(Scene):
    def construct(self):
        table = MobjectTable([
            [Square(side_length=0.25), Text("test1")],
            [MathTex(r"\pi^3"), Tex("test3")],
            [Tex("test4"), Tex(r"test $5^2$")]
            ])
        self.add(table)

Manim:如何在其中使用Tex创建带有表格和仅在第一行中有网格的表格?

For your second question: so with "grid" you mean that you only want one horizontal line after the heading and no vertical lines?

class SimpleAnimation3(Scene):
    def construct(self):
        values = [
            [0.156739345],
            [0.823478901],
            [0.465809217],
            [0.156439345],
            [0.823478903],
        ]
        table = DecimalTable(
            values,
            row_labels = [MathTex(rf"{i}") for i in range(1,6)],
            col_labels = [MathTex(r"\mathbb{R}")],
            top_left_entry = MathTex(r"\mathbb{N}"),
            element_to_mobject_config={"num_decimal_places": 9, "show_ellipsis":True},
            v_buff=0.3,
        )
        table.remove(*table.get_vertical_lines())
        table.remove(*table.get_horizontal_lines()[1:])
        self.add(table)

Manim:如何在其中使用Tex创建带有表格和仅在第一行中有网格的表格?

For more and better help come to the Discord server Where can I find more resources for learning Manim?

huangapple
  • 本文由 发表于 2023年7月27日 23:34:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76781353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定