Math & ScienceSubfig with Figure and table

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
niklz
Posts: 9
Joined: Sun Jan 24, 2010 9:51 pm

Subfig with Figure and table

Post by niklz »

Hi there,

I got another problem for you TeX-JunXies out there :).

I'm trying to have a table and figure side-by-side using the subfig package. For some reason the subfloats aren't compatible like 2 figures are.

Heres the code

Code: Select all

\begin{figure}[h]
\begin{center}
\subfloat{%
\label{fig:subassembly}\includegraphics[width=0.45\textwidth]{subassembly.eps}}
\hspace{0.01cm}
\subfloat{%
\label{tab:subkey}
		\begin{tabular}[h]{r|l}
			No.& Apparatus\\
			\hline
			\hline
			1		 				& Pole Pieces\\
			2		 				& SPH \& Caps\\
			3		 				& Sample\\
			4		 				& $\nicefrac{\pi}{2}$-Pulse\\
			5		 				& $Q$-Damping\\
		\end{tabular}}
		\end{center}
\caption{Sub-Assembly: Exploded view of sub-assembly \& key. Adapted from\citep{LDNMR}}
\label{fig:subassemandkey}
\end{figure}
The output issue is that it will not sit on the same horizontal axis, it overlaps but leaves massive white spaces in the unused corners.

Any help would be massively appriciated

Kind regards,

niklz

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Subfig with Figure and table

Post by sommerfee »

When using the subcaption package (instead of the subfig package) this works fine here:

Code: Select all

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{nicefrac,natbib}
\usepackage{caption,subcaption}
\begin{document}
\begin{figure}[h]
\centering
\subfloat[\label{fig:subassembly}]{%
  \includegraphics[width=0.45\textwidth]{subassembly.eps}}
\hspace{0.01cm}
\subfloat[\label{tab:subkey}]{%
      \begin{tabular}[h]{r|l}
         No.& Apparatus\\
         \hline
         \hline
         1                   & Pole Pieces\\
         2                   & SPH \& Caps\\
         3                   & Sample\\
         4                   & $\nicefrac{\pi}{2}$-Pulse\\
         5                   & $Q$-Damping\\
      \end{tabular}}
\caption{Sub-Assembly: Exploded view of sub-assembly \& key. Adapted from\citep{LDNMR}}
\label{fig:subassemandkey}
\end{figure}
\end{document}
niklz
Posts: 9
Joined: Sun Jan 24, 2010 9:51 pm

Re: Subfig with Figure and table

Post by niklz »

Thanks for the reply, the issue is half fixed.

Using subcaption works unless you make the image large enough that it is taller than the table. Which is something I wish to do..

I'm trying to use this code from the visual LaTeX FAQ:

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=topgraph


So they will top align, as opposed to the default bottom align.

Any ideas?

niklz
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Subfig with Figure and table

Post by gmedina »

Perhaps something like the following?

Code: Select all

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{nicefrac,natbib}
\usepackage{caption,subcaption}

\begin{document}

\begin{figure}[!ht]
\hbox{\hskip1cm%
  \vtop{\vskip0pt%
    \hbox{%
      \subfloat[\label{fig:subassembly}]{%
        \includegraphics[width=0.4\textwidth]{subassembly.eps}%
      }%
    }%
  }\hskip1cm%
  \vtop{\vskip0pt
    \subfloat[\label{tab:subkey}]{%
      \begin{tabular}[h]{r|l}
         No.& Apparatus\\
         \hline
         \hline
         1                   & Pole Pieces\\
         2                   & SPH \& Caps\\
         3                   & Sample\\
         4                   & $\nicefrac{\pi}{2}$-Pulse\\
         5                   & $Q$-Damping\\
      \end{tabular}%
    }%
  }%
}
\caption{Sub-Assembly: Exploded view of sub-assembly \& key. Adapted from\citep{LDNMR}}
\label{fig:subassemandkey}
\end{figure}

\end{document}
Depending on the real width of your image you might need to do some minor modifications to some of the dimensions used.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
niklz
Posts: 9
Joined: Sun Jan 24, 2010 9:51 pm

Re: Subfig with Figure and table

Post by niklz »

Thanks alot, that sorted the top alignment out, however that doesn't look much better in the end after all!

Is there a centre align function?

kind regards

niklz
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Subfig with Figure and table

Post by gmedina »

niklz wrote:...Is there a centre align function?..
Yes, of course. You could manipulate boxes in order to vertically center the two subfloats; however, I would suggest you to use the features provided by the floatrow package to easily achieve the desired layout.

Edit: just for the record, here's a possible use of boxes to produce vertical alignment (assuming that the image height is grater than the table's):

Code: Select all

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{nicefrac,natbib}
\usepackage{caption,subcaption}

\begin{document}

% boxing the image to record its height
\setbox0=\hbox{%
  \includegraphics[width=0.4\textwidth]{subassembly.eps}%
}
\newdimen\fght
\fght=\ht0

\begin{figure}[!ht]
\centerline{%
\hbox{%\hskip1cm%
  \vbox{\vskip0pt%
    \hbox{%
      \subfloat[\label{fig:subassembly}]{%
        \box0%  using the box that contains the image
      }
    }%
  }\hskip1cm%
  \vbox to \fght{\vskip0pt\vfil
    \hbox{\subfloat[\label{tab:subkey}]{%
    \begin{tabular}[h]{r|l}
         No.& Apparatus\\
         \hline
         \hline
         1                   & Pole Pieces\\
         2                   & SPH \& Caps\\
         3                   & Sample\\
         4                   & $\nicefrac{\pi}{2}$-Pulse\\
         5                   & $Q$-Damping\\
    \end{tabular}}%
    }\vfil%
  }%
}
}
\caption{Sub-Assembly: Exploded view of sub-assembly \& key. Adapted from\citep{LDNMR}}
\label{fig:subassemandkey}
\end{figure}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply