tabularx 的问题

tabularx 的问题

以下代码不起作用??

\documentclass[a4paper]{book}

\usepackage{tabularx}

\begin{document}
\newcommand{\vrulehg}[1]
{\makebox[#1][c]{\rule{1pt}{0.5cm}}}% rule for vertical bar cell

\newcommand{\hrulehg}[3]{% hgrule{5cm}{c}{2}
\newdimen\wwo\wwo=#1%
\newdimen\wwl\wwl=\wwo\divide \wwl by #3%
\makebox[\wwo][#2]{\rule{\wwl}{1pt}}}

\begin{tabular}{ @{}>{\centering}p{6cm} @{}>{\centering}p{6cm} @{}>{\centering}p{6cm} @{}p{0.01cm} @{}>{\centering}p{6cm}X}
aaa & & bbb & & ccc \\
ddd & & eee & & fff \\
\end{tabular}
\end{document}

错误信息是:

! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate 

l.16 ddd &
           & eee & & fff \\
? 

我在用 :

This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)
 restricted \write18 enabled.
entering extended mode

在 Mac 上

有人可以帮忙吗?

谢谢

答案1

\\是否含糊不清:单元格内的行尾或表格行的结尾?

\tabularnewline明确结束表格行:

\begin{tabular}{ @{}>{\centering}p{6cm} @{}>{\centering}p{6cm}
@{}>{\centering}p{6cm} @{}p{0.01cm} @{}>{\centering}p{6cm}X}
aaa & & bbb & & ccc \tabularnewline
ddd & & eee & & fff \tabularnewline
\end{tabular}
\end{document}

有以下新线路可供选择:

  • \tabularnewline:结束表格行并开始新行
  • \newline结束单元格内的一行(列类型p
  • \\:通常它结束表格行,除非

    • \centering、、在列规范\raggedright\raggedleft使用。这些命令重新定义\\\newline

    • \arraybackslash如果在或朋友之后调用,则后者可以反转\centering。宏由包提供array,并重新定义\\\tabularnewline. Then\` 结束表格行。

例子:

\documentclass{article}
\usepackage{array}
\begin{document}

\begin{tabular}{p{3cm} p{3cm}}
row 1, col 1, line 1\newline
row 1, col 1, line 2
&
row 1, col2, line 1\newline
row 1, col2, line 2
\\
\hline
row 2, col 1
&
row 2, col2
\tabularnewline
row 3, col 1
&
row 3, col2
\end{tabular}

\medskip

\begin{tabular}{>{\centering}p{3cm} >{\centering}p{3cm}}
row 1, col 1, line 1\\
row 1, col 1, line 2
&
row 1, col2, line 1\\
row 1, col2, line 2
\tabularnewline
\hline
row 2, col 1, line 1\newline
row 2, col 1, line 2
&
row 2, col2, line 1\newline
row 2, col2, line 2
\tabularnewline
\end{tabular}

\medskip

\begin{tabular}{>{\centering\arraybackslash}p{3cm}
                >{\centering\arraybackslash}p{3cm}}
row 1, col 1, line 1\newline
row 1, col 1, line 2
&
row 1, col2, line 1\newline
row 1, col2, line 2
\\
\hline
row 2, col 1, line 1\newline
row 2, col 1, line 2
&
row 2, col2, line 1\newline
row 2, col2, line 2
\tabularnewline
\hline
row 3, col 1
&
row 3, col2
\tabularnewline
\end{tabular}

\end{document}

结果示例

相关内容