中心对齐ipython笔记本中的输出 [英] Center align outputs in ipython notebook
问题描述
我想在我的 ipython笔记本
中对齐输出(包括文字和图表)。有没有一种方法可以在同一个笔记本中添加样式?代码或屏幕截图示例会有很大帮助。
I want to center align the outputs (which includes text and plots) in my ipython notebook
. Is there a way in which I can add styling in the same notebook for the same? Code or screenshot examples would greatly help.
推荐答案
尝试在代码单元中运行它以覆盖输出单元格的默认CSS :
Try running this in a code-cell to override the default CSS for an output cell:
from IPython.display import display, HTML
CSS = """
.output {
align-items: center;
}
"""
HTML('<style>{}</style>'.format(CSS))
示例
你可以在这里看到表格的右侧有点被切断,打印的字符串包裹到下一行。这可以通过稍微使用CSS来修复,但你必须将它自定义为你自己的输出。
You can see here that the right side of the table is cut-off a bit and the string that is printed wraps to the next line. This can be fixed by playing around with the CSS a bit, but you'll have to customize it to your own output.
在我的情况下,我添加了以下几行到CSS:
In my case, I added the following lines to the CSS:
div.output_area {
width: 30%;
}
产生以下输出:
这篇关于中心对齐ipython笔记本中的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!