如何在 Markdown 中右对齐和对齐对齐?

How to right-align and justify-align in Markdown?

Markdown 文本始终左对齐。有没有办法在 Markdown 中进行右对齐和对齐?

准确地说,我在 Jupyter Notebook (IPython) 中使用 Markdown。

无法在 native markdown 中对齐文本。但是,您可以使用内联 HTML 标签对齐文本。

<div style="text-align: right"> your-text-here </div>

为了证明,将上面的right替换为justify

如果你想在表格中右对齐,你可以试试:

| Option | Description |
| ------:| -----------:|
| data   | path to data files to supply the data that will be passed into templates. |
| engine | engine to be used for processing templates. Handlebars is the default. |
| ext    | extension to be used for dest files. |

https://learn.getgrav.org/content/markdown#right-aligned-text

如果你想在 Jupyter Notebook 中使用对齐对齐,请使用以下语法:

<p style='text-align: justify;'> Your Text </p>

右对齐:

<p style='text-align: right;'> Your Text </p>

如果你想使用,我发现当你在MacOs上使用MacDown时,你可以在文档的开头<div style="text-align: justify">来对齐所有文本并保留所有code 格式化。也许它也适用于其他编辑器,供您尝试;)

特定于您对 Jupyter Notebook 的使用:指定 table 列对齐的功能应该 return 在未来的版本中。 (当前版本在任何地方都默认为 right-aligned。)

来自PR #4130

Allow markdown tables to specify their alignment with the :--, :--:, --: syntax while still allowing --- to default to right alignment.

This reverts a previous change (part of #2534) that stripped the alignment information from the rendered HTML coming out of the marked renderer. To be clear this does not change the right alignment default but does bring back support for overriding this alignment per column by using the gfm table alignment syntax.

...

如此处所述,Markdown 不支持右对齐文本或块。但是 HTML 结果通过级联样式表 (CSS) 做到了。

在我的 Jekyll 博客上使用的语法也适用于 markdown。 "terminate" 一个块在末尾使用两个空格或两次换行。

当然你也可以添加 css-class 用 {: .right } 代替 {: style="text-align: right" }.

右边的文字

{: style="text-align: right" }
This text is on the right

文本块

{: style="text-align: justify" }
This text is a block

在通用 Markdown 文档中,使用:

<style>body {text-align: right}</style>

<style>body {text-align: justify}</style>

不过似乎不适用于 Jupyter。

我用过

<p align='right'>Farhan Khan</p>

它在 Google Colaboratory 上对我有用。有趣的是,它在其他任何地方都不起作用?

How to right-align text 和 hyperlinks 已经回答并标记为正确,但是如果你要引用一些东西 within Jupyter Notebook in您的 right-aligned 文本,您需要使用 Eradash's answer 的修改版本。修改包括 删除除法右括号 > 在您的 linked 文本之前添加一个新的空行。因此,如果您希望 link 您的标题到 Table 的目录,您可能还希望 right-aligned link 到 'Table of contents'相同的块以获得更好的笔记本美学和导航。

假设你有 Table 的内容,你的单元格标题有 link,在 markdown 中看起来像这样:

<a id='Contents'></a>
### Table of Contents
* [Project description](#Project)
* [Load Data](#Load)

稍后,您有一个包含用于某些操作的 left-aligned header 的单元格,并且您的 right-aligned go-to link:

<a id='Load'></a>
#### Loading data
<div style="text-align: right"
     
[Go to table](#Contents)

这将为您提供 left-aligned 右对齐 go-to-link 的标题。您的下一个单元格紧随其后,无需任何对齐方式修改:

(我很想知道为什么会这样工作,因为这个解决方案看起来更像是黑客。)

PS:您可以在新行后添加结束括号>甚至end-tag </div>您的 right-aligned linked 文本,但它只会在输出中添加另一行以及突出显示的 space,这当然会破坏美学目的: