[英]Manim Display Latex Table
有沒有辦法使用manim
顯示和動畫 latex 表?
例如
\begin{table}[]
\centering
\begin{tabular}{lllll}
& & \multicolumn{2}{l}{End} & \\
Top & & Bottom & Bottom & \\
& Top & 40 & 160 & 200 \\
& Bottom & 640 & 160 & 800 \\
& & 200 & 800 & 1000
\end{tabular}
\end{table}
你會怎么想manim
呢?
from manimlib import *
import numpy as np
class TableManim(Scene):
def construct(self):
...
如果你想直接用 LaTeX 做它會是這樣的:
class Table1(Scene):
def construct(self):
table = r"""
\begin{table}[]
\centering
\begin{tabular}{|l|l|l|l|l|}\hline
& & \multicolumn{2}{l}{End} & \\\hline
Top & & Bottom & Bottom & \\
& Top & 40 & 160 & 200 \\
& Bottom & 640 & 160 & 800 \\
& & 200 & 800 & 1000 \\\hline
\end{tabular}
\end{table}
"""
tex_table = TexText(table)
self.play(Write(tex_table))
但是,如果你想用 Manim 制作一張桌子,它會有點復雜,它會是這樣的(你可以轉換為 function 以防你需要它)
class Table2(Scene):
def construct(self):
table = VGroup(*[
VGroup(*[
Text(f"{t}")
for t in row
]).arrange(DOWN,aligned_edge=LEFT)
for row in [
["Top"],
["Top","Bottom"],
["Bottom",40,640,200],
["Bottom",160,160,800],
[200,800,1000],
]],
)
table.scale(0.8)
BUFF = 0.5
rectangles = VGroup(*[
Rectangle(
width=mob.get_width()+BUFF,
height=max(*[t.get_height() for t in table])+BUFF,
).move_to(mob)
for mob in table
])
for t,r,align_direction in zip(table, rectangles, [UP,None,None,None,DOWN]):
if align_direction is not None:
t.align_to(r,align_direction)
t.shift(-align_direction*BUFF/2)
table_group = VGroup(*[
VGroup(t,r)
for t,r in zip(table,rectangles)
])
table_group.arrange(RIGHT,buff=0)
self.add(table_group)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.