8

Is there a way to \kill a row in a {tabular} or {array} environment? I want to provide text that will set the column widths but then have that row not appear.

5
  • 1
    You can set column widths by using options like p{<width>} for tabular or array. Another way is to use \hphantom{<content>} for cells in a particular row. This will make cells occupy widths same as <content> (but not height) while keeping <content> invisible.
    – Herr K.
    Jan 22, 2015 at 21:18
  • if you could instead use a tabbing environment, you've got that option. if you don't really need a captioned unit, or a float, tabbing might give you mire flexibility. Jan 22, 2015 at 21:29
  • @barbarabeeton I can't use tabbing -- too much else going on. Jan 22, 2015 at 21:31
  • @KevinC I don't like p{width} because I want the text centered. I thought of using \hphantom{<content>} but then it would add the width of <content> to what's already in the cell, but I want to replace the width of the cell with the phantom. Jan 22, 2015 at 21:33
  • 2
    You can use \centering to centre text in a p Jan 22, 2015 at 22:41

2 Answers 2

10

longtable has essentially the same functionality as tabular, but also has the \kill functionality and adds the capability to break across page boundaries.

If you want to use \kill but don't want the table to break at a page boundary, simply put it inside a table environment or other box that won't break across pages.

\documentclass{article}
\usepackage{longtable}

\begin{document}
\begin{longtable}{|l|c|c|} % vertical rules for illustrative purposes only
  very long content & setting the widths & of each column \kill
  actual & content & is short \\
  killed & row & discarded
\end{longtable}
\end{document}

enter image description here

1
  • 1
    Ah, I didn't realize longtable had that feature. Thanks. This seems like the cleanest solution. Jan 23, 2015 at 16:59
6

Here is a manual way to achieve what you're after:

enter image description here

\documentclass{article}

\begin{document}

\begin{tabular}{c|c|c}
  \hline
  Something very & long and & written in a \texttt{tabular} \\
  ABC & DEF & GHI \\
  \hline
\end{tabular}

\begin{tabular}{c|c|c}
  \hline
  \phantom{Something very} & \phantom{long and} & \phantom{written in a \texttt{tabular}} \\[-\normalbaselineskip]
  ABC & DEF & GHI \\
  \hline
\end{tabular}

\end{document}

A "vertical back skip" using \\[-\normalbaselineskip] effectively "kills" the row. You may also consider using only \hphantom, depending on the content you want to align.

1
  • I like this solution too but I think using longtable is a bit cleaner. Jan 23, 2015 at 17:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .