1

I was trying to insert pictures with captions in a table in latex. I have read some posts here about adding pictures in the table using \raisebox. I tried something like

\begin{table}[ht]
\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
 Query Structure & The most similar structure & The second most similar structure & The    third most similar structure \\
\hline
\raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_B3LYP_631Gd}} &     \raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_B3LYP_631Gd}} & \raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_G3MP2B3}} &\raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_G3B3}}\\
\hline
\end{tabular}
\end{center}
\end{table}

It worked. But I want these pictures with captions. At first, I tried to add caption{} in raisebox directly like:

\raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_B3LYP_631Gd} \caption{structure GS\_Ade\_PathwayA\_I1A\_B3LYP\_631Gd}}     

I got error msg for writing latex like this. So I tired to put the captions in the next row with no \hline in between to work around.

\begin{table}[ht]
\label{table2}
\begin{center} %Note American spelling
\begin{tabular}{| p{0.25\textwidth} | p{0.25\textwidth} | p{0.25\textwidth} |   p{0.25\textwidth} |}
\hline
Query Structure & The most similar structure & The second most similar structure & The    third most similar structure \\
\hline
\raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_B3LYP_631Gd}} & raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_B3LYP_631Gd}} & \raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_G3MP2B3}} &\raisebox{-.5\height}{\includegraphics[scale=0.2]{GS_Ade_PathwayA_I1A_G3B3}} \\
GS\_Ade\_PathwayA\_I1A\_B3LYP\_631Gd.out1.ar &GS\_Ade\_PathwayA\_I1A\_B3LYP\_631Gd.out1.ar &GS\_Ade\_PathwayA\_I1A\_G3MP2B3.out1.ar &GS\_Ade\_PathwayA\_I1A\_G3B3.out1.ar \\
\hline
\caption{Results Table}
\end{tabular}
\end{center}
\end{table}

By doing above, I got two problems with the result.

  1. The pictures are not centered in each cell. Although I have set the height of the raisbox, the pictures are still closely attached to the upper cell edge.
  2. I have set the width of each column to be 1/4 width of the \textwidth. It worked for the texts in the header. Some long text such as "The second most similar structure" was splited into two rows. However, for the text under the pictures, they were all overlapped. I think Latex consider it as a whole word, so it didn't split into multiple rows.

Can anyone suggest how to solve these problems?

Thank you.

2
  • 1
    Do these figures need to be numbered like a normal figure, possibly cited elsewhere in the doc and/or showing up in a list of figures, or are you merely content with getting unnumbered subtext that functions like a caption? Jun 2, 2014 at 18:54
  • If would be better if these pictures can be cited elsewhere, but it also worked for me just getting these contents as unnumbered subtext. Jun 2, 2014 at 19:11

1 Answer 1

1

This solution only places unnumbered subtext below the figures, just using a separate figure row. If there is no text on the same row with the figures, then a \raisebox approach is not required. Since you didn't provide a minimum working example (MWE), I assumed that the figures were on a row by themselves. I omitted \hline between the titles, the figures, and the subtext, so as to group them more nicely. By using p columns, text wraps automatically.

As David pointed out, one must leave room for column padding separation, so in this case, I only made each column width 0.21\textwidth to avoid overfilling the column width.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{url}
\usepackage{caption}
\begin{document}
\begin{table}[ht]
\begin{center}
\begin{tabular}{|p{.21\textwidth}|p{.21\textwidth}|p{.21\textwidth}|p{.21\textwidth}|}
\hline
 Query Structure & The most similar structure & 
The second most similar structure & The    third most similar structure \\
\includegraphics[width=.21\textwidth]{GS_Ade_PathwayA_I1A_B3LYP_631Gd} &
\includegraphics[width=.21\textwidth]{GS_Ade_PathwayA_I1A_B3LYP_631Gd} & 
\includegraphics[width=.21\textwidth]{GS_Ade_PathwayA_I1A_G3MP2B3} &
\includegraphics[width=.21\textwidth]{GS_Ade_PathwayA_I1A_G3B3}\\
\scriptsize \url{GS_Ade_PathwayA_I1A_B3LYP_631Gd.out1.ar}
& \scriptsize next caption
& \scriptsize third caption
& \scriptsize last caption\\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}

enter image description here


To answer the OP's follow-up, on how to add gap between an \hline and a subsequent row of \includegraphics images, which are otherwise flush with the \hline, there are many approaches. The one I adopt is to use the \addvbuffer[top_gap bottom_gap]{...} macro from my verbatimbox package. One merely need apply this to the tallest image of the row. Here, I re-present the MWE with the \hlines added, and an \addvbuffer in place.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{url}
\usepackage{caption}
\usepackage{verbatimbox}
\begin{document}
\begin{table}[ht]
\begin{center}
\begin{tabular}{|p{.21\textwidth}|p{.21\textwidth}|p{.21\textwidth}|p{.21\textwidth}|}
\hline
Query Structure & The most similar structure & 
The second most similar structure & The    third most similar structure \\
\hline
\addvbuffer[4pt 0pt]{\includegraphics[width=.21\textwidth]{GS_Ade_PathwayA_I1A_B3LYP_631Gd}} &
\includegraphics[width=.21\textwidth]{GS_Ade_PathwayA_I1A_B3LYP_631Gd} &
\includegraphics[width=.21\textwidth]{GS_Ade_PathwayA_I1A_G3MP2B3} &
\includegraphics[width=.21\textwidth]{GS_Ade_PathwayA_I1A_G3B3}\\
\hline
\scriptsize \url{GS_Ade_PathwayA_I1A_B3LYP_631Gd.out1.ar}
& \scriptsize next caption
& \scriptsize third caption
& \scriptsize last caption\\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}

enter image description here

13
  • }{|p{.25\textwidth}|p{.25\textwidth}|p{.25\textwidth}|p{.25\textwidth}|} is overfull by 8\tabcolsep + 5\arrayrulewidth Jun 2, 2014 at 19:25
  • @DavidCarlisle Yeah, I knew that... Will adjust Jun 2, 2014 at 19:27
  • I guess I didn't explain my problem clearly. I knew by using p columns, texts will wraps automatically. But for my case, the text I want to put under the pictures is like "GS_Ade_PathwayA_I1A_B3LYP_631Gd.out1.ar".(some cases may even longer) It won't warps automatically. I think Latex consider it as a whole word, so it doesn't wrap it. They were all in one line and overlaps. Jun 2, 2014 at 19:35
  • @user3293338 See revision. You need the url package. Jun 2, 2014 at 19:37
  • @user3293338 put \linebreak[0] after each _ or anywhere else you want to allow a break (or url package as Steven just said, but that's optimised for breaking on / and . so you might need to change some of its defaults) Jun 2, 2014 at 19:38

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.