表格中的文字换行

表格中的文字换行

由于某种原因,我的表格中的文本没有换行,并且我一直收到错误:额外的对齐标签已更改为 \cr.. 有人可以帮忙制作一个可以换行的简单表格吗:下面是 MWE:

   %---------------------Preamble---------------%
\documentclass[twoside,b5paper,9.5pt,openright]{book}
\usepackage[total={13cm,19.5cm},top=2.5cm,bottom=2.0cm,left=2.0cm,right=2.0cm, includefoot]{geometry} 
\usepackage[english]{babel}
\usepackage{charter}
\usepackage{microtype}          % removes extra spacing between text
\usepackage{fancyhdr}           % fancy heading style in headers and footers
\usepackage{graphicx}           % include graphs/ figures  in the file
\usepackage{array,threeparttable}       % to add footnotes to the tables
\usepackage{booktabs}
\usepackage{caption}    % to create some space between table caption and table, otherwise there was no space
\captionsetup[table]{font=small,skip=0pt}
\usepackage{subfig}
\usepackage{float}              % figures as 6 (a), 6 (b) etc.
\usepackage{tabu}
\usepackage{tikz}
\raggedbottom
\begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[ht]
  \scriptsize
  \centering
  \begin{threeparttable}
  \caption{Add caption}
    \begin{tabular}{p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}}
    \toprule
          & \textbf{Overall} & \textbf{Starting} & \textbf{treatments} & \textbf{processes} & \textbf{Average} & \textbf{error (\%)} \\
    \midrule
    R2    & 0.3  & 0.6  & 0.5  & 0.7  & 0.3  & 8 \\
    C     & 2   & 17   & 2   & 5   & 2   & 8 \\
    k     & 6    & 0     & 2    & 226   & 9    & 1 \\
    Efficiency of testing system* & 74    & 9    & 8    & 5    & 8    & 0 \\
    St.dev. ** & 1    & 1    & 1    & 1    & 2    & - \\    
    \bottomrule
    \end{tabular}%
  \label{tab:first-modeldata}%
    \end{threeparttable}
\end{table}%

答案1

siunitx这是一个对齐数字和规则的版本booktabs

漂亮的桌子

\documentclass[twoside,b5paper,openright]{book}
\usepackage[total={13cm,19.5cm},top=2.5cm,bottom=2.0cm,left=2.0cm,right=2.0cm,includefoot]{geometry}
\usepackage{charter}
\usepackage{microtype}
\usepackage{array,threeparttable,siunitx}
\usepackage{booktabs}
\usepackage{caption}
\captionsetup[table]{font=small,skip=0pt}
\usepackage{subfig}
\usepackage{float}
\raggedbottom
\begin{document}
  \begin{table}[ht]
    \scriptsize
    \centering
    \begin{threeparttable}
      \caption{Add caption}
      \begin{tabular}{p{1cm}*{6}{S}}
        \toprule
        & \textbf{Overall} & \textbf{Starting} & \textbf{treatments} & \textbf{processes} & \textbf{Average} & \textbf{error (\%)} \\\midrule
        R2    & 0.3  & 0.6  & 0.5  & 0.7  & 0.3  & 8 \\
        C     & 2   & 17   & 2   & 5   & 2   & 8 \\
        k     & 6    & 0     & 2    & 226   & 9    & 1 \\
        Efficiency of testing system* & 74    & 9    & 8    & 5    & 8    & 0 \\
        St.dev.** & 1    & 1    & 1    & 1    & 2    & \multicolumn{1}{c}{--} \\\bottomrule
      \end{tabular}%
      \label{tab:first-modeldata}%
    \end{threeparttable}
  \end{table}
\end{document}

如果你确实需要垂直规则:

  \begin{table}[ht]
    \scriptsize
    \centering
    \begin{threeparttable}
      \caption{Add caption}
      \begin{tabular}{p{1cm}|*{6}{S}}
        \hline
        & \textbf{Overall} & \textbf{Starting} & \textbf{treatments} & \textbf{processes} & \textbf{Average} & \textbf{error (\%)} \\\hline
        R2    & 0.3  & 0.6  & 0.5  & 0.7  & 0.3  & 8 \\
        C     & 2   & 17   & 2   & 5   & 2   & 8 \\
        k     & 6    & 0     & 2    & 226   & 9    & 1 \\
        Efficiency of testing system* & 74    & 9    & 8    & 5    & 8    & 0 \\
        St.dev.** & 1    & 1    & 1    & 1    & 2    & \multicolumn{1}{c}{--} \\\hline
      \end{tabular}%
      \label{tab:first-modeldata}%
    \end{threeparttable}
  \end{table}

但结果(可以预见)要糟糕得多:

丑陋的桌子

booktabs桌子确实看上去更美观。

相关内容