39 Comments

  1. Michalis

    Cheers, great page and great resource on latex issues overall. It has helped me so many times ;-). Thanks again!

  2. Ana

    I need some help on the use of figures in tables, I have done something like this

    \begin{tabular}{cc}
            \hspace{0.5em}\scalebox{1.25}{\includegraphics[height=7em]{a.png}} &
            \hspace{0.5em}\scalebox{1.25}{\includegraphics[height=7em]{b.png}}
           \end{tabular}\\

    But I cannot put the captions, wherever I try to use the \caption all I get is errors… Any idea to put properly the captions?

    • Hi Ana,

      You will not be able to add a caption to your pictures, since the caption has to go in the floating environment like “figure” or “table”. However, it is not possible to add a floating environment into the cell of a table.
      In the worst case however, you can try to something like this within your cell, even though it is really bad style:

      \parbox{4cm}{\includegraphics[scale=0.1]{image}%
      \addtocounter{figure}{1} \\ %
      Figure \thefigure: bla%
      \addcontentsline{lof}{figure}{Figure \thefigure: bla}}
      • 1. Defining a box within the cell
      • 2. Add the image to the cell
      • 3. Increase the image counter
      • 4. Linebreak
      • 5. Add a caption
      • 6. Add caption to the list of figures

      If you want a caption to your “tabular” however, than you simply need to add a floating environment “table” around it.

      Cheers,
      Tom.

      • axle

        how to reference image inside table? I use \label for image inside table but it refer to the table instead..

      • Hi Axle,

        Thanks for this question. You need a caption to reference the figure, because the caption displays the figure number. Below is the example from the article with the caption added. I’m using the caption package which provides the captionof command.

        HTH, Tom

        \documentclass[11pt]{article}
        \usepackage{graphicx, array, blindtext}
        \usepackage{caption}
        \begin{document}
        \begin{table}[ht]
        \caption{A table arranging  images}
        \centering
        \begin{tabular}{*{2}{m{0.48\textwidth}}}
        \hline
        This is some text&\begin{center}\rule{0.4\textwidth}{0.3\textwidth}\end{center}\\
        \hline
        \blindtext&\begin{center}\rule{0.4\textwidth}{0.3\textwidth}\\\parbox[c]{2in}{\captionof{figure}{\label{fig:intable}A figure in a tabular environment with a caption.}}\end{center}\\
        \hline
        \end{tabular}
        \label{tab:gt}
        \end{table}
        See figure \ref{fig:intable}.
        \end{document}
  3. You can also wrap your tabular in a figure (at least in TeXLive 2009-7) to get access to a global caption and labels.

    \begin{figure}
    \caption{A table arranging images}
    \centering
    \begin{tabular}{cc}
    \includegraphics[scale=1]{graphic1}&\includegraphics[scale=1]{graphic2}\\
    \newline
    \includegraphics[scale=1]{graphic3}&\includegraphics[scale=1]{graphic4}\\
    \end{tabular}
    \label{tab:gt}
    \caption{some caption here}
    \end{figure}
  4. adam

    Just for the record, with the \captionof{}{} command of the caption package you can also access the global captions and labels without needing to place your figure in a float environment.

    \usepackage{caption}
    
    \centering
    \begin{tabular}{cc}
    \includegraphics[scale=1]{graphic1}&\includegraphics[scale=1]{graphic2}\\
    \newline
    \includegraphics[scale=1]{graphic3}&\includegraphics[scale=1]{graphic4}\\
    \end{tabular}
    \label{tab:gt}
    \captionof{figure}{some caption here}
  5. sarvesh

    Dear Sir, Is there any command to draw curly bracket in figure environment using latex. I want to use it on two vertical box drawn using

    \put(-2,-2){\framebox(2,1)[c]{\shortstack[c]{Detection}}}
    \put(-1,-2){\vector(0,-1){1.0}}
    \put(-2,-4){\framebox(2,1)[c]{\shortstack[c]{Tracking}}}

    Please suggest me.

  6. sarvesh

    Dear Sir,
    Please find herewith the code on which i am working. I wanted to cover the “motion segmentation” and “object classification” block together by using curly bracket to indicate “Human Detection Low-level Vision” statement at right side of curly bracket But i could not do it as the size of curly bracket (using this command {\Bigg\}}) is limited. It just fall short. I want to make it larger to fit according to dimension of my two block as stated above.

    \begin{figure}[!htp]
    \centering
    \setlength{\unitlength}{1.6em}
    \begin{picture}(5.000000,11.0000)(-2.000,-9.0000)
    \scriptsize
    \put(-4.0000,-2.0000){\framebox(5.0000,1.000)[c]{\shortstack[c]{Motion Segmentation}}}
    \put(-1.500,-2.000){\vector(0,-1){0.75000}}
    \put(1.1,-2.5){\Bigg\}}
    \put(1.75,-2.250){\tiny{$Human\;Detection$}}
    \put(1.75,-2.650){\tiny{$(Low-level\;Vision)$}}
    \put(-4.0000,-3.75000){\framebox(5.0000,1.000)[c]{\shortstack[c]{Object Classification}}}
    \put(-1.500,-3.75000){\vector(0,-1){0.75000}}
    \put(-4.0000,-5.5000){\framebox(5.0000,1.000)[c]{\shortstack[c]{Human Tracking}}}
    \put(-1.500,-5.5000){\vector(0,-1){0.75000}}
    \put(1.1,-5.12500){\Big\}}%\bigg\}}
    \put(1.75,-5.0){\tiny{$Human\;Tracking$}}
    \put(1.75,-5.400){\tiny{$(Intermediate-level\;Vision)$}}
    \put(-4.0000,-7.250000){\framebox(5.0000,1.000)[c]{\shortstack[c]{Action Recognition}}}
    \put(-1.500,-7.250000){\vector(0,-1){0.75000}}
    \put(-4.0000,-9.0000){\framebox(5.0000,1.000)[c]{\shortstack[c]{Semantic Description}}}
    \put(1.1,-7.7500){\Bigg\}}
    \put(1.75,-7.350){\tiny{$Behavior\;Understanding$}}
    \put(1.75,-7.7500){\tiny{$(High-level\;Vision)$}}
    \end{picture}
    \caption{\small{A general framework of human motion analysis}}
    \label{fig:featurebaseddecision}
    \end{figure}

    Please help me to get desired output.
    Thanks & Regards

    • Hi Sarvesh,

      I adapted the first brace using TikZ (see code below). You can change the second brace accordingly. You will need to typeset the document twice to get everything right. Cheers, Tom.

      \documentclass[11pt]{article}
      \usepackage{tikz}
      \usetikzlibrary{decorations.pathreplacing}
      \begin{document}
      \begin{figure}[!htp]
      \centering
      \setlength{\unitlength}{1.6em}
      \begin{picture}(5.000000,11.0000)(-2.000,-9.0000)
      \scriptsize
      \put(-4.0000,-2.0000){\framebox(5.0000,1.000)[c]{\shortstack[c]{Motion Segmentation}}}
      \put(1.0,-1.0){\tikz[remember picture] \node[coordinate, xshift=1em] (n1) {};}
      \put(-1.500,-2.000){\vector(0,-1){0.75000}}
      \put(-4.0000,-3.75000){\framebox(5.0000,1.000)[c]{\shortstack[c]{Object Classification}}}
      \put(-4.0000,-3.75000){\tikz[remember picture] \node[coordinate] (n2) {};}
      \begin{tikzpicture}[overlay,remember picture]
            \path (n2) -| node[coordinate] (n3) {} (n1);
            \draw[thick,decorate,decoration={brace,amplitude=3pt}]
                  (n1) -- (n3) node[midway, right=5pt, align=left] {Human Detection\\ Low-level Vision};
        \end{tikzpicture}
      \end{picture}
      \end{figure}
      \end{document}
      • sarvesh

        Dear Sir,
        Thanks a lot for the help. your code is working well on “bare_jrnl.tex V1.3 2007/01/11” by Michael Shell (http://www.michaelshell.org/).
        But its showing error “1.104 \pgfsetplottension{0.5}” while i am trying to compile it with “ieeecls SPECIFICATION FOR COMMON IEEE STYLES” by Gregory L. Plett, Istvan Kollar.

        Thank you very much for your guidance and help.

        with regards
        Sarvesh

  7. Hi, thanks for this!

    I am trying to place graphics in the last column of a table. The other columns are text, and when I \includegraphics the text in the first three columns ends up at the bottom of the cell, even if I define the cells as paragraph. Is there anything I can do to center the text within the columns?

    • Hi!

      The array package with it’s column type “m” should do the trick. Best, Tom.

      \documentclass[11pt]{article}
      \usepackage{array, blindtext}
      \begin{document}
      \begin{table}[ht]
      \caption{A table arranging  images}
      \centering
      \begin{tabular}{*{2}{m{0.48\textwidth}}}
      \hline
      This is some text&\begin{center}\rule{0.4\textwidth}{0.3\textwidth}\end{center}\\
      \hline
      \blindtext&\begin{center}\rule{0.4\textwidth}{0.3\textwidth}\end{center}\\
      \hline
      \end{tabular}
      \label{tab:gt}
      \end{table}
      \end{document}
  8. Clement

    Hi sir,

    i’ve tried using the m{0.3\textwidth}} command. but it only works on its own. when i tried using c | c | c to justify it, it automatically becomes bottom alligned again.
    I am writing for 2 column paper (IEEE template) and without the c | c | c, it becomes spans to the width of the whole page rather than just the column
    here’s my code:

    \begin{table}[t]
    \caption{Table Testing}
    \centering
    \begin{tabular}{*{3}{l|l|l m{0.3\textwidth}}}
    Feynman & \includegraphics[width=1.5in]{FeynPDF} &
    \begin{tabular}[t]{l}
    $P = Q$ \\ $Q = A \bigoplus B$\\
    \end{tabular}\\
    \end{tabular}
    \end{table}
    • tom

      See the updated code below for a possible fix. Just two notes for clarification:

      • Replaced inner tabular with amsmath align environment. It’s nicer to have formulas in a math environment and saves a few $-signs.
      • Fixed column type repetition (*{n}{type}), all centered horiz. and vert. now. For a smaller first column, use \begin{tabular}{|l|m{0.3\textwidth}|m{0.3\textwidth}|}.
      \documentclass[11pt]{article}
      \usepackage{graphicx, array, amsmath}
      \begin{document}
      \begin{table}[t]
      \caption{Table Testing}
      \centering
      \begin{tabular}{|*{3}{>{\centering\arraybackslash}m{0.3\textwidth}|}}
      Feynman & \rule{1.5in}{1.5in} &
      {\begin{align}
      P &= Q \\ 
      Q &= A \bigoplus B
      \end{align}}
      \end{tabular}
      \end{table}
      \end{document}

      Was having some HTML formatting issues, sorry for that. Everything should be fine now and you can copy-paste the code.

      • Clement

        this fixed my problem.
        thanks again. Learn something new today.

        \begin{tabular}{|l|m{0.2\textwidth}|m{0.1\textwidth}|}
         	Feynman & \includegraphics[width=1.5in]{FeynPDF} P &= Q \\  	Q &= A \bigoplus B \end{align}}

        Regards.
        Clement

  9. vigamage

    Thank you very much for the tutorial. But I have problem when vertically aligning the images inside the table column.

    I need my image to be aligned to the top(Where the text starts). But how to do that. My code looks like this

    \begin{tabular}{*{2}{m{0.16\textwidth}}}
       \begin{minipage}[t]{\textwidth}
            %\rule{0.4\textwidth}{0.3\textwidth}
            \includegraphics[scale=2.0]{abc}
        \end{minipage}
            &
        \begin{minipage}[t]{0.29\textwidth}
           hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world hello world 
        \end{minipage}
            \\
    \end{tabular}
    • tom

      Hi there,

      The example below should do the trick.

      HTH, Tom

      \documentclass[10pt]{article}
      \usepackage{array,blindtext}
      \begin{document}
      \begin{tabular}{*{2}{p{0.45\linewidth}}}
      \vspace{0pt}
      \rule{\linewidth}{\linewidth}
      &
      \vspace{0pt}
      \blindtext
      \end{tabular}
      \end{document}

Leave a Reply