隐藏列而不向表中添加空格

隐藏列而不向表中添加空格

有没有办法隐藏某一列而不在表中添加空格?

我隐藏了表格的最后一列,如下所述:删除列的最简单方法?

问题是隐藏最后一列的彩色行与表格宽度不对齐。

在此处输入图片描述

一个快速解决方法是更改​​列顺序,以便隐藏列位于第一列和最后一列之间。但这只会将添加的空白移动到第一列和最后一列之间。

我通过定义新的列类型隐藏了该列。此定义在表格最后一行的右侧添加了颜色,如上所示。
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}

此定义在表格最后一行的左边添加白色,如下所示:\newcolumntype{H}{>{\setbox0=\hbox\bgroup\cellcolor{white}}c<{\egroup}@{}}

在此处输入图片描述

该表格可在此处获取: https://github.com/eivinskr/fileTabulator

(已清理)来自 main.tex 的代码:

\documentclass{report}

\usepackage{tabu,booktabs}
\usepackage[table]{xcolor}
\usepackage{color} 
\usepackage{pdfpages}
\usepackage{float}
\usepackage{array}
\usepackage{pdflscape}
\usepackage{longtable,tabu}
\usepackage{array}
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}

\definecolor{lightgrey}{gray}{0.9}

\begin{document}
\title{File list}
\maketitle

\input{sections/FileTable}

\end{document}    

来自 FileTable.tex 的代码:

\begin{landscape}
\centering
\begin{longtabu} to \linewidth{|X[1,l]|X[2,l]|X[1,l]H|}
\taburowcolors[1]2{lightgrey..white} 
\toprule
\caption{File List}\label{tab:file_list}\\
\hline
\textbf{Path} & \textbf{Filename}  & \textbf{Description} & 
\textbf{Hash} \\
\hline
\endfirsthead
\multicolumn{4}{l}
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{Path} & \textbf{Filename} & \textbf{Description} & 
\textbf{Hash} \\
\hline
\endhead
\hline \multicolumn{4}{l}{\textit{Continued on next page}} \\\endfoot
\hline
\endlastfoot
\taburowcolors[1]2{lightgrey..white}
/ & testFile1.txt & & 33918e2384aee6ec78588db2ea6eacc6 \\
/testFolder & testFile2.txt & Try to move, change or edit this file! 
I'll still be here! & a3f84bf2a1f0f0b599d51c089c99091e \\
\end{longtabu}
\end{landscape}

答案1

  • 颜色问题是由于@{}在“列类型”定义中使用而引起的。我将其删除。
  • 在表格设计中,我建议保留tabu规则、行中的垂直空间和第一行字体的选项。在您的情况下,它们会运行良好。
  • 我个人不喜欢在表格的第一行添加彩色标题。

结果:

在此处输入图片描述

母语:

\documentclass{report}

\usepackage[table]{xcolor}
\usepackage{pdflscape}
\usepackage{booktabs, longtable, tabu}
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}}% <--- removed @{}
\definecolor{lightgrey}{gray}{0.9}

\begin{document}
\begin{landscape}
\centering
\tabulinesep=_3pt^3pt
\begin{longtabu} to \linewidth{|X[1,l]|X[2,l]|X[1,l]H|}
\caption{File List}
\label{tab:file_list}\\
\tabucline[1pt]{1-}
\textbf{Path} & \textbf{Filename}  & \textbf{Description} &
\textbf{Hash} \\
\tabucline[0.5pt]{1-}
\endfirsthead
\caption{File List -- \textit{Continued from previous page}} \\
\tabucline[0.5pt]{1-}
\rowfont [c]{\bfseries}
Path    &   Filename    &   Description &   Hash        \\
\tabucline[0.5pt]{1-}
\endhead
\tabucline[0.5pt]{1-}
\multicolumn{4}{l}{\textit{Continued on next page}}     \\
\endfoot
\tabucline[1pt]{1-}
\endlastfoot
\taburowcolors[1]2{lightgrey..white}
/ & testFile1.txt & & 33918e2384aee6ec78588db2ea6eacc6  \\
%
/testFolder & testFile2.txt & Try to move, change or edit this file!
I'll still be here! & a3f84bf2a1f0f0b599d51c089c99091e  \\
%
/           & testFile1.txt & & 33918e2384aee6ec78588db2ea6eacc6 \\
%
/testFolder & testFile2.txt & Try to move, change or edit this file!
I'll still be here! & a3f84bf2a1f0f0b599d51c089c99091e \\
\end{longtabu}
\end{landscape}
\end{document}

相关内容