[Tex/LaTex] Distributing two small images in a document (horizontally) evenly

graphicshorizontal alignment

Consider the following code (no special packages added)

\begin{document}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text 

\begin{center}
\includegraphics{black_square} and \includegraphics{black_square}
\par\end{center}

Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text 
\end{document}

that produces the output enter image description here, where the black squares stand for some image I wand to put in my document.

My questions are:

  1. Is this the right way to add images to a document ? I'm vaguely aware that there are some floating environments available for this, but I want the images at exactly this specific place.

  2. How can I rearrange the black square so that they are horizontally evenly distributed and the "and" is vertically in the middle, i.e. more like this: enter image description here

Best Answer

Since \includegraphics places images upon the text baseline, I here use \raisebox to shift the figures down (1/2 of their height - 1/2 the height of a textline). Then, by placing symmetric \hspaces around the word "and", I can achieve a symmetric layout. I use % at the end of the lines to prevent stray spaces from getting introduced.

\documentclass{article}
\usepackage[demo]{graphicx}
\begin{document}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text 

\begin{center}
\raisebox{\dimexpr-.5\height+.5\ht\strutbox}%
  {\includegraphics[width=1in,height=1in]{black_square}}%
\hspace{.5in}%
and%
\hspace{.5in}%
\raisebox{\dimexpr-.5\height+.5\ht\strutbox}%
  {\includegraphics[width=1in,height=1in]{black_square}}
\par\end{center}

Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text 
\end{document}

enter image description here

If you wanted the figures to be exactly spaced between the margin and the middle text, this would suffice, replacing the center environment with the appropriate \hfils, making sure to not indent the "paragraph" on which the figures appear.

\documentclass{article}
\usepackage[demo]{graphicx}
\begin{document}
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text 

\medskip
\noindent
\hfil%
\raisebox{\dimexpr-.5\height+.5\ht\strutbox}%
  {\includegraphics[width=1in,height=1in]{black_square}}%
\hfil%
and%
\hfil%
\raisebox{\dimexpr-.5\height+.5\ht\strutbox}%
  {\includegraphics[width=1in,height=1in]{black_square}}%
\hfil%
\par\medskip

Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text 

\medskip
\noindent
\hfil%
\raisebox{\dimexpr-.5\height+.5\ht\strutbox}%
  {\includegraphics[width=1.3in,height=1.3in]{black_square}}%
\hfil%
and%
\hfil%
\raisebox{\dimexpr-.5\height+.5\ht\strutbox}%
  {\includegraphics[width=1.3in,height=1.3in]{black_square}}%
\hfil%
\par\medskip

Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text Text Text Text Text Text Text Text Text Text Text Text Text
Text Text 
\end{document}

enter image description here