IPython笔记本将代码单元放入列中 [英] IPython notebook put code cells into columns

查看:118
本文介绍了IPython笔记本将代码单元放入列中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以列格式组织代码单元格?我想在IPython笔记本中编写派生函数,但是每个辅助方程似乎都破坏了我的派生。我正在使用一个模块来编写我的方程式,并将我的方程式输入到代码单元格中,因此我无法在减价内使用简单的HTML对齐方式。任何帮助非常感谢!



我的意思是,我希望我的代码单元格看起来像这样...





<而不是常规的垂直对齐的单元格...

解决方案

经过一些挖掘,我发现了一个hackish的解决方案,笔记本电脑的CSS。
这适用于IPython 2.0,但可能不适用于1.x!
要测试此方法,只需在笔记本中执行以下操作即可:

  %% HTML 
< style>
div#notebook-container.container {
/ *这充当单元格之间的间隔,即在边界之外* /
margin:2px 0px 2px 0px;
list-style:none;
padding:0;
保证金:0;
-ms-box-orient:horizo​​ntal;
display:-webkit-box;
display:-moz-box;
显示:-ms-flexbox;
display:-moz-flex;
display:-webkit-flex;
display:flex;
justify-content:space-around;
-webkit-flex-wrap:wrap;
flex-wrap:wrap;
-webkit-flex-direction:row;
flex-direction:row;
}
div.cell {
width:550px
}
< / style>

通过这种方式,您可以获得灵活的盒子布局,因此可以将两个单元并排放置。
由于我不是CSS专家,这肯定是一个相当薄弱的黑客,但它似乎工作合理。要更认真地使用这种方法,您可以创建一个新的配置文件并将css添加到您的custom.css中。

我找到了一些灵​​感

结果看起来像这样

img src =https://i.stack.imgur.com/SSfrh.pngalt =在这里输入图片描述>


Is there a way to organize the code cells in a column format? I would like to write derivations in IPython notebook, but every auxiliary equation seems to break up my derivation. I'm using a module to write my equations and entering my equations into code cells, so I can't use simple html alignment inside markdown. Any help is greatly appreciated!

An example of what I mean is that I would like my code cells to look like this...

Instead of the regular vertically aligned cells...

解决方案

After some digging around, I found a hackish solution by modifying the notebook css. This works with IPython 2.0, but may not work with 1.x! To test this approach simply execute the following in your notebook

%%HTML
<style> 
div#notebook-container.container {
  /* This acts as a spacer between cells, that is outside the border */
  margin: 2px 0px 2px 0px;
  list-style: none;
  padding: 0;
  margin: 0;
  -ms-box-orient: horizontal;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -moz-flex;
  display: -webkit-flex;
  display: flex;  
  justify-content: space-around;
  -webkit-flex-wrap: wrap;
  flex-wrap: wrap;
  -webkit-flex-direction: row;
  flex-direction: row;
}
div.cell {
width:550px
}
  </style>

This way you get a flexible box layout and thus you can have two cell floating side by side. As I'm not an CSS expert this is for sure a rather weak hack, but it seems to work reasonable. To use this approach more seriously you might create a new profile and add the css to your custom.css.
I found some inspiration
here.

The result looks like this

这篇关于IPython笔记本将代码单元放入列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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