3

I wrote the following code to make a table and a figure appear side by side:

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage{capt-of}% or \usepackage{caption}
    \usepackage{booktabs}
    \usepackage{varwidth}

    \begin{document}
    \begin{table}[ht]
    \begin{minipage}[t]{0.4\linewidth}
        \centering
        \begin{tabular}{|l l|}
            \hline
                2 Amenity & 3 Barrier \\ 
                4 Boundary & 5 Building  \\ 
                6 Craft & 7 Emergency \\ 
                8 Geological & 9 Highway \\ 
                10 Historic & 11 Landuse \\ 
                12 Leisure & 13 Man made \\ 
                14 Military & 15 Natural \\ 
                16 Office & 17 Place \\ 
                18 Power & 19 Transport \\ 
                20 Railway & 21 Route \\ 
                22 Shop & 23 Sport \\ 
                24 Tourism & 25 Waterway \\ 
                26 Aerialway & 27 Aeroway \\ 
            \hline 
        \end{tabular}
    \end{minipage}\hfill
    \begin{minipage}[t]{0.4\linewidth}
        \centering
        \includegraphics[scale=0.35]{OSMTreeDendrogram.png}
    \end{minipage}
    \caption{Tree representation of localities and their location types given by the Open Street Map.}
    \label{OSM_tree}
\end{table}
    \end{document}

It works, but they are not at the same height. They appear like this:

enter image description here

How do I make the table start at the same height as the figure?

4

try the following MWE:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{capt-of}% or \usepackage{caption}
\usepackage{booktabs}
\usepackage{varwidth}

\usepackage[export]{adjustbox}

\begin{document}
\begin{table}[ht]
\begin{tabular}{cc}
    \begin{tabular}{|l l|}
        \hline
    2 Amenity       & 3 Barrier \\
    4 Boundary      & 5 Building  \\
    6 Craft         & 7 Emergency \\
    8 Geological    & 9 Highway \\
    10 Historic     & 11 Landuse \\
    12 Leisure      & 13 Man made \\
    14 Military     & 15 Natural \\
    16 Office       & 17 Place \\
    18 Power        & 19 Transport \\
    20 Railway      & 21 Route \\
    22 Shop         & 23 Sport \\
    24 Tourism      & 25 Waterway \\
    26 Aerialway    & 27 Aeroway \\
        \hline
    \end{tabular}
&
\includegraphics[scale=0.35,valign=m]{OSMTreeDendrogram.png}
\end{tabular}
\caption{Tree representation of localities and their location types given by the Open Street Map.}
\label{OSM_tree}
\end{table}
\end{document}

Instead of minipages I usetabular environment and for vertical align option valign=m from package adjustbox. Is this what you looking for?

enter image description here

Addendum: if you like to have vertically aligned the top of table and image (I overlooked this in your question, sorry) than you need to change:

  • \begin{tabular}{|l l|} to \begin{tabular}[t]{|l l|} and
  • \includegraphics[scale=0.35,valign=m]{OSMTreeDendrogram.png} to \includegraphics[scale=0.35,valign=T]{OSMTreeDendrogram.png}.

Result is then the following:

enter image description here

I prefer the first solution :)

  • It doesn't make the 2 floats start from the same height, but at least now it looks better than what I had. – Kristada673 Jul 3 '17 at 19:05
  • @Kristada673, see addendum to my answer. Not table in image are aligned at the top. – Zarko Jul 3 '17 at 19:19
0

Another sample code (with an option to resize the table) which places a table and figure side by side.

  \begin{table}[h]
    \centering
    \begin{tabular}{ccccccc}
      \resizebox{0.5\textwidth}{!}{
        \begin{tabular}{|l|l|l|l|l|l|l|}
          \hline
          Test 1 & 0 & 1 & 2 & 3 & 4 & Test 2 \\
          \hline
          0 & 224 &  &  &  &  & 224\\
          \hline
          1 & 58 & 57 &  &  &  & 115\\
          \hline
          2 & 26 & 27 & 27  &  &  & 80\\
          \hline
          3 & 16 & 16 & 15 & 15 &  & 62\\
          \hline
          4 & 10 & 10 & 11 & 10 & 10 & 51\\
          \hline
        \end{tabular}
      }
      \includegraphics[scale=0.35, valign=m]{fig.png}
    \end{tabular}
    \caption*{Table with data and its graph shown side by side}
    \label{tab:data_and_fig}
  \end{table}

It should look like this now.

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.