Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I´m trying to put 4 images as a matrix 2 x 2

I´m having troublees with the firs row....

What am I doing bad?

(I have read that subcaption(or similar name) package .... was a good packed)

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

\begin{document}
\begin{tabular}{|c|c|}
      \hline
      % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
      \includegraphics[width=60mm]{simu.jpg} & \includegraphics[width=60mm]{simu.jpg} \\
      {\small ''iteraciones máximas de BT''=20} &  \\
      {\small ''Periodo de Tenencia en Lista Tabú''=2}&  \\
      \hline
\end{tabular}
\end{document} 

What do you recommend me?

What´s the best practise/way in these cases.

The simu.jpg is a normal image SIMU.JPG


With These technic I obtained a months ago this example a row with 4 images, without any problem.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

There is a small problem that the image touches the upper line. Some PDF readers does not show the upper line above the images depending on the view scale settings.

The following example defines macro \addheight that increases the height of the image box (adds some white space above the image). The amount can be configured via the optional argument.

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

\newcommand*{\addheight}[2][.5ex]{%
  \raisebox{0pt}[\dimexpr\height+(#1)\relax]{#2}%
}

\begin{document}
\noindent
\begin{tabular}{|c|c|}
      \hline
      \addheight{\includegraphics[width=60mm]{simu.jpg}} &
      \addheight{\includegraphics[width=60mm]{simu.jpg}} \\
      \small ``row 2, column 1'' &  ``row 2, column 2'' \\
      \hline
\end{tabular}
\end{document}

Result

share|improve this answer
    
I tried to compile your code, but I obtain the same message that with my code... sensa.square7.ch/gdfgdfg.jpg –  Mika Ike Apr 27 at 20:04
    
@MikaIke: Compile with pdflatex instead of latex. For latex/dvips/ps2pdf the .jpg files should be converted to .eps (e.g. jpeg2eps) –  Heiko Oberdiek Apr 27 at 20:28
    
Thank you! Yes You´re right with PDF-Latex my initial purpose also runs well!! but... I need to use LATEX bacause in the same document I have pstricks figures. What´s the solution? –  Mika Ike Apr 27 at 20:39
1  
@MikaIke: There are many ways, convert .png and .jpeg to .eps, use XeLaTeX, or auto-pst-pdf with pdflatex, ... too many to explain in a comment. –  Heiko Oberdiek Apr 27 at 20:47

So long as the images all have the same dimensions, you can do with a tabular; I defined an auxiliary \subf command for the picture and the subcaption, but just for keeping things properly segregated. You can add any number of \\ commands in the caption.

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{graphicx}

\newcommand{\subf}[2]{%
  {\small\begin{tabular}[t]{@{}c@{}}
  #1\\#2
  \end{tabular}}%
}


\begin{document}
\begin{figure}
\centering
\begin{tabular}{|c|c|}
\hline
\subf{\includegraphics[width=60mm]{example-image-4x3.pdf}}
     {``iteraciones máximas \\ de BT''$=20$}
&
\subf{\includegraphics[width=60mm]{example-image-4x3.pdf}}
     {``Periodo de Tenencia \\ en Lista Tabú''$=2$}
\\
\hline
\subf{\includegraphics[width=60mm]{example-image-4x3.pdf}}
     {``iteraciones máximas \\ de BT''$=20$}
&
\subf{\includegraphics[width=60mm]{example-image-4x3.pdf}}
     {``Periodo de Tenencia \\ en Lista Tabú''$=2$}
\\
\hline
\end{tabular}
\end{figure}
\end{document} 

enter image description here

If some space is wanted between the tabular rule and the image, here's a possible way: create a fake first line and back up vertically.

The code is exactly the same as before, but the definition of \subf changes into

\newcommand{\subf}[2]{%
  {\small\begin{tabular}[t]{@{}c@{}}
   \mbox{}\\[-\ht\strutbox]
   #1\\#2
   \end{tabular}}%
}

enter image description here

share|improve this answer
    
I like your answer but as Heiko Oberdiek pointed out, the overlap of the edges of the graphic element and the edge of the table create a rather awkward end result. Isn't there a (a more robust) way to inherently add space between a graphic element within a tabular environment? –  1010011010 Apr 27 at 19:44
    
@Euryris Of course there is; I'll add it. –  egreg Apr 27 at 19:49
    
@egreg I tried your code, (changing the source ...pdf for the simu.jpg) and reach... this error (the same with my purpose and the Heiko´purpose) sensa.square7.ch/gdfgdfg45.jpg –  Mika Ike Apr 27 at 20:12
    
@MikaIke You're compiling with latex instead of pdflatex; the former can't deal with JPG. –  egreg Apr 27 at 20:25
    
@egreg Yes, your´re rigght like Heiko said me the same. The problem is taht in the same document I need tuo use LATESX, bacause I have pstricks pictures. What´s the solution? –  Mika Ike Apr 27 at 20:41

Part 1 (figures):

Have you tried something like:

\documentclass{whatever}
...
\newsavebox{<boxname>}
\setbox\<boxname>=\hbox{
\includegraphics[<options>]{<filename}}
} 

\begin{document}
...
\begin{tabular}{...}
...
{\usebox{\<boxname>}}
...
\end{tabular}
...
\end{document}

You can resize boxes using the \resizebox or manually with arguments of includegraphics.


Part 2 (text):

You can also use \hbox (this is in the standard LaTeX engine, no package required), or \pbox{<size of box>}{<text, argument, figure, you name it>} (this will require \usepackage{pbox} to function, and perhaps a small update of your TeX/package distribution).

\pbox also allows you to use linebreaks within the environment:

\pbox{<size of box>}{<text, argument, figure, you name it> \\
                     <more text, arguments, figures, etc.>    
                    }

(If you decide this is prettier.)


These are pretty robust and impractical solutions to put figure (option 1) and text (option 2) into floats (floats are figures, tikzpictures, and I'm pretty sure this works too for tables).


MWE

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

\begin{document}
\begin{tabular}{|c|c|}
  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  \pbox{6cm}{\vspace{5ex} \includegraphics[width=60mm]{simu.jpg}} & \pbox{6cm}    {\vspace{5ex} \includegraphics[width=60mm]{simu.jpg}} \\
  {\pbox{6cm}{\vspace{.25ex}\small ''iteraciones máximas de BT''=20\vspace{5ex}}}     &       {\pbox{6cm}{\vspace{5ex}\small ''Periodo de Tenencia en Lista Tabú''=2\vspace{5ex}}} \\
 &  \\
  \hline
  \pbox{6cm}{\vspace{5ex} \includegraphics[width=60mm]{simu.jpg}} & \pbox{6cm}    {\vspace{5ex} \includegraphics[width=60mm]{simu.jpg}} \\
  {\pbox{6cm}{\vspace{5ex}\small ''iteraciones máximas de BT''=20\vspace{5ex}}} &   {\pbox{6cm}{\vspace{.25ex}\small ''Periodo de Tenencia en Lista Tabú''=2 \vspace{5ex}}} \\
\hline
\end{tabular}
\end{document}

Here you can see that you can control the height to whatever length you want (using vspace) and the width, using pbox. Is this what you want?

share|improve this answer
    
but.., I have use that with other smaller graphics and... good results!! ... with width I would must control the width of the image –  Mika Ike Apr 27 at 18:52
    
There's no need to use a figure environment for \includegraphics. –  egreg Apr 27 at 19:00
    
I just used figure as an example. I'll edit to avoid confusion. Thanks. –  1010011010 Apr 27 at 19:03
    
is possible a minimal example?. I think that I have view in any post any similar to what I want, but.. I can´t find it. –  Mika Ike Apr 27 at 19:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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