Graphics, Figures & TablesTabularx captioning above table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jaykemper
Posts: 22
Joined: Wed Apr 15, 2009 12:11 am

Tabularx captioning above table

Post by jaykemper »

I'm trying to put a caption above a tabularx environment.

Code: Select all

\begin{tabularx}{\textwidth}{cXcX}
\caption{The caption}\\
contents&of&the&table\\
\end{tabularx}
That produces a table that does NOT stretch the X columns (equivalent to clcl). Embedding the tabularx in a table environment causes the numbering to skip (1,3,5,etc).

Any suggestions?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Tabularx captioning above table

Post by localghost »

Please provide a small, complete and compilable, shortly spoken a minimal working example (MWE). The following doesn't cause any trouble.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs,tabularx}
\usepackage{blindtext}

\begin{document}
  \blindtext

  \begin{table}[!ht]
    \caption{Dummy table}\label{tab:dummy-1}
    \begin{tabularx}{\textwidth}{cXcX}\toprule
      contents & of & the & table \\ \bottomrule
    \end{tabularx}
  \end{table}

  \blindtext

  \begin{table}[!ht]
    \caption{Dummy table}\label{tab:dummy-2}
    \begin{tabularx}{\textwidth}{cXcX}\toprule
      contents & of & the & table \\ \bottomrule
    \end{tabularx}
  \end{table}

  \blindtext

  \begin{table}[!ht]
    \caption{Dummy table}\label{tab:dummy-3}
    \begin{tabularx}{\textwidth}{cXcX}\toprule
      contents & of & the & table \\ \bottomrule
    \end{tabularx}
  \end{table}

  \blindtext
\end{document}
Refer to the manuals of the used packages.


Best regards
Thorsten
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Tabularx captioning above table

Post by gmedina »

Hi,

using the table environment should work, as the following simple example illustrates:

Code: Select all

\documentclass{article}
\usepackage{tabularx}

\begin{document}

\begin{table}[!ht]
  \centering
  \caption{The normal table caption}
  \label{tab:test1}
  \rule{4cm}{2cm}% to simulate a table
\end{table}

\begin{table}[!ht]
  \caption{The tabularx caption}
  \label{tab:testx}
  \begin{tabularx}{\textwidth}{cXcX}
    contents&of&the&table\\
  \end{tabularx}
\end{table}

\begin{table}[!ht]
  \centering
  \caption{The normal table caption}
  \label{tab:test2}
  \rule{4cm}{2cm}% to simulate a table
\end{table}

\end{document}
If you are getting unexpected results, please provide a minimal working example showing any undesired behaviour.

Another option, instead of using a table environment, would be to use the \captionof command provided by the caption package.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
jaykemper
Posts: 22
Joined: Wed Apr 15, 2009 12:11 am

Tabularx captioning above table

Post by jaykemper »

I worked with your example, and the issue is something is happening with the package "ltablex", which combines the longtable characteristics with "tabularx"

MWE

Code: Select all

\documentclass{article}
\usepackage{tabularx}
\usepackage{ltablex}

\begin{document}
  Here's some text

  \begin{table}[!ht]
  \caption{Dummy table}\label{dummy-1}
    \begin{tabularx}{\textwidth}{cXcX}
       contents & of & the & table
    \end{tabularx}
  \end{table}

  Here's some text

  \begin{table}[!ht]
  \caption{Dummy table}\label{dummy-2}
    \begin{tabularx}{\textwidth}{cXcX}
       contents & of & the & table
    \end{tabularx}
  \end{table}

  Here's some text

  \begin{table}[!ht]
  \caption{Dummy table}\label{dummy-3}
    \begin{tabularx}{\textwidth}{cXcX}
       contents & of & the & table
    \end{tabularx}
  \end{table}

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

Tabularx captioning above table

Post by gmedina »

Since you are using the ltablex package, suppress the table environments:

Code: Select all

\documentclass{article}
\usepackage{tabularx}
\usepackage{ltablex}

\begin{document}

Here's some text

\begin{tabularx}{\textwidth}{cXcX}
  \caption{Dummy table}\label{dummy-1}\\
   contents & of & the & table
\end{tabularx}

  Here's some text

\begin{tabularx}{\textwidth}{cXcX}
  \caption{Dummy table}\label{dummy-2}\\
  contents & of & the & table
\end{tabularx}

Here's some text

\begin{tabularx}{\textwidth}{cXcX}
  \caption{Dummy table}\label{dummy-3}\\
  contents & of & the & table
\end{tabularx}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Tabularx captioning above table

Post by localghost »

I hope you now understand the significance of a MWE.
Post Reply