英文:
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)
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)
For more and better help come to the Discord server Where can I find more resources for learning Manim?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论