82

md $S$: a set of shops $I$: a set of items M wants to get

I'd like to make a new line between this two sentences. We usually put " (space)" after the first sentence before a new line, but it doesn't work in Jupyter.

How can I do this? Should I put "enter" twice after the first sentence?

James Draper
  • 5,110
  • 5
  • 40
  • 59
hrsma2i
  • 4,045
  • 6
  • 15
  • 24

5 Answers5

151

Just add <br> where you would like to make the new line.

$S$: a set of shops
<br>
$I$: a set of items M wants to get

Because jupyter notebook markdown cell is a superset of HTML.
http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Working%20With%20Markdown%20Cells.html

Note that newlines using <br> does not persist when exporting or saving the notebook to a pdf (using "Download as > PDF via LaTeX"). It is probably treating each <br> as a space.

Steven C. Howell
  • 16,902
  • 15
  • 72
  • 97
Woooody Amadeus
  • 1,664
  • 1
  • 10
  • 7
  • 4
    [Mica](//stackoverflow.com/users/2821804) has pointed out a pertinent point [here](//stackoverflow.com/questions/41906199/how-to-make-a-new-line-in-a-jupyter-markdown-cell/49225385#comment85454414_49225385), but does not have enough reputation yet to comment anywhere, so I'll repost it here - *"Unfortunately the `
    ` trick doesn't work when you're exporting to pdf via latex. If I remember correctly, `
    `s get treated as spaces in that case."*.
    – robinCTS Mar 12 '18 at 02:00
59

"We usually put ' (space)' after the first sentence before a new line, but it doesn't work in Jupyter."

That inspired me to try using two spaces instead of just one - and it worked!!

(Of course, that functionality could possibly have been introduced between when the question was asked in January 2017, and when my answer was posted in March 2018.)

robinCTS
  • 5,746
  • 14
  • 30
  • 37
violet
  • 717
  • 1
  • 6
  • 11
  • 5
    unfortunately the "
    " trick doesn't work when you're exporting to pdf via latex. if I remember correctly, "
    "s get treated as spaces in that case. I would comment directly on that answer but I don't have enough reputation.
    – violet Mar 11 '18 at 21:40
  • 1
    after I wrote this answer I saw that people already put this answer as comments on the question.... but I never saw those until AFTER I already figured it out.. so putting the answer as a comment on the question isn't very helpful! I hope this answer saves people from wasting time like I did.. – violet Mar 11 '18 at 21:45
  • Even if you *had* seen the comment before posting, it is still acceptable to re-post a comment as an answer. Just make sure that the OP of the comment has had a chance to do so first. (A year is plenty of time!) If you do do so, try to make the answer as substantial as possible. Yeah, as you pointed out, answers in comments are easy to miss. Comments are also ephemeral second-class citizens, commonly deleted. That is why there is a rulez that answers should not be posted as comments. Oh, and kudos for *not* posting your first comment as an answer, which a lot of newbies decide is OK to do! – robinCTS Mar 12 '18 at 01:46
  • 1
    I've reposted your first comment directly on the appropriate answer for you. Hopefully, it won't be another four years until you get enough reputation to "spam" comments anywhere ;) – robinCTS Mar 12 '18 at 02:11
  • 2
    @robinCTS "Oh, and kudos for not posting your first comment as an answer, which a lot of newbies decide is OK to do!" thanks! although I have low reputation, I think I have a pretty good understanding of how to properly use a question-answer system. it drives me nuts to see an answer that asks clarification/doesn't answer the question (which should be a comment) or an answer written as a comment. my university classmates make the rookie mistakes too often in piazza, so I learn about mistakes to avoid. "I've reposted your first comment directly on the appropriate answer for you." thanks again! – violet Mar 12 '18 at 13:57
  • Thanks, the line break still persistent in the PDF after choosing Download as `PDF via LaTeX (.pdf)` – K_inverse Dec 13 '18 at 07:53
  • Helen, could you be more specific? is the cell markdown? are you using Jupyter Notebook or Jupyter Lab? which version? are you trying to export as pdf? – violet Feb 21 '19 at 17:42
  • I took a look again and realized I'd made a mistake. It does work! – Helen May 02 '19 at 09:43
  • It doesn't work for me. – Parsa Noori Jan 23 '22 at 20:40
11

Just use backslash \ at the end of the line atop.

The problem with double space is that it adds a white-space, so you have two different paragraphs.

I like sometimes having a new line in the same paragraph, for readability, but without a white-space between lines.

Backslash allows it, even if I'd prefer to have it the default option for "enter" in jupyter. If anyone has an idea of how to do this (by editing the right file in site-packages/notebook/static/notebook/js/ maybe?) I'm interested.

NoGa
  • 111
  • 1
  • 2
3

The double space generally works well. However, sometimes the lacking newline in the PDF still occurs to me when using four pound sign sub titles #### in Jupyter Notebook, as the next paragraph is put into the subtitle as a single paragraph. No amount of double spaces and returns fixed this, until I created a notebook copy 'v. PDF' and started using a single backslash '\' which also indents the next paragraph nicely:

#### 1.1 My Subtitle  \

1.1 My Subtitle
    Next paragraph text.

An alternative to this, is to upgrade the level of your four # titles to three # titles, etc. up the title chain, which will remove the next paragraph indent and format the indent of the title itself (#### My Subtitle ---> ### My Subtitle).

### My Subtitle


1.1 My Subtitle

Next paragraph text.
DataCodeFu
  • 31
  • 3
0

There is a simple way to place text which will not be modified in Jupyter Notebook (markdown). You only use triple quotes with the reverse accent sign and end with the same quotes three times.
Update: Now, we can your single quote as well, i.e., `your text here` = your text here will do the same job as triple quotes ```your text here``` = your text here

ecram
  • 31
  • 7