简体   繁体   English

Ipython笔记本在Ipython.Display模块中对齐Latex方程式

[英]Ipython notebook align Latex equations in Ipython.Display module

I am using ipython notebook to write latex equations with the following modules 我正在使用ipython notebook来编写具有以下模块的乳胶方程式

from IPython.display import display, Math, Latex

a simple example code might look like: 一个简单的示例代码可能如下所示:

display(Math('a = \\frac{1}{2}'))
display(Math('b = \\frac{1}{3}'))
display(Math('c = \\frac{1}{4}'))

Which would output: 哪个会输出:

a = 1/2
b = 1/3
c = 1/4

in a pretty print format. 以漂亮的打印格式。 Is there a way that I can somehow align this in columns like: 有没有办法,我可以以某种方式在列中对齐,如:

a = 1/2      b = 1/3      c = 1/4

? I know that the markup allows HTML usage, but this markup is entered into the input for a code-based cell. 我知道标记允许HTML使用,但是这个标记被输入到基于代码的单元格的输入中。 Any help/advice is greatly appreciated!! 任何帮助/建议非常感谢!!

I'm not sure how familiar you are with LaTeX, but the notebook does allow you to use things like \\begin{align} , allowing you to organize things into columns by separating them with & symbols. 我不确定你对LaTeX有多熟悉,但是笔记本允许你使用像\\begin{align}这样的东西,允许你通过用&符号分隔它们来组织列。 For example, this works if you enter it into a Markdown cell: 例如,如果您将其输入Markdown单元格,则此方法有效:

$$
\begin{align}
a = \frac{1}{2} && b = \frac{1}{3} && c = \frac{1}{4} \\
a && b && c
\end{align}
$$

This also works using display(Math()) , eg: 这也可以使用display(Math()) ,例如:

display(Math(
r"""
\begin{align}
a = \frac{1}{2} && b = \frac{1}{3} && c = \frac{1}{4} \\
a && b && c \\
1 && 2 && 3
\end{align}
"""))

Giving you this output: 给你这个输出:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM