0

The questions are in this document.

enter image description here

\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}
  • @ Werner: Thank you for your help, that fits my needs good. Additional to my example I have to tell, that also the width is variable by each picture.

    So is it possible to connect \setlength{\imagecolwidth}{2em} and [width=1\textwidth] in \includegraphics

    so that I had to define the wanted width of the picture only once?

    @ David: Thank you for your example: Is it possible to change each picture in the size, especially the width?

    – user145530 Oct 12 '17 at 17:24
  • is this not the same as https://tex.stackexchange.com/questions/395693/how-can-i-use-symbols-icons-left-of-a-description/395697#395697 – David Carlisle Oct 12 '17 at 17:33
  • @ David: No, now there are pictures in the text left of the icon. And I do not know how to center the picture. – user145530 Oct 12 '17 at 17:36
  • And there are the two additional questions to you and Werner in the first comment to the answers of your link. – user145530 Oct 12 '17 at 17:38
  • \usepackage[export]{adjustbox} and \includegraphics[valign=c,width=4ex]{example-image}? – Torbjørn T. Oct 12 '17 at 17:39
  • @ David: Thank you for your example: Is it possible to change each picture in the size, especially the width? – user145530 Oct 12 '17 at 17:58
  • @user145530: Can you (1) register your account and (2) merge your accounts? The Stack Exchange staff can merge them together for you. – Werner Oct 12 '17 at 18:01
  • it is very disconcerting if you have a new user name every question. I do not understand your question about size of image, Of course you can use with= and height= keys on \includegraphics as you show in your code above. – David Carlisle Oct 12 '17 at 18:36

1 Answers1

2

The problem is the vertical alignment of the second image. You can use the adjustbox package to introduce vertical alignment in \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}

enter image description here

For the question in your comment about only specifying the width once and setting the height so that the aspect ratio remains unchanged:

Just don't use the optional argument to \begin{centerentry}. This way the image will get the full line width (which equals \imagecolwidth in the environment) and the aspect-ratio thingy should be the default of graphicx.

Skillmon
  • 60,462
  • Yes, section 1 is now very good. Thank you Skillmon. And what to do with section 4? Section 4 is not nice. But I need sometimes bigger pictures, additional to the text for explanation. – user145530 Oct 12 '17 at 17:50
  • @user145530 As I stated in my answer, I only applied the change to the first occurence, therefore do the same as with the first line. Add valign=c to the options of the \includegraphics. Same for section 5. The question you ask in section 4 is not really coverable in LaTeX as far as I know. Take a look at the wrapfig, the picins and the floatflt package for the best you can get. – Skillmon Oct 12 '17 at 17:51
  • @user145530 I added the valign=c to all \includegraphics in the text. – Skillmon Oct 12 '17 at 17:54
  • @ all: is it possible to connect \setlength{\imagecolwidth}{2em} and [width=1\textwidth] in \includegraphics so that I had to define the wanted width of the picture only once? And the height should be choosen automatically in proportion of the Icon. – user145530 Oct 12 '17 at 18:00
  • @user145530 I've updated my answer to answer the question in your last comment. Now please stop changing your question by comments. If my answer is good in your eyes, upvote it. If there is no new answer within a reasonable time that is better than mine, and if mine fits your needs, accept it. You might also take a look at the cutwin package for the stuff you want to achieve in section 4. – Skillmon Oct 12 '17 at 18:11