单元格的ipython笔记本背景颜色 [英] ipython notebook background colour of a cell

查看:131
本文介绍了单元格的ipython笔记本背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改iPython Notebook中特定单元格的背景颜色?例如,我正在编写手册,并且希望在灰色文本框中添加一些终端命令,如

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.

推荐答案

基本上,您可以在markdown单元内的预格式化代码块中编写终端命令. 对于单行(内联)代码,您可以使用双坟墓(``) echo 1(``回声1'').就像在Stackoverflow上一样.

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
为* .jpg中的我做
显示$ i
完成
```
在这里, bash 指定语法颜色.像
这样在IPython 2.x中呈现
如果要使用其他背景样式,则可以使用CSS样式.例如.在代码单元格中添加以下几行,或者将其添加到您的custom.css中(或稍作修改).

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

这篇关于单元格的ipython笔记本背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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