3

My starting point is the following code:

\documentclass{article}
\begin{document}
Section Number: \hfill A01: 8:00--8:50 am \hfill A02: 9:00--9:50 am \hspace*{\stretch{1}}
\end{document}

This produces spacing that I like, but I need another line, which I would like to align against the first line. I thought of putting it in a tabbing environment like so:

\documentclass{article}
\begin{document}

\begin{tabbing}
Section Number:\hfill\=A01: 8:00--8:50 am\hfill\=A02: 9:00--9:50 am \hspace*{\stretch{1}}\\
                     \>A03: 10:00--10:50 am    \>A04: 11:00--11:50 am
\end{tabbing}

\end{document}

But the tabbing environment suppresses the \hfill commands. I know that I can set the spacing explicitly with \hspace commands, but is there a way to set tab stops against stretchy spaces?

7
  • 2
    Isn’t the tabular* environment what you are looking for?
    – GuM
    Jul 16, 2018 at 0:58
  • @GuM Hmm, I wasn't familiar with tabular*. The code \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}lll} gets me pretty close, except that I've lost the space to the right of the last column. How can I get that back? Jul 16, 2018 at 1:12
  • 1
    Well, can’t you simply add one extra column you never use, e.g., \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}llll}? (:-)
    – GuM
    Jul 16, 2018 at 1:28
  • @GuM Figured that out as you were typing! If you want to make it an answer, I'll accept. Jul 16, 2018 at 1:29
  • 1
    \textwidth refers to the full width of the text area, and this might not be what you want: the most obvious example of when this happens is two-column mode, but there are other cases. \linewidth always refers to the width currently used in paragraph justification.
    – GuM
    Jul 16, 2018 at 1:45

1 Answer 1

3

I can get what I want with the tabular* environment:

\documentclass{article}
\begin{document}

\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}llll@{}}
Section Number: & A01: 8:00--8:50 am   & A02: 9:00--9:50 am \\
                & A03: 10:00--10:50 am & A04: 11:00--11:50 am
\end{tabular*}

\end{document}

Note that \linewidth forces the table to fill the width of the line, @{\extracolsep{\fill}} adds the stretchy space between the columns, and the extra column l gives me my space to the right of the last column. Also note the @{} after the last (unused) column, which suppresses the small, but unwanted space at the far right.

2
  • 1
    I took the liberty to slightly refine your answer.
    – GuM
    Jul 16, 2018 at 2:05
  • The &s at the end of each line aren’t necessary either.
    – GuM
    Jul 16, 2018 at 2:15

You must log in to answer this question.

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