表格问题 - \tabular 与 \tabularx

表格问题 - \tabular 与 \tabularx

该表无法pdflatex与 编译()\tabular,但可以与\tabularx

\begin{table}[h]
    \centering
    \caption{Comparison of two-sided market definitions}
    \label{tab:two-sided market definitions comparison}
    \begin{tabular}{\textwidth}{|l|m{0.2\textwidth}<{\centering}|m{0.2\textwidth}<{\centering}|m{0.2\textwidth}<{\centering}|}
        \toprule
         & \cite{rochet06two} & \cite{evans13} & \cite{rysman09} \\
        \midrule
        payment systems & Y & Y & Y \\
        \midrule
        video game consoles & Y & Y & Y \\
        \midrule
        operating systems & Y & Y & Y \\
        \midrule
        online recruitment & N & Y & Y \\
        \midrule
        shopping malls & N & Y & Y \\
        \midrule
        academic journals & Y & Y & Y \\
        \midrule
        industrial standards & Y & Y & Y \\
        \midrule
        automobile engines & N & N & Y \\
        \midrule
        airports & N & Y & Y \\
        \midrule
        supermarkets & Y & Y & Y/N \\
        \midrule
        conferences & Y & Y & Y \\
        \midrule
        franchising & N & Y/N & Y \\
        \midrule
        collecting societies & Y & Y & Y \\
        \midrule
        highways & N & N & Y \\
        \bottomrule
    \end{tabular}
\end{table} 

显示此错误

./chapters/terminology_of_data.tex:178: Package array Error:  Illegal pream-token (\textwidth): `c' used.

See the array package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.178   \begin{tabular}{\textwidth}
                                  {|l|m{0.2pt\textwidth}<{\centering}|m{0.2p...
Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

./chapters/terminology_of_data.tex:178: Missing number, treated as zero.
<to be read again> 
                   }
l.178 ...abular}{\textwidth}{|l|m{0.2pt\textwidth}
                                                  <{\centering}|m{0.2pt\text...
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)

./chapters/terminology_of_data.tex:178: Illegal unit of measure (pt inserted).
<to be read again> 
                   }
l.178 ...abular}{\textwidth}{|l|m{0.2pt\textwidth}
                                                  <{\centering}|m{0.2pt\text...
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)

./chapters/terminology_of_data.tex:178: Missing number, treated as zero.
<to be read again> 
                   }
l.178 ...extwidth}<{\centering}|m{0.2pt\textwidth}
                                                  <{\centering}|m{0.2pt\text...
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
./chapters/terminology_of_data.tex:179: Misplaced \noalign.
\toprule ->\noalign 
                    {\ifnum 0=`}\fi \@aboverulesep =\abovetopsep \global \@b...
l.179       \toprule
                
I expect to see \noalign only after the \cr of
an alignment. Proceed, and I'll ignore this case.
./chapters/terminology_of_data.tex:180: Missing \cr inserted.
<inserted text> 
                \cr 
l.180        &
           \cite{rochet06two} & \cite{evans13} & \cite{rysman09} \\
I'm guessing that you meant to end an alignment here.

另外,为什么在编制表格时悬挂水平线?

答案1

tabular*与和环境不同tabularxtabular环境不将目标宽度作为其参数之一。

并且,在使用该包的线条绘制宏时booktabs,应该不是采用任何垂直规则。没有例外。另外,请不要过度使用水平线。我会删除所有内部\midrule指令;为了给表格提供一些视觉节奏,我会在指令的帮助下,每隔 5 行左右添加一些额外的垂直空白\addlinespace

以下屏幕截图中的第一个表格显示了使用环境的结果tabular,其中三个数据列使用p宽度等于的 -type 列0.2\textwidth。第二个表格w对三个数据列使用列类型,因为这些列中似乎不需要换行;数据列的宽度设置为“Y/N”的自然宽度。第二个表格还使用threeparttable“包装器”将标题的宽度限制为相关tabular环境的宽度。

在此处输入图片描述

我想大多数读者可能更喜欢第二张设计紧凑的表格的外观。

\documentclass{article}
\usepackage{booktabs,array}
\usepackage[flushleft]{threeparttable}
\newlength\mylen

\begin{document}
\begin{table}[h]
\centering

   \caption{Comparison of two-sided market definitions\strut}
   \label{tab:comparison}
   \begin{tabular}{@{} l *{3}{>{\centering\arraybackslash}p{0.2\textwidth}} @{}}
   \toprule
   & \cite{rochet06two} & \cite{evans13} & \cite{rysman09} \\
   \midrule
   payment systems     & Y & Y & Y \\  
   video game consoles & Y & Y & Y \\
   operating systems   & Y & Y & Y \\
   online recruitment  & N & Y & Y \\
   shopping malls      & N & Y & Y \\
   \addlinespace
   academic journals   & Y & Y & Y \\
   industrial standards& Y & Y & Y \\
   automobile engines  & N & N & Y \\
   airports            & N & Y & Y \\
   supermarkets        & Y & Y & Y/N \\
   \addlinespace
   conferences         & Y & Y & Y \\
   franchising         & N & Y/N & Y \\
   collecting societies& Y & Y & Y \\
   highways            & N & N & Y \\
   \bottomrule
   \end{tabular}
   
\vspace{8mm}

   \settowidth{\mylen}{Y/N} % set width of data columns
   \begin{threeparttable}
   \caption{Comparison of two-sided market definitions, 
            Natural column widths}
   \label{tab:comparison2}
   \begin{tabular}{@{} l *{3}{wc{\mylen}} @{}}
   \toprule
   & \cite{rochet06two} & \cite{evans13} & \cite{rysman09} \\
   \midrule
   payment systems     & Y & Y & Y \\  
   video game consoles & Y & Y & Y \\
   operating systems   & Y & Y & Y \\
   online recruitment  & N & Y & Y \\
   shopping malls      & N & Y & Y \\
   \addlinespace
   academic journals   & Y & Y & Y \\
   industrial standards& Y & Y & Y \\
   automobile engines  & N & N & Y \\
   airports            & N & Y & Y \\
   supermarkets        & Y & Y & Y/N \\
   \addlinespace
   conferences         & Y & Y & Y \\
   franchising         & N & Y/N & Y \\
   collecting societies& Y & Y & Y \\
   highways            & N & N & Y \\
   \bottomrule
   \end{tabular}
   \end{threeparttable}
\end{table} 
 
\end{document}

相关内容