admin管理员组文章数量:1125797
I created a text/code .ipynb file in colab. Then to turn it into HTML I opened the file with Jupyter Notebook. After that, I realized that i need to center images that i put in the file. But all tries failed. How can i do that?
The format of the image is:
![1new.png](data:image/png;base64,iVBORw0K...u0AAAAASUVORK5CYII=)
This is my image needs to be centered:
I created a text/code .ipynb file in colab. Then to turn it into HTML I opened the file with Jupyter Notebook. After that, I realized that i need to center images that i put in the file. But all tries failed. How can i do that?
The format of the image is:
![1new.png](data:image/png;base64,iVBORw0K...u0AAAAASUVORK5CYII=)
This is my image needs to be centered:
Share Improve this question asked Jan 9 at 3:14 Ege TunçEge Tunç 214 bronze badges 01 Answer
Reset to default 0With text you can just wrap it with <center>
tags, see here, here, or here.
However, it seems that unlike with text, you cannot wrap markdown-specified images in <center>
tags. If you do, they don't render.
Because you can use HTML in Jupyter markdown cells you can, though, just wrap the HTML reference to an image file, with <center>
, as covered here. Yet, here in your case, you have Base64 content that you are using and not an image file. So you need to additionally combine the approach spelled out in 'How to display Base64 images in HTML' to address your case.
So for you example that comes together as putting the following in a markdown cell in your Jupyter:
<center><img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" /></center>
You'll see a centered red dot.
You should be able to replace the base64 code there with your own content. (Note that is a long line so you'll need to scroll to see/select all of it.)
(The simple Base64 image code used in this demo comes from here.)
That is as opposed to the following self-contained, complete example, based on your provided code:
![a_dot](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==)
That just gives a red dot on the left side. Not centered.
Even finer control of elements is possible with the ability to use HTML in Jupyter cells, too. See here to get an idea.
Additional related resources
- A thorough answer to 'How do I center an image in the README.md file on GitHub?'
- 'Jupyter Notebook position embedded image in markdown'
本文标签: How to center an image in Jupyter NotebookStack Overflow
版权声明:本文标题:How to center an image in Jupyter Notebook? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736675054a1947136.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论