8

I have to reproduce a part of the following figureenter image description here

Here is my code

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}[htb]
\centering
  \begin{tabular}{@{}cccc@{}}
    \includegraphics[width=.23\textwidth]{example.pdf} =  &
    \includegraphics[width=.23\textwidth]{example0.pdf} + &
    \includegraphics[width=.23\textwidth]{example1.pdf} + &
    \includegraphics[width=.23\textwidth]{example2.pdf} + &
                                +                     &
    \includegraphics[width=.23\textwidth]{example3.pdf} +&
    \includegraphics[width=.23\textwidth]{example4.pdf} +&
    \includegraphics[width=.23\textwidth]{example5.pdf} +&
                                                      &
    \includegraphics[width=.23\textwidth]{example6.pdf} +&
    \includegraphics[width=.23\textwidth]{example7.pdf} +&  
    \includegraphics[width=.23\textwidth]{example8.pdf} &
  \end{tabular}
  \caption{This is   some figure side by side}
\end{figure}
\end{document}

I get the following output

enter image description here

I would like to know how I can alligh the math operators (+,=) so I can get them in the middle

Thanks and Regards,

Fowaz

3

Precise alignment to the plus sign is obtained by enveloping the \includegraphics in \vcenter, which is automatically done by array (since we're in math mode) without optional arguments.

\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}

\newcommand{\vcenterincludegraphics}[2][]{%
  \begin{array}{@{}c@{}}
  \includegraphics[#1]{#2}
  \end{array}%
}


\begin{document}
\begin{figure}
\centering

$\begin{aligned}
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} ={}&
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} +
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} +
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} + {} \\
  &
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} +
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} +
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} + {} \\
  &
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} +
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1} +
  \vcenterincludegraphics[width=.20\textwidth]{example-image-1x1}
\end{aligned}$

\caption{This is some figure side by side}

\end{figure}

\end{document}

I changed .23 to .20 to avoid overfull lines (the code has been taken, with modifications, from Werner's answer).

enter image description here

Of course the definition

\newcommand{\vcenterincludegraphics}[2][]{%
  \vcenter{\hbox{%
    \includegraphics[#1]{#2}
  }}%
}

would be more efficient, perhaps at the expense of clarity.

4

I did several things. I edited to force line breaks in the tabular, where appropriate, I used \raisebox to achieve vertical centering of math operators, which I also cast into math mode for proper spacing.

\documentclass[a4paper,12pt]{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\newcommand\IG[1]{\raisebox{-.5\height}{%
  \includegraphics[width=.23\textwidth]{#1}}}
\begin{document}
\begin{figure}[htb]
\centering
\tabcolsep0pt
\renewcommand\arraystretch{7}
  \begin{tabular}{@{}cccc@{}}
    \IG{example.pdf}${}={}$&
    \IG{example0.pdf}${}+{}$&
    \IG{example1.pdf}${}+{}$&
    \IG{example2.pdf}${}+{}$\\&
    \IG{example3.pdf}${}+{}$&
    \IG{example4.pdf}${}+{}$&
    \IG{example5.pdf}${}+{}$\\&
    \IG{example6.pdf}${}+{}$&
    \IG{example7.pdf}${}+{}$&  
    \IG{example8.pdf} 
    \phantom{${}+{}$}
  \end{tabular}
  \caption{This is   some figure side by side}
\end{figure}
\end{document}

enter image description here

4

You may wish to set this like a regular equation, using adjustbox's valign=m to set the images with a vertical anchor point in the middle:

enter image description here

\documentclass{article}
\usepackage[export]{adjustbox}
\usepackage{amsmath}

\let\oldincludegraphics\includegraphics

\begin{document}
\begin{figure}
  \renewcommand{\includegraphics}[2][]{\oldincludegraphics[valign=m,width=.23\textwidth,#1]{#2}}
  \begin{align*}
    \includegraphics{example-image-1x1} &=
    \includegraphics{example-image-1x1} +
    \includegraphics{example-image-1x1} +
    \includegraphics{example-image-1x1} + {} \\
    & \phantom{{}={}}
    \includegraphics{example-image-1x1} +
    \includegraphics{example-image-1x1} +
    \includegraphics{example-image-1x1} + {} \\
    & \phantom{{}={}}
    \includegraphics{example-image-1x1} +
    \includegraphics{example-image-1x1} +
    \includegraphics{example-image-1x1}
  \end{align*}
  \vspace{-\belowdisplayskip}
  \caption{This is some figure side by side}
\end{figure}

\end{document}

The above approach mimics typical mathematical typesetting in terms of spacing around operators, seeing as your are doing exactly that.

  • Good answer, but I disagree with the idea of redefining \includegraphics, even locally. – egreg Oct 14 '15 at 20:11
3

Similarly, but with help of adjustbox and `array package:

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\usepackage{subcaption}

\usepackage{array}
\usepackage[export]{adjustbox}

    \begin{document}
\begin{figure}[h]
\centering
  \begin{tabular}{@{}*{4}{p{0.23\textwidth}>{$}c<{$}}@{}}
    \includegraphics[width=\hsize,valign=m]{example-image-a} &=&
    \includegraphics[width=\hsize,valign=m]{example-image}   &+& 
    \includegraphics[width=\hsize,valign=m]{example-image}   &+& 
    \includegraphics[width=\hsize,valign=m]{example-image}   &+  \\[7ex]
%
    &   &
    \includegraphics[width=\hsize,valign=m]{example-image}   &+&
    \includegraphics[width=\hsize,valign=m]{example-image}   &+&
    \includegraphics[width=\hsize,valign=m]{example-image}   &  \\
  \end{tabular}
 \caption{This is   some figure side by side}
\end{figure}
    \end{document}

enter image description here

0

I would use \raisebox on every "+"sign

\includegraphics[width=.23\textwidth]{example.pdf} \raisebox{1.1cm}{=}  &
\includegraphics[width=.23\textwidth]{example0.pdf} \raisebox{1.1cm}{+} &
\includegraphics[width=.23\textwidth]{example1.pdf} \raisebox{1.1cm}{+} &
\includegraphics[width=.23\textwidth]{example2.pdf} \raisebox{1.1cm}{+} &
                            \raisebox{1.1cm}{+}                   

You gotta iterate the height of the sign for different desired results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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