文本和图像垂直居中在一行

文本和图像垂直居中在一行

我需要将图标和文本放在一行上,并排放置。图标高于一行文本,我想让图标和文本居中对齐。我该怎么做?

答案1

我发现唯一能稳健地做到这一点的方法(好吧,斯科特向我展示了这个......)是将这个数字放在数学矩阵中:

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

导致替代文本

答案2

您可以使用\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}

结果是:

文本行上垂直居中图片的示例

相关内容