1

I am using "subfloat" to visualize both an image and a table inside the same figure as follows:

\begin{figure}
\centering
\subfloat[Summary statistics\label{subfig-1:tab}]{%
  \begin{tabular}{|l|r|}\hline
            \textbf{Min.}           & 0      \\ \hline
            \textbf{1st Qu.}        & 0             \\ \hline
            \textbf{Median}         & 0         \\ \hline
            \textbf{Mean}           & 88.37  \\ \hline
            \textbf{3rd Qu.}        & 0         \\ \hline
            \textbf{Max.}           & 4356          \\ \hline
            \textbf{Std}        & 404.3     \\ \hline                
        \end{tabular}
}
\hfill
\subfloat[Histogram\label{subfig-2:histogram}]{%
  \includegraphics[width=0.60\textwidth]{capital_loss_histogram.pdf}
}
\caption{Summary statistics and histogram of the attribute capital-loss}
\label{fig:attribute_capital-loss}
\end{figure}

The problem is that the image is not displayed at the same level as the table, as in the following image:

The problem

How can I fix this?

  • 2
    use [b] on the tabular, as in \begin{tabular}[b]{|l|r|}\hline – Steven B. Segletes Sep 30 '13 at 12:32
  • @StevenB.Segletes Please, make an answer – egreg Sep 30 '13 at 22:23
2

The problem arises because \includegraphics sets the bottom of the image along the baseline of the text, whereas, by default, the tabular environment puts the center of the table along the baseline. This will make the tabular hang lower than the graphic. The default alignment of the tabular can be changed with the optional argument [b], which tells LaTeX to place the bottom of the table along the baseline, which is the same alignment as the graphic. Here is the result:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\centering
\subfloat[Summary statistics\label{subfig-1:tab}]{%
  \begin{tabular}[b]{|l|r|}\hline
            \textbf{Min.}           & 0      \\ \hline
            \textbf{1st Qu.}        & 0             \\ \hline
            \textbf{Median}         & 0         \\ \hline
            \textbf{Mean}           & 88.37  \\ \hline
            \textbf{3rd Qu.}        & 0         \\ \hline
            \textbf{Max.}           & 4356          \\ \hline
            \textbf{Std}        & 404.3     \\ \hline                
        \end{tabular}
}
\hfill
\subfloat[Histogram\label{subfig-2:histogram}]{%
  \includegraphics[width=0.60\textwidth]{capital_loss_histogram.pdf}
}
\caption{Summary statistics and histogram of the attribute capital-loss}
\label{fig:attribute_capital-loss}
\end{figure}
\end{document}

enter image description here

  • It worked perfectly. Very good explanation! – markusian Oct 1 '13 at 12:31

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.