Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to place an icon and text behind each other on one line. The icon is higher than a single text line, and would like to have the icon and text center aligned. How do I do that?

share|improve this question

2 Answers 2

up vote 12 down vote accepted

The only way I found to do this robustly (well, Scott showed me this...) is to put the figure in a math matrix:

\documentclass{article}
\usepackage{graphics}
\begin{document}
hello here is $
\begin{array}{l}
\includegraphics{icon}
\end{array}
$ my line.
\end{document}

resulting in alt text

share|improve this answer
    
indent code by four spaces. It’s easier if you select the relevant text and just press the code formatting button in the toolbar, the one with the 101 010 image, right next to the colourful little picture. –  Konrad Rudolph Jul 28 '10 at 9:43
    
@Konrad: thanks. now I'd like to put an image of the result in, but it seems that I should host this image somewhere...is there a make-sence place to put it? or what is the correct way? –  Yossi Farjoun Jul 28 '10 at 9:54
    
That works for me. Thanx! –  Egon Willighagen Jul 28 '10 at 10:32
3  
See also How to vertically center two images for alternative solutions with \vcenter and \raisebox. –  Stefan Kottwitz Dec 16 '10 at 15:08
    
Thanks @Staephan, this is a much better solution, IMO. –  Yossi Farjoun Dec 16 '10 at 15:12

You can use a \parbox.

\documentclass{minimal}
\usepackage{graphicx}

\newcommand{\vcenteredinclude}[1]{\begingroup
\setbox0=\hbox{\includegraphics{#1}}%
\parbox{\wd0}{\box0}\endgroup}

\begin{document}

I need to place an icon \vcenteredinclude{test.png}
and text behind each other on one line. The icon is
higher than a single text line, and would like to have the icon and text
center aligned. How do I do that?

\end{document}

and the outcome is:

example of a vertically centered picture on a text line

share|improve this answer
    
Thank you, this worked perfectly and is really easy to use! –  Spencevail May 2 at 12:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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