14

I am trying to make my first LaTeX file and have been reading syntax for a bit and have not been able to figure one thing out yet and don't seem to find anything about it online so I thought I might just ask:)

How is it possible to place an image next to an equation?

I tried to do it by wrapping it around, putting it into a table or anything similar but I can't get it working... Of course I could just have used the syntax wrong since I'm new to the subject:) It's for a summary for my exams and the pages are limited so I would like to save some space, plus it would look a lot better.

Additionally, if anyone could give me a link to a tutorial that is a bit more extensive than just the basics i would be very thankful as well!

\documentclass[11pt, a4paper]{article}      
\usepackage{geometry}                        
\usepackage{amsmath}
\usepackage{wrapfig}
\geometry{a4paper}                                      
\usepackage{graphicx}                   
\usepackage{amssymb}
\geometry{left=5mm, right=5mm, top=0mm, bottom=5mm}

\title{\huge {\textbf{Lineare Algebra}}}
\author{ David Wright}

\date{\today}

\begin{document}
\maketitle{\large{\textbf{Vektorgeometrie}}}
\vspace {5mm}

\maketitle{\textbf{Skalarprodukt}}

Das Skalarprodukt ergibt die L\"{a}nge der Projektion von \ensuremath{\vec{a}} auf \ensuremath{\vec{b}}.


\begin {tabular}{p{10cm}l}
{\begin {align*}
\vec{a} \bullet \vec{b}& = |\vec{a}| \cdot |\vec{b}| \cdot \cos(\phi) \\
                       & = a_x  \cdot b_x + a_y \cdot b_y + a_z \cdot b_z \\
            \cos(\phi) & =  \frac {\vec{a} \bullet \vec{b}}{|\vec{a}| \cdot  |\vec{b}|}\\
                       & = \frac {a_x  \cdot b_x + a_y \cdot b_y + a_z \cdot b_z}{\sqrt{a_x^2 + a_y2 + a_z^2}\sqrt{b_x^2 + b_y^2 + b_z^2}}
\end {align*}}
&

\includegraphics[keepaspectratio = true, scale = 1] {dotp.jpg}
\end{tabular}

\vspace{5mm}

\maketitle{\textbf{Vektorprodukt}}

TextTextTextTextTextTextTextTextTextText


\end{document}  

This is the outcome now

David Carlisle
  • 757,742

3 Answers3

12

There are several possibilities. Perhaps the simplest is

\usepackage{graphicx}

...

\begin{tabular}{p{3cm}c}
\begin{equation}
1=1
\end{equation}
&
\includegraphics{mypic}
\end{tabular}

or with align:

\documentclass{article}

\usepackage{graphicx,amsmath}

\begin{document}

\begin{tabular}{p{5cm}c}
{\begin{align}
1&=1\\
11&=22
\end{align}}
&
\includegraphics[draft]{mypic}
\end{tabular}

