Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center align outputs in ipython notebook

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.

like image 914
Abhijay Ghildyal Avatar asked Dec 25 '22 03:12

Abhijay Ghildyal


1 Answers

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 Center align output Jupyter notebook

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:

enter image description here

like image 50
zarak Avatar answered Dec 26 '22 18:12

zarak