删除表格中的空白行

删除表格中的空白行

我使用 tabulary 包进行自动宽度调整,但第一行有一个空白行。

在此处输入图片描述

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

\begin{table}[htbp]
\begin{tabulary}{1.0\textwidth}{L|L|L|L|L}
\hline
& \hbox{Name} & \hbox{Function} & \hbox{Properties} & \hbox{Relationships} \\\hline\hline
7 & \hbox{System Maintenance Database} & Stores all kinds of errors occurred during operation from all components in a specified way   
& Only error related information is stored & \\
9 & Main Database & & \\
\hline
\end{tabulary}
\caption{Data elements} 
\label{data}
\end{table}
\end{document}

怎么了?我该如何移除它?

答案1

您正尝试使用 更改某些单元格的格式\hbox。正确的方法是使用\multicolumn

示例输出

\documentclass{article}

\usepackage{tabulary}

\begin{document}

\begin{table}[htbp]
  \begin{tabulary}{0.9\textwidth}{L|L|L|L|L}
    \hline
    &\multicolumn{1}{l|}{Name}&\multicolumn{1}{l|}{Function}
    &\multicolumn{1}{l|}{Properties}&\multicolumn{1}{l}{Relationships}\\
    \hline\hline
    7 &System Maintenance Database &Stores all kinds of
    errors occurred during operation from all components in a
    specified way
    & Only error related information is stored & \\
    9 & Main Database & & \\
    \hline
  \end{tabulary}
\caption{Data elements} 
\label{data}
\end{table}
\end{document}

我已经解开了你的“系统维护数据库”的包装,以便表格可以放在页面上;如果你希望它不被破坏,你应该再次使用\multicolumn

答案2

如果您不介意稍微改变一下表格的样式,我建议使用booktabs,它会让表格看起来更干净、更美观。如果您仍想修复自己的表格,请在评论中告诉我。

表头中的命令L{3cm}表示某一列将左对齐,宽度为 3 厘米。您可以随意更改。由于第一列是一个小数字,所以我只写了l只给出对齐方式,没有宽度。

表格图像

\documentclass{article}
\usepackage[a4paper]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{tabulary}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

\begin{document}

\begin{table}    
\begin{tabular}{l*{4}{L{3cm}}}
\toprule
& Name & Function & Properties & Relationships \\ \midrule
7 & System Maintenance Database & Stores all kinds of errors occurred during operation from all components in a specified way   
& Only error related information is stored & \\
9 & Main Database & & \\
\bottomrule
\end{tabular}
\caption{Data elements} 
\label{data}
\end{table}

\end{document}

相关内容