5

To speed up visually scanning my org file I would like to add icons to my headings. I am using 16x16 images which seem to fit well with the size of the font, but the images always appear slightly offset, lower than they should be.

Is this expected behavior? Is there a way to fix it so it is vertically aligned with the text? Thanks.

example

3

Create the image with an:ascent property of value center.

Advising org-display-inline-images might be a way of doing this in org-mode, though it will apply to all images.

(defadvice org-display-inline-images (around center-images activate)
  (let ((create-image-orig (symbol-function 'create-image)))
    (cl-letf (((symbol-function 'create-image)
               (lambda (file-or-data &optional type data-p &rest props)
                 (apply create-image-orig file-or-data type data-p
                        (plist-put props :ascent 'center)))))
      ad-do-it)))
  • Thank you for your answer @politza. I can see a doc of the Image Descriptor in section 37.17.2 of the emacs manual, but the org syntax is simply (in my example above) [[file:/usr/share/emacs/24.4/etc/images/icons/hicolor/16x16/apps/emacs.png]] so I'm not sure where I would put the :ascent. – jtgd Apr 12 '15 at 21:49
  • If it is not possible with org-mode syntax, perhaps another question would be, how can I make an image appear as in the example by using just elisp code? – jtgd Apr 12 '15 at 23:18
  • Thank you so much @politza for graciously writing that code. I look forward to the day I know elisp well enough to do that. Your solution works perfectly and was just what I was looking for. I do find that it helps me searching for headlines and I hope it helps others. – jtgd Apr 13 '15 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.