Graphics, Figures & Tablessubfig | Caption Alignment of Table and Figure Sub-floats

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
drobinson
Posts: 3
Joined: Tue Oct 25, 2011 7:33 am

subfig | Caption Alignment of Table and Figure Sub-floats

Post by drobinson »

I'm somewhat new to latex, so this is probably some simple misunderstanding, but I am trying to create a figure with a subfloat figure and a subfloat table side-by-side. However I am having difficulties making the captions align properly

When I compile the following code the caption for the table lies slightly below the caption for the figure. However, if I add a \hline after the last table row the captions align perfectly. Is there anyway I can make the captions align without adding the line at the bottom of the table?

\documentclass{report}
\usepackage{subfig}

\begin{document}

\begin{figure}[h!]
\centering
\subfloat[A figure left of a table]{
\rule{6.4cm}{3.6cm}
}\qquad
\subfloat[Truth Table]{
\begin{tabular}{ c c || c c }%
E & X & D & D\\%
\hline%
0 & 0 & 0 & 0\\%
0 & 1 & 0 & 0\\%
1 & 0 & 0 & 1\\%
1 & 1 & 1 & 0\\
\end{tabular}
}
\end{figure}

\end{document}

Any help would be greatly appreciated :)

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

drobinson
Posts: 3
Joined: Tue Oct 25, 2011 7:33 am

subfig | Caption Alignment of Table and Figure Sub-floats

Post by drobinson »

Here is what the problem looks like. I have been searching around online and can't seem to find any explanation as to why this is happening.
alignment-figure-table-01.png
alignment-figure-table-01.png (9.47 KiB) Viewed 5126 times
This is what it looks like if I add an hline at the end of the table. Notice how the captions are properly aligned.
alignment-figure-table-02.png
alignment-figure-table-02.png (9.3 KiB) Viewed 5126 times
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

subfig | Caption Alignment of Table and Figure Sub-floats

Post by sommerfee »

Since the alignment is ok when using my subcaption package I assume it's a bug in the subfig package:

Code: Select all

\documentclass{report}
\usepackage{caption,subcaption}

\begin{document}

\begin{figure}[h!]
\centering
\subcaptionbox{A figure left of a table}{
 \rule{6.4cm}{3.6cm}
 }\qquad
\subcaptionbox{Truth Table}{
\begin{tabular}[b]{ c c || c c }%
 E & X & D & D\\%
 \hline%
 0 & 0 & 0 & 0\\%
 0 & 1 & 0 & 0\\%
 1 & 0 & 0 & 1\\%
 1 & 1 & 1 & 0\\
\end{tabular}
}
\end{figure}

\end{document}
So either correct the position of the table using \raisebox or similar, or use the subcaption package instead. (Sorry for the shameless self-advertisement.)

Additionally, I would drop a short bug report to the maintainer of the subfig package.
drobinson
Posts: 3
Joined: Tue Oct 25, 2011 7:33 am

Re: subfig | Caption Alignment of Table and Figure Sub-floa

Post by drobinson »

Thanks for the reply. No harm in advertising something that works. I will give the subcaption package a try, and most likely being submitting a bug to the maintainer of subfig.
Post Reply