You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Manim技术问询:实数符号插入与仅首行带网格的Tex表格制作

Manim 表格相关问题解决方案

问题1:在Table组件中插入实数符号$\mathbb{R}$

Manim的Table默认用Text渲染单元格,不支持LaTeX数学符号。只需指定element_to_mobject参数为MathTex(或Tex),即可让单元格识别LaTeX语法:

from manim import *

class SimpleAnimation(Scene):
    def construct(self):
        table = Table(
            [
                ["oi", r"\mathbb{R}"],
                ["test2", "test3"],
                ["test4", "test5"]
            ],
            element_to_mobject=MathTex
        )
        self.play(Write(table))

如果需要混合普通文本与数学符号,替换为element_to_mobject=Tex,单元格内容可写为r"示例 $\mathbb{R}$"。

问题2:制作仅第一行带网格的含Tex表格

提供两种实现方案:

方案1:基于Manim原生Table组件修改线条

创建Table后,隐藏不需要的网格线,仅保留第一行底部的横线:

from manim import *

class SimpleAnimation(Scene):
    def construct(self):
        table_content = [
            [r"\mathbb{N}", r"\mathbb{R}"],
            ["1", "0,156739345..."],
            ["2", "0,823478901..."],
            ["3", "0,465809217..."],
            ["4", "0,156439345..."],
            ["5", "0,823478903..."],
            [r"\vdots", r"\vdots"]
        ]
        
        table = Table(
            table_content,
            element_to_mobject=MathTex,
            include_outer_lines=False
        )
        
        # 隐藏所有竖线
        for line in table.get_vertical_lines():
            line.set_opacity(0)
        # 仅保留第一行底部的横线(索引为1的水平线)
        for idx, line in enumerate(table.get_horizontal_lines()):
            if idx != 1:
                line.set_opacity(0)
        
        self.play(Write(table))

方案2:用Tex直接渲染LaTeX tabular(样式更灵活)

沿用你熟悉的LaTeX语法,直接通过Tex渲染表格,完全自定义线条样式:

from manim import *

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))

内容的提问来源于stack exchange,提问作者Eric Mairene

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 20:50:55