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 am attempting to add a caption to a non-float environment.

The following is a MWE of how I'm trying to do it:

\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{tabular}{l|l}
     hello & world
\captionof{table}{my table}
\end{tabular}
\end{document}

However, this is not working for me.

What am I doing wrong?

share|improve this question
add comment

1 Answer

up vote 12 down vote accepted

The \captionof command must go outside the tabular environment. You may put tabular plus \captionof inside a minipage environment to avoid a page break between the table and its caption.

\documentclass{article}
\usepackage{caption}
\begin{document}
\begin{minipage}{\textwidth}
\centering
\begin{tabular}{l|l}
     hello & world
\end{tabular}
\captionof{table}{my table}
\end{minipage}
\end{document}
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.