3

While creating a table in LaTeX, I encountered some unexpected behavior. I started out with Table 1 in the MWE below. However, I didn't like the appearance because it didn't fill the entire width of the page.

My understanding of tabular was that, by adding @{\extracolsep{\fill}}, I would insert exactly the right amount of space in such that the tabular environment fills the entire width. However, I was surprised to see that the spacing between other columns that I surround with @{} increased. I would have expected that these columns ((2 and 3) and (4 and 5) in the MWE) remained close together.

Some more experimentation seems to suggest that the position of this "filler" column is important, as Table 3 in the MWE behaves like I would have expected. Specifically, Columns 4 and 5 are pushed apart, but Columns 2 and 3 remain tight.

How do I push columns 1 and 2 apart, without affecting the positioning of the other columns? Any why is Table 2 not the right way to do it?

\documentclass{article}
\begin{document}
\begin{table}
    \centering
    % Table 1
    \begin{tabular*}{\linewidth}{@{}lc@{}rc@{}r@{}}
        Left & Center & Right & Center & Right \\
        \hline
        Text & Text & Text & Text & Text \\
    \end{tabular*}

    % Table 2
    \begin{tabular*}{\linewidth}{@{}l@{\extracolsep{\fill}}c@{}rc@{}r@{}}
        Left & Center & Right & Center & Right \\
        \hline
        Text & Text & Text & Text & Text \\
    \end{tabular*}

    % Table 3
    \begin{tabular*}{\linewidth}{@{}lc@{}rc@{\extracolsep{\fill}}r@{}}
        Left & Center & Right & Center & Right \\
        \hline
        Text & Text & Text & Text & Text \\
    \end{tabular*}

\end{table}
\end{document}
1
  • I use TeXStudio for editing. Its help on LaTeX states: "An \extracolsep{wd} command in an @-expression causes an extra space of width wd to appear to the left of all subsequent columns, until countermanded by another \extracolsep. Unlike ordinary intercolumn space, this extra space is not suppressed by an @-expression.". The way I understand this another \extracolsep{0pt}, or so, is required to switch off the insertion of filling space
    – Ronald
    Apr 12 at 7:41

1 Answer 1

3

As far as I understand your question, you're looking for something like

\documentclass{article}
\begin{document}
\begin{table}
    \centering
    % Table 2
    \begin{tabular*}{\linewidth}{@{}l@{\extracolsep{\fill}}c@{\extracolsep{0pt}}rc@{}r@{}}
        Left & Center & Right & Center & Right \\
        \hline
        Text & Text & Text & Text & Text \\
    \end{tabular*}
\end{table}
\end{document}
1
  • Yes, this works. After reading your answer, I also found texfaq.org/FAQ-fixwidtab . It mentions that extracolsep applies to everything to its right, so i guess it works by redefining a width under the hood...
    – Shffl
    Apr 12 at 9:41

You must log in to answer this question.

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