4

Is there a convenient way to not typeset a particular column in a tabular environment by modifying only the preamble of the tabular? That is, without modifying the body of the tabular itself?

My first idea was to do @{}>{\nullfont}c@{} to zero out the spacing around the ignored column (here, a c column) and typeset it with a null font. I also tried several difference sizes of space inside @{}.

This works, but the spacing between columns is not the same as it would be if I'd just left out the column entirely. See the following MWE, where I've committed a deadly sin with vertical rules (doubled, even! ) to show the difference clearly:

\documentclass{article}
\usepackage{array}

\begin{document}
\begin{tabular}{c|@{}>{\nullfont}c@{\,}|c}
  a & b & c \\
  d & e & f
\end{tabular}

\begin{tabular}{c||c}
  a & c \\
  d & f
\end{tabular}
\end{document}

enter image description here

What should be inserted so the spacing matches? I've tried various combinations of the standard spacing commands.

Or, is there a more convenient way to do this than what I've proposed?

  • I was a little bit surprised that I did not find a question like this already on the site: if you know of a duplicate, let me know. :-) – Paul Gessler Mar 28 '15 at 21:22
  • 1
  • @UlrikeFischer ooops, that's it! I've even voted there, haha. But it did not come up in my searches. Thanks. – Paul Gessler Mar 28 '15 at 21:27
4

enter image description here

\documentclass{article}
\usepackage{array}

\begin{document}
\begin{tabular}{c||>{\nullfont}c@{}c}
  a & b & c \\
  d & e & f
\end{tabular}

\begin{tabular}{c||c}
  a & c \\
  d & f
\end{tabular}
\end{document}

although if you want to omit images and math etc, you are better to grab the cell in a macro which is then not used, rather than using \nullfont.

\documentclass{article}
\def\zzzforegreg#1\unskip{}
\usepackage{array}

\begin{document}


\begin{tabular}{c||>{\nullfont}c@{}c}
  a & \textbf{b} & c \\
  d & $e$ & f
\end{tabular}


\begin{tabular}{c||>{\zzzforegreg}c@{}c}
  a & \textbf{b} & c \\
  d & $e$ & f
\end{tabular}

\begin{tabular}{c||c}
  a & c \\
  d & f
\end{tabular}
\end{document}

which makes

enter image description here

  • What if the rules should surround the column when it is shown (not a double rule before as you've done here)? – Paul Gessler Mar 28 '15 at 21:34
  • @PaulGessler well you can move the rule back at same time as you remove the hiding code, so it comes to the same thing. You could have the rule after the column but the "natural" spacing wouldn't be the doublerulesep that you get in the final 2-col table as latex looks for two adjacent | and adds that space, so |<hidingcode>| you woud have to add the douberulesep by hand. which is what you were trying with \, except that isn't same as \hspace{\doublerulesep} – David Carlisle Mar 28 '15 at 21:40

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