LaTeX 中的景观表错误(放错 noalign 和省略)

LaTeX 中的景观表错误(放错 noalign 和省略)

我尝试使用多列使表格的第一行居中,其余部分遵循正常段落规则。以下是代码片段:

\documentclass[a4paper,12pt]{report}
\usepackage{indentfirst}
    \setlength{\parindent}{2.30em}
    
\usepackage[utf8]{inputenc}

\usepackage{pdflscape}
\usepackage{lscape}
\usepackage{booktabs, tabularx}
\usepackage{bm}
\usepackage{xfrac}

\usepackage[titles]{tocloft}

\usepackage{subfig}
\usepackage{rotating}
\usepackage{wrapfig}

\usepackage{mathptmx}
\usepackage{amsmath, amssymb, amsfonts}
\usepackage{cleveref}

\usepackage[top=1.8in, bottom=1.25in, left=1.75in, right=1.25in, headheight=1.25in]{geometry}
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\sloppy
\microtypecontext{spacing=nonfrench}
\emergencystretch=\maxdimen

% Fonts
\usepackage{sectsty} 
    \allsectionsfont{\normalsize}

%Pagination
\usepackage{fancyhdr}
    \pagestyle{fancyplain}% <- use fancyplain instead fancy
    \fancyhf{}
    \fancyhead[R]{\thepage}
    \renewcommand{\headrulewidth}{0pt}

% Caption
\usepackage{caption}
\captionsetup{format=hang, font=normalsize, labelfont=bf, justification=justified, labelsep=period}

% Graphics
\usepackage{graphicx}
    \graphicspath{{./Figure/}}
    \DeclareGraphicsExtensions{.pdf,.jpeg,.jpg,.png}

% Spacing
\usepackage{setspace} % control linespacing
    \setstretch{1.5}
    

\clearpage

\begin{document}
    \renewcommand{\thechapter}{\Roman{chapter}}
    \chapter{Methodology}
    \renewcommand{\thechapter}{\arabic{chapter}}
    \label{ch:Methodology}
    \thispagestyle{empty}

    \begin{landscape}
        \centering
        \begin{tabularx}{\linewidth}{| p{0.75in} | p{1in} | p{0.9in} | p{2in} | p{0.8in} | p{0.6in} | p{0.8in} |}{\hyphenpenalty=20\exhyphenpenalty=20}
            \hline
            \multicolumn{1}{|c|}{\textbf{Name}} & \multicolumn{1}{|c|}{\textbf{Alphanumeric Name}} & \multicolumn{1}{|c|}{\textbf{Fiber Strand Size}} (mm) & 
            \multicolumn{1}{|c|}{\textbf{Color}} & \multicolumn{1}{|c|}{\textbf{Stripping}} & \multicolumn{1}{|c|}{\textbf{Texture}} & 
            \multicolumn{1}{|c|}{\textbf{Extracted From}} \\
            \hline
            Streaky Two & S2 & 0.20 - 0.50 & Ivory white, slightly tinged with very light brown to red or purple streak & Excellent & Soft &
            Next to the outer leafsheath \\
            \hline
        \end{tabularx}
        \label{table:Abaca Fiber Grades}
    \end{landscape}

\end{document}

但是,我在该行中收到以下错误\end{tabularx}

我该如何消除这些错误?我不明白错误在说什么。非常感谢您的帮助。谢谢!

在此处输入图片描述

答案1

Atabularx型桌必须至少有一个X-type 列,这样表格的整体宽度才有可能等于目标宽度。此外,由于您将每个标题单元格都包裹在包装器中\multicolumn{1}{c},因此您实际上禁用了标题单元格中的换行符,从而导致表格太宽。我的建议是不要使用包装器——也不要使用大胆的也一样。哦,一定要去掉{\hyphenpenalty=20\exhyphenpenalty=20}

我还想鼓励您通过取消所有垂直线并使用间距合适的水平线,让表格看起来更加开放和诱人。请查看以下屏幕截图,比较牢房窗户和开放和诱人的外观。

在此处输入图片描述

\documentclass[a4paper,12pt]{report}
\usepackage{indentfirst}
\setlength{\parindent}{2.30em} % that's kind of extreme
    
%\usepackage[utf8]{inputenc} % that's the default nowadays

\usepackage{pdflscape}
%\usepackage{lscape} %% don't load both lscape and pdflscape
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{tabularx}
\usepackage{bm}
\usepackage{xfrac}

