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?

  • 6
    $\begingroup$ 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. $\endgroup$ – Mariano Suárez-Álvarez May 23 '12 at 21:32
  • 1
    $\begingroup$ What Mariano said. For the sake of those who read the site using wget or telnet!! :-) $\endgroup$ – Asaf Karagila May 23 '12 at 21:35
  • 1
    $\begingroup$ @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. $\endgroup$ – Zev Chonoles May 23 '12 at 21:55
  • $\begingroup$ @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. $\endgroup$ – Asaf Karagila May 23 '12 at 21:59
  • 1
    $\begingroup$ @Asaf: Haha I see :) I found a meta.SO thread where they suggest using  '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. $\endgroup$ – Zev Chonoles May 23 '12 at 22:11
  • $\begingroup$ @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. $\endgroup$ – user17762 May 24 '12 at 3:09
  • $\begingroup$ @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! $\endgroup$ – Mariano Suárez-Álvarez May 24 '12 at 3:12
  • 1
    $\begingroup$ @AsafKaragila: What about those of us who use lynx? $\endgroup$ – Isaac May 24 '12 at 3:50
  • $\begingroup$ @Isaac: "We" don't care about lynx! ;-) $\endgroup$ – Asaf Karagila 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  '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  's:

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


                                                       enter image description here

and here is an image centered in a code block:

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



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


$\hskip2in$ enter image description here

  • 1
    $\begingroup$ Thanks Zev. This does it. I will wait for sometime before I accept an answer. $\endgroup$ – user17762 May 23 '12 at 21:19
  • 6
    $\begingroup$ 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 $\endgroup$ – Mariano Suárez-Álvarez May 24 '12 at 2:47

You must log in to answer this question.