\end{document}
David Carlisle
  • 757,742
  • thank you for your answer, i tried to do that before but it did not seem to work because it seemed to have a problem with the equation, would it be possible that the the align-environment doesn't work with tabular? – David Wright Aug 04 '12 at 12:14
  • 1
    should work but you need extra brace group to hide the &, did you make sure to use a p column for the display environments (which won't work in a c columns) But this is why we always ask people to include a complete document in their question if you'd included align I would have used it in the answer – David Carlisle Aug 04 '12 at 12:25
  • Thanks I just realised that so I updated the question and pasted the part of the document! But I don't understand what you meant with p and c columns to be honest..:) – David Wright Aug 04 '12 at 12:33
  • equation and align are display enviornments that need to go in vertical material, so they work in a \parbox but not in an \mbox which is a single-line construct. In a table l c r are single line horizontal boxes like \mbox so you need a p columns of a specified width which makes a paragraph box to hold the display. Your updated question used ll change that to p{something}l would have been enough for equation but for align the & confuses things so you need an extra {} as in my answer – David Carlisle Aug 04 '12 at 12:42
  • oh also align is a complete math environment ot should not be inside equation. Finally when making a MWE pleas include the \documentclass and \usepackage .. end{document} it avoids misunderstandings and makes it easier for anyone trying to answer. – David Carlisle Aug 04 '12 at 12:49
  • thank you very much that solved the problem!

    but somehow now the picture is further up and the equation is beneath it, even though they are on the left, respectively on the right side, do you know what might have caused that? I'll update the code in the question.

    – David Wright Aug 04 '12 at 12:52
  • Also I uploaded a screenshot – David Wright Aug 04 '12 at 13:01
  • images have a baseline at the bottom, you could use the adjustbox package or \raisebox{-20pt}{\includegraphics... to move it down – David Carlisle Aug 04 '12 at 13:08
  • \raisebox{-20pt}{\includegraphics...} won't work(I can only move the picture down and the boxes further apart somehow) and if I put \adjustbox{raise = -20pt}{\includegraphics.....} it won't compile. can you maybe tell me where exactly I've got to enter that bit or if I maybe made a mistake? – David Wright Aug 04 '12 at 13:59
  • Never mind, i tried it with \raisebox again and now it worked! I just had to put it in one line! Thank you very much you were incredibly helpful! – David Wright Aug 04 '12 at 14:07
  • You can also add \raisebox{-3cm or so...} to the tabular enviroment. This will vertically move your grphx. Tested. –  Aug 24 '12 at 09:44
10

Instead of using a tabularenvironment to position the objects, there is also the possibility to make the graphics part of the math formula, for example like this:

\[
\begin {aligned}
\vec{a} \bullet \vec{b}& = |\vec{a}| \cdot |\vec{b}| \cdot \cos(\phi) \\
                       & = a_x  \cdot b_x + a_y \cdot b_y + a_z \cdot b_z \\
            \cos(\phi) & =  \frac {\vec{a} \bullet \vec{b}}{|\vec{a}| \cdot  |\vec{b}|}\\
                       & = \frac {a_x  \cdot b_x + a_y \cdot b_y + a_z \cdot b_z}{\sqrt{a_x^2 + a_y2 + a_z^2}\sqrt{b_x^2 + b_y^2 + b_z^2}}
\end {aligned}
\qquad
\raisebox{-15mm}{\includegraphics[keepaspectratio = true, scale = 1] {dotp.jpg}}
\]

The \qquad is used to get some whitespace (2em) and \raisebox is only there is you have to adjust the picture vertically.

David Carlisle
  • 757,742
1

I recommend using "subcaption" package. Look at this link for the manual of the package. (link: click here)

I didn't have your dotp.jpg file so I just took a screenshot, copy-pasted in paint and cut a part of the screensot and saved it in a png file. So sorry for the quality in the image I uploaded below the code I wrote for you here.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{subcaption}
\author{AmirHosein Sadeghimanesh}
\title{Equation-and-image-side-by-side-20200202}
\begin{document}
    \maketitle

    \begin{figure}[h]
        \centering
        \begin{subfigure}[b]{0.45\textwidth}
            \centering
            \begin {align*}
            \vec{a} \bullet \vec{b}& = |\vec{a}| \cdot |\vec{b}| \cdot \cos(\phi) \\
            & = a_x  \cdot b_x + a_y \cdot b_y + a_z \cdot b_z \\
            \cos(\phi) & =  \frac {\vec{a} \bullet \vec{b}}{|\vec{a}| \cdot  |\vec{b}|}\\
            & = \frac {a_x  \cdot b_x + a_y \cdot b_y + a_z \cdot b_z}{\sqrt{a_x^2 + a_y2 + a_z^2}\sqrt{b_x^2 + b_y^2 + b_z^2}}
            \end {align*}
            \caption{Equation.}
            \label{fig:equation}
        \end{subfigure}
        \hfill
        \begin{subfigure}[b]{0.45\textwidth}
            \centering
            \includegraphics[width=\textwidth]{dotp.png}
            \caption{Image.}
            \label{fig:image}
        \end{subfigure}
        \caption{Total caption.}
    \end{figure}

enter image description here