Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing the font size for just certain cells/one notebook in Jupyter notebook

I want to increase the font size and add boldness to my outputted text in Jupyter notebook. However, I just want to change the settings for that particular notebook or that particular cell. (both solutions are welcomed)

I see most threads showing how to configure the .css files which I'm assuming is a global change?

How to change font in ipython notebook

However I want cell by cell control or just that particular notebook.

As an example output of one my cells is the following:

Killing C.I.A. Informants, China Crippled U.S. Spying https://www.nytimes.com/2017/05/20/world/asia/china-cia-spies-espionage.html

I would like to make the first sentence(the title) bold.

Thank you.

EDIT: Trying to utilize the markdown method within this loop.

for i in today_links:
    if i[0] == '':
        del (i)
    else:
        Markdown('**{}**  \n{}'.format(i[0], i[1]))

today_links is a list of tuples

[('Killing C.I.A. Informants, China Crippled U.S. Spying',
  'https://www.nytimes.com/2017/05/20/world/asia/china-cia-spies-espionage.html'),
 ('How Rollbacks at Pruitt’s E.P.A. Are a Boon to Oil and Gas',
  'https://www.nytimes.com/2017/05/20/business/energy-environment/devon-energy.html'),

Not sure why it's not working within the loop.

Thank you.

like image 570
Moondra Avatar asked May 21 '17 14:05

Moondra


People also ask

How do I increase font size in Markdown cell Jupyter?

If you want to change the text cell font and font size you can type the following in a cell and hit shift+enter. Don't forget to refresh your browser for the change to take place. You can find all the font types here.

How do you select specific cells in a Jupyter Notebook?

There are commonly known keyboard shortcuts such as Ctrl + Shift + - to split the cell, Shift + M to merge multiple cells, and Shift + Down / Up to select the cells below or above the selected one.

How do you increase cell size in Jupyter Notebook?

One more way to change the width of the Jupyter Notebook cell is by using themes. This will increase the cell width to 100%. Also you will be able to change the font and the font size.

How do you Bolden text in Jupyter Notebook?

Use the following code to emphasize text: Bold text: __string__ or **string** Italic text: _string_ or *string*


1 Answers

I assume you are talking about output cells from your code... obviously you can use markdown cells and control the formatting for documentation cells.

Assuming two variables:

title = "Killing C.I.A. Informants, China Crippled U.S. Spying"
url = "https://www.nytimes.com/2017/05/20/world/asia/china-cia-spies-espionage.html"

For output cells from code you can do a similar thing and use the IPython.display.Markdown, e.g.:

from IPython.display import display, Markdown
Markdown('<strong>{}</strong><br/>{}'.format(title, url))
Output:

Killing C.I.A. Informants, China Crippled U.S. Spying
https://www.nytimes.com/2017/05/20/world/asia/china-cia-spies-espionage.html

If you want to do it in the middle of a loop you need to explicitly call display(), e.g.:

from IPython.display import display, Markdown
for i in today_links:
    display(Markdown('**{}**  \n{}'.format(i[0], i[1])))
Output:

Killing C.I.A. Informants, China Crippled U.S. Spying
https://www.nytimes.com/2017/05/20/world/asia/china-cia-spies-espionage.html

How Rollbacks at Pruitt’s E.P.A. Are a Boon to Oil and Gas
https://www.nytimes.com/2017/05/20/business/energy-environment/devon-energy.html

Alternatively you can use IPython.display.HTML:

from IPython.display import display, HTML
HTML('<strong>{}</strong><br/>{}'.format(title, url))
Output:

Killing C.I.A. Informants, China Crippled U.S. Spying
https://www.nytimes.com/2017/05/20/world/asia/china-cia-spies-espionage.html

You can also embed variables into a Markdown cell directly (note: there are 2 spaces at the end of **{{title}}** line to force a new line):

Markdown Cell
**{{title}}**  
{{url}}
Output:

Killing C.I.A. Informants, China Crippled U.S. Spying
https://www.nytimes.com/2017/05/20/world/asia/china-cia-spies-espionage.html

like image 195
AChampion Avatar answered Oct 22 '22 11:10

AChampion