2

Is there a way to hide a column without adding whitespace to the table?

I have hidden the last column of a table as described here: Easiest way to delete a column?

The problem is that colorised rows with the last column hidden don't align with the table width.

enter image description here

A quick-fix is to change the column order, so that the hidden column is between the first and last column. But this only moves the added whitespace to between the first and last column.

I've hidden the column by defining a new column type. This definition adds colour to the right of the last table line as shown above.
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}

This definition adds white color to the left of the last table line as shown below: \newcolumntype{H}{>{\setbox0=\hbox\bgroup\cellcolor{white}}c<{\egroup}@{}}

enter image description here

The table is available here: https://github.com/eivinskr/fileTabulator

(cleaned) Code from 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}    

Code from 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}
Kaffekoppen
  • 123
  • 5

1 Answers1

0
  • problem with coloring is caused by use of @{} in the definition of `` column type. i remove it.
  • in table design i suggest to stay with tabu options fro rules, vertical spaces in rows and first row fonts. in your they case work well.
  • personally i don't like to have caption in colored first table row.

result:

enter image description here

mwe:

\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}
Zarko
  • 296,517