How to center a figure in the post?

In this post here, the figure appears on the left side. I tried to center the figure but I could not do so. Is there a way to center figures/text in a post?

• I'd suggest not doing any tricks to get the image centered. If you really really want this, file a request-for-enhancement in this meta or on SO's for proper support for this feature. May 23 '12 at 21:32
• What Mariano said. For the sake of those who read the site using wget or telnet!! :-)
– Asaf Karagila Mod
May 23 '12 at 21:35
• @Asaf: Could you expand a bit more on the issue you're pointing out? I'm not familiar with the capabilities of those programs(?), but surely if they don't support MathJax then their users have much bigger problems reading the site than just those due to images centered in this manner, and if they do support MathJax, then shouldn't everything work fine? Apologies for my un-tech-savviness in this regard. May 23 '12 at 21:55
• @Zev: That was a hyperbole. wget is a command line program for downloading content; telnet is just a client for the most basic internet client. Both would be text-mode clients, so MathJax or any visual interpretation are moot. I do agree, however, that doing your best to conform to standards and avoiding MathJax-tricks is a very good advice.
– Asaf Karagila Mod
May 23 '12 at 21:59
• @Asaf: Haha I see :) I found a meta.SO thread where they suggest using &nbsp;'s, which is still ad-hoc and seems prone to breaking (in the sense of the image no longer being centered) if the site's code is changed but at least it doesn't depend on MathJax. May 23 '12 at 22:11
• @MarianoSuárez-Alvarez I am wondering if I should file a request since I seldom need to center images. I will probably stick with the workaround suggested by Zev and in the meta.SO thread in case the need arises.
– user17762
May 24 '12 at 3:09
• @Marvis, none of the options given by Zev (except, maaaaaybe, the one using a pre block) should really be used. I cannot imagine a situation in which you need to center an image here, really! May 24 '12 at 3:12
• @AsafKaragila: What about those of us who use lynx? May 24 '12 at 3:50
• @Isaac: "We" don't care about lynx! ;-)
– Asaf Karagila Mod
May 24 '12 at 7:35

There's a meta.SO thread on this issue, though perhaps it's out of date. The advice there is essentially the same, though they suggest using repeated &nbsp;'s or spaces inside a code block to achieve the same effect. So I suppose that's better than my suggestion below in the sense that it doesn't depend on MathJax, but it still isn't automatic and nice.

Here's an image centered via &nbsp;'s:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;![enter image description here][1]
[1]: http://i.stack.imgur.com/FMddM.jpg


produces

and here is an image centered in a code block:

<pre>
<img src="http://i.stack.imgur.com/wllNN.jpg">
</pre>


produces




My ad-hoc approach in the comments here is one way of centering images.

Reproduced here for convenience:

Insert $\hskip x in$ (adjusting the measurement $x$ as needed) before the ![enter image description here][n] bit, on the same line.

For example,

 $\hskip2in$ ![enter image description here][3]
[3]: http://i.stack.imgur.com/YIFq0.jpg


produces

$\hskip2in$

• Thanks Zev. This does it. I will wait for sometime before I accept an answer.
– user17762
May 23 '12 at 21:19
• Both using nonbreakable spaces and the TeX \hskip only indent the image, as opposed to centering it. All those nbsp's are incredibly sillier than the \hskip :D May 24 '12 at 2:47