IPython notebook put code cells into columns

烂漫一生 提交于 2020-01-06 14:41:45

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/23370670/ipython-notebook-put-code-cells-into-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!