我尝试在这里搜索答案,但没有找到。我有很多 25x25 的表格,里面有很长的条目。表格应该适合一张 A4 纸。我尝试使用“横向”。这有点帮助,但有些表格仍然不适合。
谁能告诉我如何改变表格的单元格间距,即表格元素边框之间的距离?
答案1
我在这里特意使用垂直线,以显示它们对间距的影响。
下面的示例显示了边框间距的影响\tabcolsep
,黑色框显示了打字区域与左右间距的关系。
通常情况下,\tabcolsep
默认为6pt
。
如果还包括垂直线,则会有额外的\arrayrulewidth
,默认为0.4pt
,更改这会影响由创建的水平规则的粗细\hline
。
这一切都适用于标准tabular
环境,无需添加额外的table
包。
\documentclass[paper=a4,12pt]{scrbook}
\usepackage{xcolor}
\begin{document}
\begin{table}
\begin{tabular}{|l|*{24}{l|}}
\hline
\colorbox{black}{\parbox{1cm}{\hspace{1cm}}} & & & & & & & & & & & & & & & & & & & & & & & & \tabularnewline
\hline
\colorbox{black}{\parbox{1cm}{\hspace{1cm}}} & & & & & & & & & & & & & & & & & & & & & & & & \tabularnewline
\hline
\end{tabular}
\caption{Normal tabcolsep length: \the\tabcolsep, normal vertical spacing of \arraystretch}
\end{table}
\begin{table}
\setlength{\tabcolsep}{3pt}
\begin{tabular}{|l|*{24}{l|}}
\hline
\colorbox{black}{\parbox{1cm}{\hspace{1cm}}} & & & & & & & & & & & & & & & & & & & & & & \tabularnewline
\hline
\end{tabular}
\caption{Changed tabcolsep length: \the\tabcolsep}
\end{table}
\begin{table}
\setlength{\tabcolsep}{0.0pt}
\begin{tabular}{|l|*{24}{l|}}
\hline
\colorbox{black}{\parbox{1cm}{\hspace{1cm}}} & & & & & & & & & & & & & & & & & & & & & & \tabularnewline
\hline
\end{tabular}
\caption{Changed tabcolsep length: \the\tabcolsep}
\end{table}
\begin{table}
\setlength{\arrayrulewidth}{2pt}%
\begin{tabular}{|l|*{24}{l|}}
\hline
\colorbox{black}{\parbox{1cm}{\hspace{1cm}}} & & & & & & & & & & & & & & & & & & & & & & \tabularnewline
\hline
\end{tabular}
\caption{Normal tabcolsep length: \the\tabcolsep, changed arrayrulewidth to \the\arrayrulewidth}
\end{table}
\begin{table}
\renewcommand{\arraystretch}{0.8}
\begin{tabular}{|l|*{24}{l|}}
\hline
\colorbox{black}{\parbox{1cm}{\hspace{1cm}}} & & & & & & & & & & & & & & & & & & & & & & & & \tabularnewline
\hline
\colorbox{black}{\parbox{1cm}{\hspace{1cm}}} & & & & & & & & & & & & & & & & & & & & & & & & \tabularnewline
\hline
\end{tabular}
\caption{Normal tabcolsep length: \the\tabcolsep, reduced verticalspacing to \arraystretch}
\end{table}
\end{document}