How to Align Text in the Jupyter Notebook
To display how to alight text left, center and right
It is very convenient to use Markdown in the Jupyter notebook, while the text alignment of Markdown is left. Whereas, we can run HTML directly in the Markdown cells in the Jupyter notebook. I have a post on “Different Methods to Run HTML Inside the Jupyter Notebook” if you are not familiar about running HTML in the Jupyter notebook. In this post, we will see how to align text in the Jupyter notebook using examples headers
and paragraph
.
1. Header Alignment
We can align text using the HTML style attribute
in the Jupyter notebook
(1) Align left
<h1 style='text-align: left;'> A left aligned header 1 </h1>
The output looks as follows:
(2) Align center
<h2 style='text-align: right;'> A right aligned header 2 </h2>
The result goes as follows:
(3) Align right
<h3 style=’text-align: right;’> A right aligned header 3 </h3>
The outcome looks as:
Besides, we can also use div
tags. For example, let’s align header 3 center.