Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a set of 10 tables and each has an extra column that I don't want. Specifically, these tables are descriptions of database tables exported by phpMyAdmin, and they all have a "MIME" column that I would like to remove. Is there a way to do this other than using string manipulation / find and replace?

I have tried setting the column to p{0in}, but the column title still remains.

share|improve this question
add comment

2 Answers 2

up vote 60 down vote accepted
\documentclass[a4paper]{article}
\usepackage{array}
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}

\begin{document}
\begin{tabular}{ccHc}
one & two & hide & three\\
1 & 2 & H & 3
\end{tabular}

\begin{tabular}{ccc}
one & two & three\\
1 & 2 &  3
\end{tabular}

\end{document}

The second tabular is there to show that the result is the same. Basically, we set a column without intercolumn space, and its content is swallowed by \setbox0=\hbox{<entry>}

share|improve this answer
3  
That's very cool! –  Alan Munn Apr 25 '11 at 20:03
5  
You can write it shorter by using the lrbox environment, which is the environment form of \sbox (which is the LaTeX form of the plain \setbox): \newcolumntype{H}{>{\lrbox0}c<{\endlrbox}@{}}. @Alan might find this even cooler ;-) –  Martin Scharrer Apr 26 '11 at 11:42
add comment

The solution of egreg is good. It typesets the cell content in a box which is then discarded. All code in the cell is executed and typeset. There are also two alternatives which I list here for the sake of completeness.

First you can use the collcell package to collect the cell content and then feed it to a macro which simply discards it. The \@gobble macro does that. This method doesn't execute or typeset the cell content but needs to scan every token. It might be faster or slower than the use of a box dependent on the content.

Another method is to insert a macro which reads everything till the next \unskip which is inserted after each cell except the very last column of a row. There the \unskip is inside \\ and won't be seen by the macro. This method is the fastest and doesn't execute, typeset or check the cell content beside the argument scanning of the TeX parser.

For small cells the speed difference should be not important.

\documentclass[a4paper]{article}

\usepackage{collcell}
\makeatletter
\newcolumntype{G}{>{\collectcell\@gobble}c<{\endcollectcell}@{}}
\makeatother
% Fastest. Does not work in the last column.
\def\eatcell#1\unskip{}
\newcolumntype{E}{>{\eatcell}c@{}}

\begin{document}
\begin{tabular}{ccGc}
one & two & hide & three\\
1 & 2 & H & 3
\end{tabular}

\begin{tabular}{ccEc}
one & two & hide & three\\
1 & 2 & H & 3
\end{tabular}

\begin{tabular}{ccc}
one & two & three\\
1 & 2 &  3
\end{tabular}

\end{document}
share|improve this answer
1  
Nice; I should remember the collcell package. –  egreg Apr 25 '11 at 21:42
4  
Is the solution that doesn't work in the last column, but is faster, really a solution? :-) When I first started programming I was told the following story by my boss: Some engineers and some computer scientists are asked to solve a problem. The engineers say "Our program is 10000 lines of FORTRAN that takes 8 hours to run"; the computer scientists say "Ours is much better, it's 2000 lines of LISP and takes an hour to run. But it sill has a few bugs...." –  Alan Munn Apr 25 '11 at 21:42
    
@Alan: If it would be a satisfying solution I wouldn't had spend all the time coding the collcell package :-) It doesn't has a bug, just two limitations. The not-in-the-last-column is the first and the second I forgot to mention is that the cell must not contain an \unskip outside { }. –  Martin Scharrer Apr 25 '11 at 22:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.