\usepackage[titles]{tocloft}

\usepackage{subfig}
%%\usepackage{rotating} %% do you need this package?
\usepackage{wrapfig}

\usepackage{amsmath, amssymb} % 'amsfonts' is loaded automatically by 'amssymb'
%\usepackage{mathptmx} % mathptmx is borderline obsolete
\usepackage{newtxtext,newtxmath}

\usepackage{cleveref}

\usepackage[top=1.8in, bottom=1.25in, 
            left=1.75in, right=1.25in, 
            headheight=1.25in % this seems excessive
           ]{geometry}
\usepackage[activate={true,nocompatibility},final,tracking=true,kerning=true,spacing=true,factor=1100,stretch=10,shrink=10]{microtype}
\microtypecontext{spacing=nonfrench}
%%\sloppy %% <-- a bad idea
%%\emergencystretch=\maxdimen

% Modify styles of sectioning headers
\usepackage{sectsty} 
\allsectionsfont{\normalsize}

%Apperance of pages
\usepackage{fancyhdr}
\pagestyle{fancyplain}% <- use fancyplain instead fancy
\fancyhf{}
\fancyhead[R]{\thepage}
\renewcommand{\headrulewidth}{0pt}

% Caption
\usepackage{caption}
\captionsetup{format=hang, 
              font=normalsize, 
              labelfont=bf, 
              justification=justified, 
              labelsep=period,
              skip=0.333\baselineskip}

% Graphics
\usepackage{graphicx}
    \graphicspath{{./Figure/}}
    \DeclareGraphicsExtensions{.pdf,.jpeg,.jpg,.png}

% Spacing
\usepackage{setspace} % control linespacing
\setstretch{1.5}

%%\clearpage % <-- not needed

%% New
\usepackage{ragged2e} % for '\RaggedRight' macro
\newcolumntype{P}[1]{>{\RaggedRight}p{#1}} % get rid of full justification, allow hyphenation
\newcolumntype{L}{>{\RaggedRight}X} % ditto
\usepackage{calc}     % for '\widthof' macro

\begin{document}
%    \renewcommand{\thechapter}{\Roman{chapter}}
%    \chapter{Methodology}
%    \label{ch:Methodology}
%    
%    \renewcommand{\thechapter}{\arabic{chapter}}
%    
%    \thispagestyle{empty}

\begin{landscape}
%%\centering % no need for this
\begin{table}
\caption{Abaca Fiber Grades}
\label{table:Abaca_Fiber_Grades}
\begin{tabularx}{\linewidth}%
   {| P{\widthof{Streaky Two}} | 
      P{\widthof{Alphanumeric}} | 
      P{\widthof{Fiber strand}} | 
      L | 
      P{\widthof{Excellent}} | 
      P{\widthof{Texture}} | 
      P{1.1in} |}
   %\hyphenpenalty=20\exhyphenpenalty=20 % huh??
   \hline
   Name & 
   Alphanumeric name & 
   Fiber strand size (mm) & 
   Color & 
   Stripping & % 'Stripping' or 'Striping'?
   Texture & 
   Extracted from \\
   \hline
   Streaky Two & 
   S2 & 
   0.20--0.50 & 
   Ivory white, slightly tinged with very light brown to red or purple streak & 
   Excellent & 
   Soft &
   Next to the outer leafsheath \\
   \hline
\end{tabularx}

\vspace*{1.5cm}
\caption{Same table, but (i) without vertical rules and (ii) with well-spaced horizontal rules}
\begin{tabularx}{\linewidth}%
 {@{} P{\widthof{Streaky Two}}  
      P{\widthof{Alphanumeric}}  
      P{\widthof{Fiber strand}}  
      L 
      P{\widthof{Excellent}}  
      P{\widthof{Texture}} 
      P{1.1in} @{}}
   %\hyphenpenalty=20\exhyphenpenalty=20 % huh?
   \toprule
   Name & 
   Alphanumeric name & 
   Fiber strand size (mm) & 
   Color & 
   Stripping & % 'Stripping' or 'Striping'?
   Texture & 
   Extracted from \\
   \midrule
   Streaky Two & 
   S2 & 
   0.20--0.50 & 
   Ivory white, slightly tinged with very light brown to red or purple streak & 
   Excellent & 
   Soft &
   Next to the outer leafsheath \\
   \bottomrule
\end{tabularx}
\end{table}
\end{landscape}

\end{document}

相关内容