“\tabular”环境中出现“放错 \noalign”错误和缺少列分隔符

“\tabular”环境中出现“放错 \noalign”错误和缺少列分隔符

我正在尝试在文档中制作一个简单的表格,但遇到了一些问题。我对 LaTeX 还不太熟悉,所以这个问题可能比较愚蠢!

1)我试图用一条垂直线分隔每列,但无论出于什么原因,它永远不会在第一列和第二列之间画出一条线。

2)当我尝试使用该选项限制列的大小时p{<column width>},它根本不起作用。

这是我的表格的简化版本:

\documentclass{report}
\begindocument
\begin{tabular}{l p{2cm} | c p{3cm} | c p{2cm} |}
\hline
First Column Description & Second Column Description & Third Column Description
\hline
\hline
First Column First Row Contents & Second Column First Row Contents & Third Column First Row Contents \\[3pt]
\hline
First Column Second Row Contents & Second Column Second Row Contents & Third Column Second Row Contents \\[3pt]
\hline
First Column Third Row Contents & Second Column Third Row Contents & Third Column Third Row Contents \\[3pt]
\hline
First Column Fourth Row Contents & Second Column Fourth Row Contents & Third Column Fourth Row Contents \\[3pt]
\hline
First Column Fifth Row Contents & Second Column Fifth Row Contents & Third Column Fifth Row Contents \\[3pt]
\hline
First Column Sixth Row Contents & Second Column Sixth Row Contents & Third Column Sixth Row Contents
\hline
\end{tabular}
\end{document}

此外,当我尝试通过 LaTeX 运行此示例时,错误更多,看起来比原始文档更混乱。我也可以提供原始表格,尽管除了内容之外,我很确定它们是相同的

另外,以下是我收到的错误:

Misplaced \noalign.
\hline ->\noalign 
                  {\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.111 \hline

? 
./chapters/chapter2.tex:111: You can't use `\hrule' here except with leaders.
\hline ->\noalign {\ifnum 0=`}\fi \hrule 
                                         \@height \arrayrulewidth \futurelet...
l.111 \hline

? 
./chapters/chapter2.tex:111: Missing number, treated as zero.
<to be read again> 
                   \futurelet 
l.111 \hline

? 
./chapters/chapter2.tex:111: Illegal unit of measure (pt inserted).
<to be read again> 
                   \futurelet 
l.111 \hline

答案1

  1. 您需要戴牙套\begin{document}
  2. 您有三列,但{l p{2cm} | c p{3cm} | c p{2cm} |}显示tabular预期为六列。
  3. 您需要\\在第一行和最后一行的末尾。

编辑

要调整列内文本的对齐方式p,您可以在表格条目内使用\centering\raggedleft\raggedright。请注意,如果您在最后一列中执行此操作,则需要使用括号。要更改整个列的对齐方式,您可以使用数组包,正如@Bernard 在评论中所建议的那样。

\documentclass{report}
\begin{document}
\begin{tabular}{p{2cm}|p{3cm}|p{2cm}|}
\hline
\centering First Column Description & \raggedright Second Column Description & {\raggedleft Third Column Description} \\
\hline
\hline
First Column First Row Contents & Second Column First Row Contents & Third Column First Row Contents \\[3pt]
\hline
First Column Second Row Contents & Second Column Second Row Contents & Third Column Second Row Contents \\[3pt]
\hline
First Column Third Row Contents & Second Column Third Row Contents & Third Column Third Row Contents \\[3pt]
\hline
First Column Fourth Row Contents & Second Column Fourth Row Contents & Third Column Fourth Row Contents \\[3pt]
\hline
First Column Fifth Row Contents & Second Column Fifth Row Contents & Third Column Fifth Row Contents \\[3pt]
\hline
First Column Sixth Row Contents & Second Column Sixth Row Contents & Third Column Sixth Row Contents \\
\hline
\end{tabular}
\end{document}

相关内容