How to Align Text in the Jupyter Notebook

To display the text alignment methods in the Jupyter notebook

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.

<div style="text-align: center"> <h1>A center alighed header 1</h1></div>

The result looks as:

2. Paragraph Alignment

Similarly, we can align a paragraph left, center and right using HTML style attribute as follows:

<p style=’text-align: left;’> A paragraph is left Aligned </p>
<p style='text-align: center;'> A paragraph is center Aligned </p>
<p style='text-align: right;'> A paragraph is center Aligned </p>

The results look as follows:

3. Online Course

If you are interested in learning Jupyter notebook in details, you are welcome to enroll one of my course Practical Jupyter Notebook from Beginner to Expert.

Bookmark
ClosePlease login
0 - 0

Thank You For Your Vote!

Sorry You have Already Voted!

Please follow and like me:

Leave a Reply

Your email address will not be published. Required fields are marked *