ipython notebook background colour of a cell

元气小坏坏 提交于 2020-01-02 04:47:28

问题


How may I change the background colour of a particular cell in iPython Notebook? For example, I'm writing a manual and I'd like to add some Terminal commands in a grey text box as in http://ipython.org/ipython-doc/1/interactive/nbconvert.html.


回答1:


Basically, you could write the terminal commands in preformatted code blocks within markdown cells. For single line (inline) code you can use double graves (``) like echo 1 (``echo 1``). This works exactly like here on Stackoverflow.

Longer code snippets (with syntax highlighting) may be better placed in fenced code blocks like

```bash
for i in *.jpg; do
display $i
done
```
here, bash specifies the syntax color. This renders in IPython 2.x like


If you want a different background style, you can use CSS styles. E.g. add the following lines in a code cell, or better (slightly adapted) to your custom.css.
%%html
<style type="text/css">
.rendered_html code  {
   background-color:#E8E8E8;
   padding: 3px;
};
</style>

With this the preformatted code looks like



来源:https://stackoverflow.com/questions/28034783/ipython-notebook-background-colour-of-a-cell

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