\vbox 未满(tabularx 中 badness 为 1000,文本中会自动调整断点

\vbox 未满(tabularx 中 badness 为 1000,文本中会自动调整断点

这是我在这里的第一篇帖子。虽然我使用(或尝试)Latex 有一段时间了,但我还是个初学者,还在努力学习基础知识。我读过其他解决方案来解决这个问题,但我仍然无法解决。

每次使用 \tabularx 时,我都会收到警告。主要问题是它似乎也弄乱了表格的数量。

我在用:

\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}

在此处输入图片描述

答案1

您问题的原因及其解决方法已在问题下方的评论中解释。

tabularray但是,我们可以在您的文档中使用包来避免您的问题。由它编写的表格,使用X[...]列类型,行为与表格类似tabularx。以下 MWE 适用于tabullarray包版本 2021P 或最新版本:


\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}

在此处输入图片描述

附註: 当然,您可以使用经典的表格包。例如,使用 xltabular也可以提供所需的文档格式。表格代码稍长一些,如tabularray​​包中所示:


\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}

结果(几乎)与以前相同。

相关内容