Math & SciencePutting on the same line a matrix and a figure

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
soldigiovanni
Posts: 4
Joined: Mon May 09, 2011 6:59 pm

Putting on the same line a matrix and a figure

Post by soldigiovanni »

Hi all!

Does anyone of you know how to put on the same line a matrix and an image in the figure environment? I would be really grateful in your help!

Giovanni
Last edited by soldigiovanni on Wed May 11, 2011 2:00 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Putting on the same line a matrix and a figure

Post by Stefan Kottwitz »

Hi Giovanni,

welcome to the board!

Just write the matrix, using inline math such as $...$ or \(...\), and write \includegraphics{...} after it without a line break or a paragraph break respl. empty line. If both fits on the line, it works. Also within a figure environment.

Stefan
LaTeX.org admin
soldigiovanni
Posts: 4
Joined: Mon May 09, 2011 6:59 pm

Re: Putting on the same line a matrix and a figure

Post by soldigiovanni »

Ah ok perfect! Now my doubt is: how can i insert the matrix with $...$ or \(...\)?
I usually use:

\begin{pmatrix}
.. & .. \\
.. & ..
\end{pmatrix}

Thx a lot,
Giovanni
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Putting on the same line a matrix and a figure

Post by Stefan Kottwitz »

Just insert that environment there, matrices also work in inline math mode.

Stefan
LaTeX.org admin
soldigiovanni
Posts: 4
Joined: Mon May 09, 2011 6:59 pm

Putting on the same line a matrix and a figure

Post by soldigiovanni »

Thx Stefan! It works.
And if I would like to adjust the position of the matrix and of the figure, how can I do? The matrix appears below, while the image on the right upper. I paste you the code:

Code: Select all

\begin{figure}
\begin{tabular}{cc}
$\begin{pmatrix}
0 & 0 & 0 & 0 & 0 & 0 &0 \\
0 & 1 & 1 & 0 & 1 & 1 &0 \\
0 & 1 & 0 & 1 & 0 & 1 &0 \\ 
0 & 1 & 0 & 1 & 0 & 1 &0 \\ 
0 & 1 & 0 & 1 & 0 & 1 &0 \\ 
0 & 1 & 1 & 1 & 1 & 1 &0 \\ 
0 & 1 & 1 & 0 & 1 & 1 &0 \\
0 & 0 & 0 & 0 & 0 & 0 &0 \nonumber
\end{pmatrix} $ &
\includegraphics[scale = 0.3, keepaspectratio = 0.3]{variance} \\
\end{tabular}
\end{figure}
Thx! I'm writing my master thesis :)

Giovanni
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Putting on the same line a matrix and a figure

Post by Stefan Kottwitz »

Hi Giovanni,

to make code more readable, you can insert code tags. I just did it for you. When writing or editing, a Code button is available above the edit field.

For vertical centering, you could use \vcenter:

Code: Select all

\begin{figure}
$\begin{pmatrix}
0 & 0 & 0 & 0 & 0 & 0 &0 \\
0 & 1 & 1 & 0 & 1 & 1 &0 \\
0 & 1 & 0 & 1 & 0 & 1 &0 \\
0 & 1 & 0 & 1 & 0 & 1 &0 \\
0 & 1 & 0 & 1 & 0 & 1 &0 \\
0 & 1 & 1 & 1 & 1 & 1 &0 \\
0 & 1 & 1 & 0 & 1 & 1 &0 \\
0 & 0 & 0 & 0 & 0 & 0 &0 \nonumber
\end{pmatrix} $
$\vcenter{\hbox{\includegraphics[scale = 0.3, keepaspectratio = 0.3]{variance}}}$
\end{figure}
You don't need to use tabular here.

Stefan
LaTeX.org admin
soldigiovanni
Posts: 4
Joined: Mon May 09, 2011 6:59 pm

Re: Putting on the same line a matrix and a figure

Post by soldigiovanni »

Awesome!

Thx
Post Reply