使用文本左侧的图标和文本行中的符号

使用文本左侧的图标和文本行中的符号

问题都在本文档中。

在此处输入图片描述

\documentclass{article}

\usepackage{graphicx, tabularx}
\usepackage[nopar]{lipsum}

\newenvironment{centerentry}[2][]
  {\renewcommand{\tabularxcolumn}[1]{m{##1}}
   \noindent
   \tabularx{\linewidth}{ @{} m{\imagecolwidth} X @{} }
     \includegraphics[width=\linewidth,#1]{#2} &
  }{%
   \endtabularx%
  }
\newlength{\imagecolwidth}
\setlength{\imagecolwidth}{2em}

\sloppy% Just for this example

\begin{document}
\section{Is it possible to get this text line and the two pictures centered?}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a} horizontal centered? \includegraphics[height=8ex]{example-image-b}\\
\end{centerentry}
\section{This text is centerd to the picture.}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\section{Third  text is not centerd.}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a} horizontal centered? \includegraphics[height=8ex]{example-image-b}\\
\end{centerentry}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\section{More than one text line: Output is OK. Of course it would be nice if the text is around the Picture B.}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 Write some text to get more lines. Write some text to get more lines. To see. Write some text to get more lines. More lines. Write some text to get more lines. \includegraphics[height=8ex]{example-image-b}  Write some text to get more lines. Write some text to get more lines.
\end{centerentry}
\section{With Photoshop:}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a} horizontal centered? \includegraphics[height=8ex]{example-image-b}\\
\end{centerentry}
\end{document}

答案1

问题在于第二幅图像的垂直对齐。您可以使用adjustbox包在中引入垂直对齐\includegraphics

\documentclass{article}

\usepackage{graphicx, tabularx}
\usepackage[nopar]{lipsum}
\usepackage[export]{adjustbox}

\newenvironment{centerentry}[2][]
  {\renewcommand{\tabularxcolumn}[1]{m{##1}}
   \noindent
   \tabularx{\linewidth}{ @{} m{\imagecolwidth} X @{} }
     \includegraphics[width=\linewidth,#1]{#2} &
  }{%
   \endtabularx%
  }
\newlength{\imagecolwidth}
\setlength{\imagecolwidth}{2em}

\sloppy% Just for this example

\begin{document}
\section{Is it possible to get this text line and the two pictures centered?}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a} horizontal centered?
  \includegraphics[height=8ex,valign=c]{example-image-b}\\
\end{centerentry}
\section{This text is centerd to the picture.}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\section{Third  text is not centerd.}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a} horizontal centered?
  \includegraphics[height=8ex,valign=c]{example-image-b}\\
\end{centerentry}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 This text is centerd to the picture.
\end{centerentry}
\section{More than one text line: Output is OK. Of course it would be nice if the text is around the picture.}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a}
 Write some text to get more lines. Write some text to get more lines. To see.
 Write some text to get more lines. More lines. Write some text to get more
 lines. \includegraphics[height=8ex,valign=c]{example-image-b}  Write some text to get more lines. Write some text to get more lines.
\end{centerentry}
\section{With Photoshop:}
\begin{centerentry}[height=4ex, width=4ex]{example-image-a} horizontal centered?
  \includegraphics[height=8ex,valign=c]{example-image-b}\\
\end{centerentry}
\end{document}

在此处输入图片描述

对于您评论中关于仅指定一次宽度并设置高度以使纵横比保持不变的问题:

只是不要使用 的可选参数\begin{centerentry}。这样,​​图像将获得完整的线宽(\imagecolwidth在环境中相等),并且纵横比应该是 的默认值graphicx

相关内容