Center align outputs in ipython notebook

旧巷老猫 提交于 2020-01-04 02:15:07

问题


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.


回答1:


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

Example

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.

In my case, I added the following lines to the CSS:

div.output_area {
    width: 30%;
}

resulting in the following output:



来源:https://stackoverflow.com/questions/38848219/center-align-outputs-in-ipython-notebook

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