Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm simply trying to get a table on the right side of my text. I've tried many different packages like float, floatflt, and wrapfig, the latter got me the closest to what I wanted. My only issue at this point is that the caption says "Figure 1:" Whereas it should be a table. I can't use \begin{table} with \begin{wrapfig} since it screws things up.

Here is the full code for the table:

\begin{wrapfigure}{r}{0.24\textwidth}
\centering
\begin{tabular}{ | c || c | c | }
    \hline
      & a & b \\
    \hline \hline
    1 & 1 & 2 \\
    \hline
    2 & 3 & 2 \\
    \hline
    3 & 1 & 2 \\
    \hline
\end{tabular}
\caption{Table representation of the DFA in Figure \ref{fig:dfa_example}}
\label{DFA_table}
\end{wrapfigure}

As a side note, would it also be possible to get the table to be a little higher than the text (top margin)?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

This is perhaps just informative in terms of float and caption interaction (even on a small scale such as in the original post).

The caption used inside a floating environment, including that of wrapfig checks \@captype in order to set the appropriate caption. You can modify \@captype to be table to obtain the appropriate caption style. For this, add

\makeatletter
\def\@captype{table}
\makeatother

before your \caption command. Using wraptable instead (as in Gonzalo's answer) is preferred, since it removes this kind of detail from the user interface. Why would you want to do this? Perhaps, instead of a wraptable, you have a small algorithm that you want to display but wrapfig does not provide a wrapalgorithm environment.

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{wrapfig}% http://ctan.org/pkg/wrapfig
\begin{document}
\begin{wrapfigure}{r}{0.24\textwidth}
  \centering
  \begin{tabular}{ | c || c | c | }
    \hline
      & a & b \\
    \hline \hline
    1 & 1 & 2 \\
    \hline
    2 & 3 & 2 \\
    \hline
    3 & 1 & 2 \\
    \hline
  \end{tabular}
  \makeatletter\def\@captype{table}\makeatother% "Change float to table"
  \caption{Table representation of the DFA in Figure 2.}
  \label{DFA_table}
\end{wrapfigure}
\lipsum[1]

\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

For vertical displacement, you can add

\vspace*{<len>}

where <len> is a negative length at the start of your wrapfig. This will move it up a bit. For example, using \vspace*{-.5\baselineskip} will move it up half a line.

share|improve this answer
add comment

Use wraptable instead:

\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}% just to generate text for the example

\begin{document}

\begin{wraptable}{r}{0.24\textwidth}
\centering
\begin{tabular}{ | c || c | c | }
    \hline
      & a & b \\
    \hline \hline
    1 & 1 & 2 \\
    \hline
    2 & 3 & 2 \\
    \hline
    3 & 1 & 2 \\
    \hline
\end{tabular}
\caption{Table representation of the DFA in Figure \ref{fig:dfa_example}}
\label{DFA_table}
\end{wraptable}
\lipsum[1-2]

\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.