允许使用允许分页符的表格以及不允许分页符的表格

允许使用允许分页符的表格以及不允许分页符的表格

我的序言中有一个设置允许这样做:

\documentclass[12pt]{report}% Not sure what this is for
 \usepackage{array,ltablex, makecell}%
\newenvironment{conditions}
 {\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
 {\end{tabular}\par\vspace{\belowdisplayskip}}%This is for descriptions of equations
\usepackage[]{multirow}%Essential for cells in table spanning multiple rows
\usepackage{tabulary}% This is for tables
\usepackage{longtable,array,ragged2e}% This is formatting for long tables
\usepackage{tabularx,caption}
\newcolumntype{LL}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}X}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{CC}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}%C is for central aligned columns and middle aligned.
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}%C is for central aligned columns and middle aligned.
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}%This is for precision tables per property

\begin{document}

\begin{longtable}{@{}LL{6cm}LL{8cm}@{}}
\caption{Claims that are Difficult to Check}
\label{table:claimimpossible}\\
\toprule
\textbf{Example Sentence} & \textbf{Explanation}\\
\midrule
\endhead
\bottomrule
\endlastfoot
Long text...... & Long text......\\
\midrule
Long text...... & Long text......\\
\midrule
Long text...... & Long text......\\
\end{longtable}

\begin{table}[!htbp]
\setlength\extrarowheight{3pt}
\setlength\tabcolsep{4pt} % default value: 6pt
\catcode`_=13 % Make _ "active"; 
%% This setting expires at end of current group, i.e., at end of "table" environment
\def_{\textunderscore\hspace{0pt}} % "meaning" of "_"
\caption{List of Open and Closed Evaluation Properties}
\label{table:openclosed}
\ra{1.0}%This stretches the contents of cells
\begin{tabularx}{\textwidth}{|C|C|C|}
\hline
\textbf{Open Properties} & \textbf{Closed Properties} & 
\textbf{Sentence Label Properties} \\ 
\hline 
\begin{tabular}{@{}L@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}                   
& 
\begin{tabular}{@{}L@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}
& 
\begin{tabular}{@{}L@{}}
foreign_direct_investment_net_inflows\\
\end{tabular}\\
\hline
\end{tabularx}
\end{table}

\end{document}

第一个表格需要有分页符和固定的列宽,因此我使用了longtable。第二种表格需要灵活,并在其设置中提供基于 等字符换行的选项_,因为单词time_required_to_start_a_business目前永远不会在单元格中换行。但是,它不需要允许分页符。

目前,我的 longtable 出现错误:

Package array Error:  Illegal pream-token (4cm)
: `c' used.

See the array package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.23 ...in{longtable}{@{}LL{4cm}LL{4cm}LL{6cm}@{}}

请注意,第二个表格来自之前的答案,它解释了我想要实现的基于下划线的文本换行的用例(注意,如果可能的话最好不要针对每个表格都这样做):

表格中包含下划线的文本换行

该错误与包有关array- 我知道我加载了两次,但错误真的与包有关吗?

答案1

这需要进一步调整,例如确保标题和表格之间的间距一致,并可能减少水平线或修剪它们。但是,它确实可以编译,并且确保了比原始代码更高的一致性。

然而,如果您不知道这\documentclass[12pt]{report}是什么意思,那么您需要阅读 LaTeX 的介绍,否则就没有任何意义了。

如果您认为自己没有时间,或者仅查看示例会更容易,那么您需要重新考虑。

它将极大地节省你的时间。

它将使您能够理解示例,而不是随机复制粘贴代码片段,根据某些假设或冲动对其进行更改,然后希望它能够以某种方式起作用。

如果你很幸运的话,它将会因错误而失败。

如果你运气不好,它将会编译出可接受的输出,而你只会在很晚之后才发现其中的弊端。

\documentclass[12pt]{report}% Not sure what this is for - ??? this is the class you are using and the default font size
\usepackage{geometry}% bad boxes without this
\usepackage{array,booktabs}% you need booktabs, but you're not using makecell
\usepackage{longtable}% This is formatting for long tables - don't load packages twice, you already loaded array
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash\hspace{0pt}}p{#1}}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{Y}{>{\raggedright\arraybackslash\hspace{0pt}}X}
\newcolumntype{C}[1]{>{\centering\arraybackslash\hspace{0pt}}m{#1}}%C is for central aligned columns and middle aligned.
\newcolumntype{Z}{>{\centering\arraybackslash\hspace{0pt}}X}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash\hspace{0pt}}m{#1}}
\newcommand*{\ra}[1]{\renewcommand*{\arraystretch}{#1}}%This is for precision tables per property
\begin{document}
\begin{longtable}{@{}L{6cm}L{8cm}@{}}
  \caption{Claims that are Difficult to Check}
  \label{table:claimimpossible}\\
  \toprule
  \textbf{Example Sentence} & \textbf{Explanation}\\
  \midrule
  \endhead
  \bottomrule
  \endlastfoot
  Long text...... & Long text......\\
  \midrule
  Long text...... & Long text......\\
  \midrule
  Long text...... & Long text......\\
\end{longtable}

\begin{table}[!htbp]
  \setlength\extrarowheight{3pt}
  \setlength\tabcolsep{4pt} % default value: 6pt
  \catcode`_=13 % Make _ "active";
  %% This setting expires at end of current group, i.e., at end of "table" environment
  \def_{\textunderscore\hspace{0pt}} % "meaning" of "_"
  \caption{List of Open and Closed Evaluation Properties}
  \label{table:openclosed}
  \ra{1.0}%This stretches the contents of cells
  \begin{tabularx}{\textwidth}{ZZZ}
    \toprule
    \textbf{Open Properties} & \textbf{Closed Properties} &
    \textbf{Sentence Label Properties} \\
    \midrule
    \begin{tabular}{@{}Y@{}}
      foreign_direct_investment_net_inflows\\
    \end{tabular}
    &
    \begin{tabular}{@{}Y@{}}
      foreign_direct_investment_net_inflows\\
    \end{tabular}
    &
    \begin{tabular}{@{}Y@{}}
      foreign_direct_investment_net_inflows\\
    \end{tabular}\\
    \bottomrule
  \end{tabularx}
\end{table}
\end{document}

两种表格

相关内容