Ipython笔记本对齐Ipython.Display模块中的乳胶方程 [英] Ipython notebook align Latex equations in Ipython.Display module

查看:484
本文介绍了Ipython笔记本对齐Ipython.Display模块中的乳胶方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ipython notebook用以下模块编写乳胶方程。

 来自IPython.display import display,Math,Latex 

一个简单的示例代码可能如下所示:

 显示(Math('a = \\frac {1} {2}'))
display(Math('b = \\frac {1 } {b}})



这将输出:

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

是否有一种方法,我可以在某种程度上在列中对齐这样:

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

?我知道标记允许HTML使用,但是这个标记被输入到基于代码的单元格的输入。非常感谢任何帮助/建议!

解决方案

我不知道你是如何熟悉LaTeX,允许你使用 \begin {align} 的东西,让你可以用& 符号。例如,如果你输入到一个Markdown单元格,这将工作:

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

显示(Math()),例如:

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



>


I am using ipython notebook to write latex equations with the following modules

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. 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. For example, this works if you enter it into a Markdown cell:

$$
\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()), e.g.:

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:

这篇关于Ipython笔记本对齐Ipython.Display模块中的乳胶方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