1

I'd like to use "p" formatting in my longtable, and I'd like each column to be about 1 inch wide. I understand that there's some intercolumn spacing, so I used @{} to suppress that as much as possible. And I also understand that the vertical lines between cells take up a little space. Anyhow, I tried this:

\documentclass{scrartcl}
\usepackage{longtable}

\begin{document}

\hspace*{0.53in}\rule{4in}{0.4pt}

\noindent\begin{longtable}%
{%
@{}|p{1in}%
@{}|p{1in}%
@{}|p{1in}%
@{}|p{1in}|@{}}\hline%
ABC&  &  &   \\\hline
\end{longtable}
\end{document}

This produces a longtable that's about 4.5 inches wide, i.e., each column is about 1/8 inch wider than what I asked for. Sure, I can fiddle with the numbers, but this table is being generated by a program, so it'd be nice to get it right in some way that doesn't involve a brilliant tailor.

2
  • @{} on both sides of the |.
    – daleif
    Jul 9, 2020 at 13:44
  • You are my new hero. :)
    – John
    Jul 9, 2020 at 13:46

2 Answers 2

1

This table will be 4in plus 2pt wide (because of the five rules' width).

Note that \noindent does nothing at all in front of a longtable.

\documentclass{article}
\usepackage{longtable}

\begin{document}

\begin{longtable}{
  @{\vline}p{1in}
  @{\vline}p{1in}
  @{\vline}p{1in}
  @{\vline}p{1in}
  @{\vline}
}
\hline
Abc & Def & Ghi jkl mno pqr stu & vw xyz \\
\hline
\end{longtable}

\end{document}

On the other hand, the text will touch the rules.

enter image description here

If you want to have the rules just in the document preparation phase, it could be handy to define a new column type. In the example below I redefine the column type just to emulate what happens if you switch the comment in the two lines in the preamble.

\documentclass{article}
\usepackage{longtable,array}

\newcolumntype{?}{@{\vline}}\newcommand{\yline}{\hline}
%\newcolumntype{?}{@{}}\newcommand{\yline}{}

\begin{document}

\begin{longtable}{
  ?p{1in}
  ?p{1in}
  ?p{1in}
  ?p{1in}
  ?
}
\yline
Abc & Def & Ghi jkl mno pqr stu & vw xyz \\
\yline
\end{longtable}

% just to show what happens if you switch the comments in the preamble
\newcolumntype{?}{@{}}\renewcommand{\yline}{}

\begin{longtable}{
  ?p{1in}
  ?p{1in}
  ?p{1in}
  ?p{1in}
  ?
}
\yline
Abc & Def & Ghi jkl mno pqr stu & vw xyz \\
\yline
\end{longtable}

\end{document}

enter image description here

4
  • Thanks for letting me know how much the "rules" are going to "cost". To be honest, I'm using them only in the debugging/layout phase, so having the text crammed up against them is exactly the desired behavior.
    – John
    Jul 9, 2020 at 14:15
  • @John Yes, the default value for the rule's width is 0.4pt
    – egreg
    Jul 9, 2020 at 14:19
  • @John I added some code to ease the transition from the debugging to the final stage.
    – egreg
    Jul 9, 2020 at 14:28
  • That's similar to what I've got --- "\vb" is defined to be a vertical-bar-or-nothing, and \oline is defined to be an \hline-or-nothing. And the "debug" macro turns both of them (and some other stuff) on and off. I definitely like the use of "newcolumntype" though --- very elegant.
    – John
    Jul 9, 2020 at 15:53
0

Here's a revised table-spec for others to copy from, based on @daleif's comment:

\noindent\begin{longtable}%
{%
@{}|@{}p{1in}%
@{}|@{}p{1in}%
@{}|@{}p{1in}%
@{}|@{}p{1in}@{}|@{}}\hline%
ABC&  &  &   \\\hline
\end{longtable}

You must log in to answer this question.

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