GeneralDo not display column in table

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
mro
Posts: 18
Joined: Thu Oct 16, 2008 10:49 pm

Do not display column in table

Post by mro »

Hi there guys,
is there a simple way not to display a column in a tabular environment?
I thought there must be something like "\begin{tabular}{cccxc}", which would mean do not display the 4th column. But I guess it's not that simple.
I just wanna try how my table looks without that column :|
Thanks
Marki

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Do not display column in table

Post by phi »

Hello,

this code creates "x" as a new column type which simply makes the cell text white, so that it is invisible (but still in the document):

Code: Select all

\documentclass{article}
\usepackage{color}
\usepackage{array}
\newcolumntype{x}{>{\color{white}}c}

\begin{document}
\begin{tabular}{cccxc}
  A & B & C & D & E
\end{tabular}
\end{document}
mro
Posts: 18
Joined: Thu Oct 16, 2008 10:49 pm

Do not display column in table

Post by mro »

Yeah, but this does not really make the width of the column zero = make it disappear completely.
Even if I use sth. like

Code: Select all

\newcolumntype{x}{>{\color{white}}p{0mm}}
it will still mess up the formatting as it will try to break the (non-visible) white stuff ...

As a sidenote: It would also be cool to have a package that allowed to reorder the columns in a simple way :)
mro
Posts: 18
Joined: Thu Oct 16, 2008 10:49 pm

Do not display column in table

Post by mro »

So, no idea on this one?
  • make tabular column disappear, and/or
  • reorder columns without reordering source text
I guess it just does not exist :(
mro
Posts: 18
Joined: Thu Oct 16, 2008 10:49 pm

Do not display column in table

Post by mro »

Oh yeah I forgot,
also something like

Code: Select all

\newcolumntype{x}{>{\begin{comment}}c<{\end{comment}}}
is not working for the first part....

Code: Select all

...
Runaway argument?
! File ended while scanning use of \next.
...
So I guess 'comment' is not allowed within a table (cell).

For the second part... I was just wondering if there was no editor for tables. For small tables just manipulating the source is good enough but for larger ones some WYSIWYG would be great .... :-\
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Do not display column in table

Post by Juanjo »

Try this example:

Code: Select all

\documentclass{article}
\usepackage[margin=2cm]{geometry}

\usepackage{array}

\newsavebox{\hiddenbox}
\newcommand{\ZZ}{\hspace{\tabcolsep}}
\newcolumntype{Z}{>{\begin{lrbox}{\hiddenbox}}p{0pt}<{\end{lrbox}}}
\newcolumntype{U}{@{\ZZ}Z@{}}
\newcolumntype{V}{@{\ZZ}Z@{\ZZ}}

\begin{document}

\begin{tabular}{|c|c|c|c|c|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  \hline
\end{tabular}
\bigskip

\begin{tabular}{|Uc|c|c|c|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  \hline
\end{tabular}
\bigskip

\begin{tabular}{|cU|c|c|c|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  \hline
\end{tabular}
\bigskip

\begin{tabular}{|cU|cU|c|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  \hline
\end{tabular}
\bigskip


\begin{tabular}{|c|c|c|cU|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \tabularnewline
  First column & Second column & Third column & Fourth column & Fifth column \tabularnewline
  First column & Second column & Third column & Fourth column & Fifth column \tabularnewline
  \hline
\end{tabular}
\bigskip

\begin{tabular}{|ccccc|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  \hline
\end{tabular}
\bigskip

\begin{tabular}{|Ucccc|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  \hline
\end{tabular}
\bigskip

\begin{tabular}{|cVcVc|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  First column & Second column & Third column & Fourth column & Fifth column \\
  \hline
\end{tabular}
\bigskip

\begin{tabular}{|ccccU|}
  \hline
  First column & Second column & Third column & Fourth column & Fifth column \tabularnewline
  First column & Second column & Third column & Fourth column & Fifth column \tabularnewline
  First column & Second column & Third column & Fourth column & Fifth column \tabularnewline
  \hline
\end{tabular}

\end{document}
If you don't see how it works, ask for an explanation. Please, note the use of \tabularnewline to end rows when the hidden column is the last one. Note also that the column types U and V are almost identical; they only differ in the space after the hidden column.

Edited to simplify the definition of the Z column type
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply