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

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

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

问题

以下是翻译好的部分:

第一个问题的代码部分:

  1. 我正在为我的毕业论文制作动画但无法插入实数符号以下是代码
  2. ```python
  3. from manim import *
  4. class SimpleAnimation(Scene):
  5. def construct(self):
  6. table = Table([
  7. ["oi", "test1"],
  8. ["test2", "test3"],
  9. ["test4", "test5"]
  10. ])
  11. self.play(Write(table))

第二个问题的代码部分:

  1. 另一个问题如何创建一个只在第一行显示网格的表格就像这样但是使用LaTeX
  2. ```python
  3. class SimpleAnimation(Scene):
  4. def construct(self):
  5. tex = Tex(r"""\begin{tabular}{l l}
  6. $\mathbb{N}$ & $\ \mathbb{R}$\\
  7. \hline
  8. 1 & \ 0.156739345...\\
  9. 2 & \ 0.823478901...\\
  10. 3 & \ 0.465809217...\\
  11. 4 & \ 0.156439345...\\
  12. 5 & \ 0.823478903...\\
  13. $\vdots$ & $\ \vdots$\\
  14. \end{tabular}""",
  15. font_size=70)
  16. 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:

  1. from manim import *
  2. class SimpleAnimation(Scene):
  3. def construct(self):
  4. table = Table([
  5. ["oi", "test1"],
  6. ["test2", "test3"],
  7. ["test4", "test5"]
  8. ])
  9. 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:

  1. class SimpleAnimation(Scene):
  2. def construct(self):
  3. tex = Tex(r"""\begin{tabular}{l l}
  4. $\mathbb{N}$ & $\ \mathbb{R}$\\
  5. \hline
  6. 1 & \ 0,156739345...\\
  7. 2 & \ 0,823478901...\\
  8. 3 & \ 0,465809217...\\
  9. 4 & \ 0,156439345...\\
  10. 5 & \ 0,823478903...\\
  11. $\vdots$ & $\ \vdots$\\
  12. \end{tabular}""",
  13. font_size=70)
  14. 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对象放置在任何位置:

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

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

  1. class SimpleAnimation3(Scene):
  2. def construct(self):
  3. values = [
  4. [0.156739345],
  5. [0.823478901],
  6. [0.465809217],
  7. [0.156439345],
  8. [0.823478903],
  9. ]
  10. table = DecimalTable(
  11. values,
  12. row_labels=[MathTex(rf"{i}") for i in range(1, 6)],
  13. col_labels=[MathTex(r"\mathbb{R}")],
  14. top_left_entry=MathTex(r"\mathbb{N}"),
  15. element_to_mobject_config={"num_decimal_places": 9, "show_ellipsis": True},
  16. v_buff=0.3,
  17. )
  18. table.remove(*table.get_vertical_lines())
  19. table.remove(*table.get_horizontal_lines()[1:])
  20. 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:

  1. class SimpleAnimation(Scene):
  2. def construct(self):
  3. table = MobjectTable([
  4. [Square(side_length=0.25), Text("test1")],
  5. [MathTex(r"\pi^3"), Tex("test3")],
  6. [Tex("test4"), Tex(r"test $5^2$")]
  7. ])
  8. 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?

  1. class SimpleAnimation3(Scene):
  2. def construct(self):
  3. values = [
  4. [0.156739345],
  5. [0.823478901],
  6. [0.465809217],
  7. [0.156439345],
  8. [0.823478903],
  9. ]
  10. table = DecimalTable(
  11. values,
  12. row_labels = [MathTex(rf"{i}") for i in range(1,6)],
  13. col_labels = [MathTex(r"\mathbb{R}")],
  14. top_left_entry = MathTex(r"\mathbb{N}"),
  15. element_to_mobject_config={"num_decimal_places": 9, "show_ellipsis":True},
  16. v_buff=0.3,
  17. )
  18. table.remove(*table.get_vertical_lines())
  19. table.remove(*table.get_horizontal_lines()[1:])
  20. 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:

确定