1

this is my first post here. Although I use (or try to) Latex for a while, I am a beginner and I am struggling with basic stuff. I read other solutions for the type of problem I am having and I still cannot solve it.

I am getting a warning whenever I use \tabularx. The main problem is that it seems to be messing up with the number of the tables as well.

I am using:

\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}

\usepackage[myheadings]{fullpage}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{tabularx,ragged2e}
\usepackage{booktabs}
\usepackage{ltablex}
%\usepackage[table,xcdraw]{xcolor}
%\usepackage[margin=1in]{geometry}
%\usepackage[demo]{graphicx}
\usepackage{subcaption}
\usepackage{float}
\usepackage{adjustbox}
%\usepackage[margin=20pt]{subfig}
\usepackage{lscape}
\usepackage{graphicx}
\usepackage{makecell}
\usepackage{enumitem}
\usepackage{ragged2e}

\begin{document}

\section{test}

\begin{table}[H]
  \centering
    \caption{Treatment's description.}
    \begin{tabularx}{\textwidth}{XX}
    \toprule
\multicolumn{1}{c}{\textbf{Variable} \textbf{(Type)}} &
\multicolumn{1}{c}{\textbf{Description} \textbf{(States)}} 
\endhead    
       \midrule 
%
Treatment (Labelled)&
The treatment used during the pregnancy: None for GDM negative people, Diet for GDM positive people that never had any medication to control BGL during pregnancy and Medication for GDM positive people that had medication at any point during the pregnancy. (None, Diet and Medication)\\

    \bottomrule
    \end{tabularx}%
  \label{tab:treatmenttable}%
\end{table}%

\begin{table}[H]
  \centering
    \caption{Signs' description.}
    \begin{tabularx}{\textwidth}{lX}
    \toprule
\multicolumn{1}{c}{\textbf{Variable} \textbf{(Type)}} &
\multicolumn{1}{c}{\textbf{Description} \textbf{(States)}} 
\endhead    
       \midrule 
%
%
BGL before 20 weeks (Labelled) & Blood glucose level before 20 weeks. (Normal, Abnormal) \\
BGL after 20 weeks (Labelled) & Blood glucose level after 20 weeks. (Normal, Abnormal) \\

    \bottomrule
    \end{tabularx}%
  \label{tab:signstable}%

\end{table}%


\end{document}

enter image description here

5
  • 1
    Welcome to TeX.SE! Can you please make your code snippet be compilable, then we do not have to guess what you are doing ...
    – Mensch
    Oct 8, 2021 at 1:26
  • Warnings like Underfull \vbox (badness 1000) can be ignored without much affecting your output-- so far as my experience goes.
    – Partha D.
    Oct 8, 2021 at 2:37
  • 1
    What is \endhead doing inside your tabularx? \endhead is usually only used in tables that span multiple pages, such as ones that are created using longtable or xltabular. Please also make your code compilable by adding the documentclass as well as the relevant packages. Please also explain what "messing up with the number of the tables" means specifically. What kind of numbering do you expect instead of the one you currently get?
    – leandriis
    Oct 8, 2021 at 6:05
  • 1
    Laslt,y there is a \\ missing at the end of your header row and right before the following \midrule.
    – leandriis
    Oct 8, 2021 at 6:07
  • 1
    Problem, which you faced is use of ltablex package. Since your tables is inside of table float, you not need this package (which is combination of longtable and tabularx. In preamble add tabularx packag, remove ltablex package and command \endhead from tables codes. After this you will get desired result. Instead ltablex i suggest to use xltabular or recent version of tabularray . BTW, from preamble remove all duplicate loaded packages.
    – Zarko
    Oct 8, 2021 at 20:53

1 Answer 1

1

The cause of your problems and cure for them are explained in comments below your question.

However, your problems can be avoided by us of the tabularray package in your document. Tables written by it, using X[...] column types behave similar as tabularx tables. Followed MWE works with tabullarray package version 2021P or newest:


\documentclass[12pt]{report}
\usepackage[myheadings]{fullpage}
\usepackage[skip=1ex]{caption}

\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\usepackage{lipsum} % for dummy text


\begin{document}

\section{Test}
Use of \verb+booktabs+ table environment as defined in the \verb+tabularray+ package:
    \begin{table}[ht]
    \caption{Treatment's description.}
    \label{tab:treatmenttable}
\begin{booktabs}{colspec = X[l] X[j],
                 row{1} = {font=\bfseries, c},
                }
    \toprule
Variable (Type) & Description (States)  \\
    \midrule
Treatment (Labelled)
    &   The treatment used during the pregnancy: None for GDM negative people, Diet for GDM positive people that never had any medication to control BGL during pregnancy and Medication for GDM positive people that had medication at any point during the pregnancy. (None, Diet and Medication)\\
    \bottomrule
\end{booktabs}
    \end{table}
    
Use of \verb+longtblr+ table environment as defined in the \verb+tabularray+ package:

\begin{longtblr}[
caption = {Signs’ description.},
  label = {tab:signstable},
                ]{colspec = l X[j],
                  rowhead=1, 
                  row{1} = {font=\bfseries, c},
                }
    \toprule
Variable (Type) & Description (States)  \\
    \midrule
BGL before 20 weeks (Labelled) & Blood glucose level before 20 weeks. (Normal, Abnormal) \\
BGL after 20 weeks (Labelled)  & Blood glucose level after 20 weeks. (Normal, Abnormal) \\
    \midrule
just dummy filler               & \lipsum[65]    \\
just dummy filler               & \lipsum[66]    \\
just dummy filler               & \lipsum[67]    \\
    \bottomrule
\end{longtblr}

\end{document}

enter image description here

Addedndum: Of course you can use classic tables packages. For example use of the xltabular also gives desired document format. A tables codes are abit longer as at tabularray package:


\documentclass[12pt]{report}
\usepackage[myheadings]{fullpage}
\usepackage[skip=1ex]{caption}

\usepackage{booktabs, makecell, xltabular}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}

\usepackage{lipsum} % for dummy text


\begin{document}

\section{Test}
Use of \verb+tabularx+ table environment which is loaded by \verb+xltabular+ package:
    \begin{table}[ht]
    \caption{Treatment's description.}
    \label{tab:treatmenttable}
\begin{tabularx}{\linewidth}{XX}
    \toprule
\multicolumn{1}{c}{\thead{Variable (Type)}} 
    & \multicolumn{1}{c}{\thead{Description (States)}}  \\
    \midrule
Treatment (Labelled)
    &   The treatment used during the pregnancy: None for GDM negative people, Diet for GDM positive people that never had any medication to control BGL during pregnancy and Medication for GDM positive people that had medication at any point during the pregnancy. (None, Diet and Medication)\\
    \bottomrule
\end{tabularx}
    \end{table}
    
Use of \verb+xltabular+ table environment:

\begin{xltabular}{\linewidth}{lX}
\caption{Signs’ description.}
\label = {tab:signstable}\\
    \toprule
\multicolumn{1}{c}{\thead{Variable (Type)}}
    & \multicolumn{1}{c}{\thead{Description (States)}}  \\
    \midrule
\endfirsthead
\caption[]{Signs’ description (cont.).} \\
    \toprule
\multicolumn{1}{c}{\thead{Variable (Type)}}
    & \multicolumn{1}{c}{\thead{Description (States)}}  \\
    \midrule
\endhead
    \midrule
\multicolumn{2}{r}{\footnotesize\textit{Continue on the next page}}
\endfoot
    \bottomrule
\endlastfoot
% table body
BGL before 20 weeks (Labelled) & Blood glucose level before 20 weeks. (Normal, Abnormal) \\
BGL after 20 weeks (Labelled)  & Blood glucose level after 20 weeks. (Normal, Abnormal) \\
    \midrule
just dummy filler               & \lipsum[65]    \\
just dummy filler               & \lipsum[66]    \\
just dummy filler               & \lipsum[67]    \\
\end{xltabular}

\end{document}

Result is(almost) the same as before.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .