表格离开页面并且无法编译

表格离开页面并且无法编译

我正在写一张表格但它一直离开页面。

\begin{center}
    \begin{tabular}{ |c|c|c|c| } 
    \hline
    \textbf{Type} & \textbf{Problem} & \textbf{Fix} \\
    \hline
    \multirow{6}{*}{\textbf{Inconsistency}} & cell & \textbf{cell} \\ \cline{2-3}
    & cell. & cell6 \\ \cline{2-3}
    & cell8 & cell9 \\ \cline{2-3}
    & cell8 & cell9 \\ \cline{2-3}
    & cell8 & cell9 \\ \cline{2-3}
    & cell8 & cell9 \\ \cline{2-3}
    \hline
    \end{tabular}
\end{center}

每当我填满单元格时,表格就会延伸到页面的右侧。我改用表格生成器,它生成了以下内容:

% Please add the following required packages to your document preamble:
% \usepackage{multirow}
\begin{table}[]
  \begin{tabular}{lll}
    \textbf{Type}                           & \textbf{Problem}                                                                                                          & \textbf{Fix}                                                                                                                                                                 \\
    \multirow{6}{*}{\textbf{Inconsistency}} & Some records have missing data for all UPDRS-III variables.                                                               & Remove these records                                                                                                                                                         \\
                                            & A few records have PDSTATE=ON and PDTRTMNT=0, which is inconsistent:                                                      & Set PDTRTMNT=1 for these records. It doesn't seem realistic that a plausible PDMEDTM and PDSTATE=ON have been entered by mistake while the patient was not under medication. \\
                                            & Some records have a non-empty PDMEDTM and have PDTRTMNT=0, which is inconsistent.                                         & Set PDTRTMNT=1. It is unlikely that a plausible medication time was entered by mistake.                                                                                      \\
                                            & Some patients were on medication at screening time while PPMI patients were supposed to be unmedicated at screening time. & \textbf{Keep the records. Maybe the patients started medication between recruitment and screening time.}                                                                     \\
                                            & Some records have PDSTATE=ON but PDMEDTM is after EXAMTM.                                                                 & \textbf{Discard the records.}                                                                                                                                                \\
                                            & Some visits have 3 exams while a maximum of two exams per visit are expected, one in OFF state and one in ON state.       & Remove exam with EXAMTM=NaN and PDSTATE=NaN  when visit has 3 exams                                                                                                          \\
                                            &                                                                                                                           &
  \end{tabular}
\end{table}

但是,我收到这些错误:

在此处输入图片描述

编辑:文档类别

\documentclass[12pt]{report}
\include{config}
\include{constants}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\include{pages/abstract}
\include{pages/acknowledgements}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Body of Thesis goes here.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%To inlcude new chapter add "\include{chapters/chapter-no/chapter-no.tex"
\include{chapters/chapter1/chapter1}
\include{chapters/chapter2/chapter2}
\include{chapters/chapter3/chapter3}
\include{chapters/chapter4/chapter4}
\include{chapters/chapter5/chapter5}

% Appendix
\appendix
\include{chapters/appendix/appendix}

%You can edit your citation style by changing the name in \bibliographystyle{plain} --> \bibliographystyle{new style name}
\bibliographystyle{plain}
%Add the bibilography file name below
\bibliography{bibfile}

\end{document}

答案1

我只关注表格,因为它是你问题的一个主题。

表格超出页面的原因在于文本和l类型列的长度,如果超出页面边界,则不会换行。一种解决方案是应用p{width}(及其变体 sam{}b{})来创建固定列,这样可以换行较长的文本。

此外,按照您的方法,表格有 3 列。第一列只包含一行长文本,占用大量空间,其他两列可以使用这些空间,因为它们包含长段落。我会将“不一致”一词移到顶部,并将问题/修复排列在单独的行中。

“不一致”可以旋转以减小第一列的大小,并使所有内容保持与原始布局相似。您可以考虑垂直渲染整个表格;只需将table[tbh]环境更改为sidewaystable(需要加载rotating)。

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{mathtools}
\usepackage{caption}

\renewcommand\tabularxcolumn[1]{>{\raggedright\arraybackslash}p{#1}}


\begin{document}
\begin{center}
  \renewcommand\arraystretch{1.25}
  \begin{tabularx}{\textwidth}{p{1.7cm}X}
    \toprule
    \multicolumn{2}{c}{\textbf{Inconsistency}} \\
    \midrule[\heavyrulewidth]
    \textbf{Problem:} & Some records have missing data for all UPDRS-III variables. \\
    \textbf{Fix:}     & Remove these records \\
    \midrule
    \textbf{Problem:} & A few records have PDSTATE=ON and PDTRTMNT=0, which is inconsistent: \\
    \textbf{Fix:}     & Set PDTRTMNT=1 for these records. It doesn't seem realistic that a plausible PDMEDTM and PDSTATE=ON have been entered by mistake while the patient was not under medication. \\
    \midrule
    \textbf{Problem:} & Some records have a non-empty PDMEDTM and have PDTRTMNT=0, which is inconsistent. \\
    \textbf{Fix:}     & Set PDTRTMNT=1. It is unlikely that a plausible medication time was entered by mistake. \\
    \midrule
    \textbf{Problem:} & Some patients were on medication at screening time while PPMI patients were supposed to be unmedicated at screening time. \\
    \textbf{Fix:}     & \textbf{Keep the records. Maybe the patients started medication between recruitment and screening time.} \\
    \midrule
    \textbf{Problem:} & Some records have PDSTATE=ON but PDMEDTM is after EXAMTM. \\
    \textbf{Fix:}     & \textbf{Discard the records.} \\
    \midrule
    \textbf{Problem:} & Some visits have 3 exams while a maximum of two exams per visit are expected, one in OFF state and one in ON state. \\
    \textbf{Fix:}     & Remove exam with EXAMTM=NaN and PDSTATE=NaN  when visit has 3 exams \\
    % & &
    \bottomrule
  \end{tabularx}
\end{center}

\begin{table}[tbh]
  \renewcommand\arraystretch{1.25}
  \captionsetup{skip=3pt}
  \centering
  \caption{The table}
  \begin{tabularx}{\textwidth}{@{}cXX@{}}
    \toprule
    \multicolumn{1}{c}{}
    & \multicolumn{1}{c}{\textbf{Type}}
    & \multicolumn{1}{c}{\textbf{Problem}} \\
    \midrule[\heavyrulewidth]
    \multirow{12}*[-5\normalbaselineskip]{\rotatebox{90}{$\xmathstrut[0.35]{0}$\textbf{Inconsistency}}}
    & Some records have missing data for all UPDRS-III variables.
    & Remove these records \\ \cmidrule{2-3}
    & A few records have PDSTATE=ON and PDTRTMNT=0, which is inconsistent:
    & Set PDTRTMNT=1 for these records. It doesn't seem realistic that a plausible PDMEDTM and PDSTATE=ON have been entered by mistake while the patient was not under medication. \\ \cmidrule{2-3}
    & Some records have a non-empty PDMEDTM and have PDTRTMNT=0, which is inconsistent.
    & Set PDTRTMNT=1. It is unlikely that a plausible medication time was entered by mistake. \\ \cmidrule{2-3}
    & Some patients were on medication at screening time while PPMI patients were supposed to be unmedicated at screening time.
    & \textbf{Keep the records. Maybe the patients started medication between recruitment and screening time.} \\ \cmidrule{2-3}
    & Some records have PDSTATE=ON but PDMEDTM is after EXAMTM.
    & \textbf{Discard the records.} \\ \cmidrule{2-3}
    & Some visits have 3 exams while a maximum of two exams per visit are expected, one in OFF state and one in ON state.   
    & Remove exam with EXAMTM=NaN and PDSTATE=NaN  when visit has 3 exams \\
    % & &
    \bottomrule
  \end{tabularx}
\end{table}
\end{document}

在此处输入图片描述


编辑
第一个例子被改为带有 的长表xltabular。目前,分页符\\*后将Problem/Fix组合在一起。如果后者不是必需的,只需\\在任何地方使用正则即可。

\documentclass{report}
\usepackage{xltabular}
\usepackage{booktabs}

\begin{document}
\appendix
\chapter{Data cleaning rules implemented in MDS UPRDS III}
\begingroup
  \renewcommand\arraystretch{1.25}
  \begin{xltabular}{\textwidth}{p{1.7cm}X}
    \toprule
    \multicolumn{2}{c}{\textbf{Inconsistency}} \\
    \midrule[\heavyrulewidth] \endhead
    \textbf{Problem:} & Some records have missing data for all UPDRS-III variables. \\*
    \textbf{Fix:}     & Remove these records \\
    \midrule
    \textbf{Problem:} & A few records have PDSTATE=ON and PDTRTMNT=0, which is inconsistent: \\*
    \textbf{Fix:}     & Set PDTRTMNT=1 for these records. It doesn't seem realistic that a plausible PDMEDTM and PDSTATE=ON have been entered by mistake while the patient was not under medication. \\
    \midrule
    \textbf{Problem:} & Some records have a non-empty PDMEDTM and have PDTRTMNT=0, which is inconsistent. \\*
    \textbf{Fix:}     & Set PDTRTMNT=1. It is unlikely that a plausible medication time was entered by mistake. \\
    \midrule
    \textbf{Problem:} & Some patients were on medication at screening time while PPMI patients were supposed to be unmedicated at screening time. \\*
    \textbf{Fix:}     & \textbf{Keep the records. Maybe the patients started medication between recruitment and screening time.} \\
    \midrule
    \textbf{Problem:} & Some records have PDSTATE=ON but PDMEDTM is after EXAMTM. \\*
    \textbf{Fix:}     & \textbf{Discard the records.} \\
    \midrule
    \textbf{Problem:} & Some visits have 3 exams while a maximum of two exams per visit are expected, one in OFF state and one in ON state. \\*
    \textbf{Fix:}     & Remove exam with EXAMTM=NaN and PDSTATE=NaN  when visit has 3 exams \\
    \bottomrule
    % & &
  \end{xltabular}
\endgroup
\end{document}

在此处输入图片描述

答案2

您可能喜欢以下表格设计:

在此处输入图片描述

对于更简单的表格代码,我建议使用tabularray包,为了更好地填充单元格,使用\small字体大小并减少行距:

\documentclass[12pt]{report}
%
\usepackage{geometry}   % added, since your config file is unknow
\usepackage{ragged2e}   % for better (smart) breaking text in table cells
\usepackage{tabularray}
\UseTblrLibrary{booktabs}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
    \begin{table}[ht]
\begin{tblr}{colsep=4pt, colspec = {@{} X X @{}},
              rowsep = 4pt,
            row{1,2} = {font=\small\bfseries, rowsep=1pt},
            row{3-Z} = {font=\small\linespread{0.9}\selectfont, cmd=\RaggedRight}
             }
    \toprule
\SetCell[c=2]{l}    Type: Inconsistency           
        &                               \\
Problem &   Fix                         \\
    \midrule
Some records have missing data for all UPDRS-III variables.
        & Remove these records          \\
A few records have PDSTATE=ON and PDTRTMNT=0, which is inconsistent:
        & Set PDTRTMNT=1 for these records. It doesn't seem realistic that a plausible PDMEDTM and PDSTATE=ON have been entered by mistake while the patient was not under medication. 
                                        \\
Some records have a non-empty PDMEDTM and have PDTRTMNT=0, which is inconsistent.
        & Set PDTRTMNT=1. It is unlikely that a plausible medication time was entered by mistake.
                                        \\
Some patients were on medication at screening time while PPMI patients were supposed to be unmedicated at screening time.
        & \textbf{Keep the records. Maybe the patients started medication between recruitment and screening time.}                          \\
Some records have PDSTATE=ON but PDMEDTM is after EXAMTM. 
        & \textbf{Discard the records.} \\
Some visits have 3 exams while a maximum of two exams per visit are expected, one in OFF state and one in ON state.
        & Remove exam with EXAMTM=NaN and PDSTATE=NaN  when visit has 3 exams   \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

相关内容