2

I know this has to be somewhere, so a link to the right question would be helpful; my google-fu keeps returning the incorrect version of what I want (clarified below).

Goal: I want to be able to have a tabular environment that spans some fixed width (say, for example, the entire width of the page), with multiple columns, where specific columns have contents that are left justified, but whose text is centered within the column.

For example;

\documentclass{article}
\begin{document}
\begin{center}
    \begin{tabular}{llll}
        \textbf{\Large{Semester}} & \textbf{\large{Start Date}} 
               & \textbf{\large{End Date}} & \textbf{\large{Last Day of Finals}}\\
        \textbf{Summer A} & May 1st & June 2nd & June 5th \\[5pt]
        \textbf{Summer B} & June 1st & August 25th & August 30th \\[5pt]
        \textbf{Summer C} & August 1st & August 20th & August 30th \\
    \end{tabular}
\end{center}
\end{document}

That currently prints a centered table, with all left-justified columns. I would like to:

  1. Be able to manually change the width of the table (I currently only know how to do this with tabularx, but there's got to be another way; preferably one that doesn't require packages that aren't loaded by the article class automatically)
  2. Once the table is wider, to make the text in the second column still be left justified, but centered within the (now artificially wider) column.

As I say, this has to be a pretty normal issue that has been answered a hundred times, but when I try to search it I am only finding people looking to center the table itself with left-justified contents within the table. I figure for most cases the table is automatically width-adjusted, so centering a left-justified column doesn't make sense... but if you make the column artificially wider than the text demands, the left-justified looks rather strange, hence my question.

For clarity, I'm aiming for a certain aesthetic of having text in that column sort of `floating' in the midst of the table. I realize this is a pretty specific use-case and there's lots of reasons to normally not want to do this and instead do something else which would "look better". However, I am trying to figure out how to typeset this specific feature regardless, and I can't seem to figure out what to use.

As I said at the start, even simply linking me to an existing question that has an answer to this would be great, and I shall bow to your superior search skills.

EDIT: Also forgot another point; if I have a long header (eg the header "Last Day of Finals" in the MWE above) in a table, but the rest of the column is relatively short (horizontally) data, this would be another aspect where I would like the data below the "header" of that column to be centered relative to the header, but still have all the data left-justified relative to itself... if that makes sense.

Thanks!

1
  • makes no difference here but \large{Start Date} should be \large Start Date , size commands do not take an argument. Commented Jan 28, 2019 at 17:42

1 Answer 1

2

You can use tabular* to force the table width, centering the headings over the width requires a bit of fiddling around, but perhaps

enter image description here

\documentclass{article}
\usepackage{array}
\newcommand\hd[1]{\multicolumn{1}{c}{\textbf{\large#1}}}

\begin{document}

\begin{center}
    \begin{tabular*}{\textwidth}{
!{\extracolsep{\fill}}
l
>{\kern10pt}l<{\kern10pt}
>{\kern5pt}l<{\kern5pt}
>{\kern25pt}l<{\kern25pt}
!{}}
        \hd{Semester} & \hd{Start Date}
               & \hd{End Date} & \hd{Last Day of Finals}\\[5pt]
        \textbf{Summer A} & May 1st & June 2nd & June 5th \\[5pt]
        \textbf{Summer B} & June 1st & August 25th & August 30th \\[5pt]
        \textbf{Summer C} & August 1st & August 20th & August 30th \\
    \end{tabular*}
\end{center}
\end{document}
2
  • In practice it looks great; but can you explain what is going on in the second argument of the \begin{tabular*} environment? The section with the \kernXXpt. I've never seen the \kern command before, and the formating (with the ! and > symbols) looks a bit odd to me as well?
    – Jason
    Commented Jan 29, 2019 at 21:10
  • 1
    \kern is basically a form of \hspace which is better here as the latex table code removes "normal" white space around table cells. The > and < are array package syntax (see the package doc which adds the supplied token at teh beginning and end of every cell, so basically I am just inserting a space to the left and right of each number to force the column to be wider, but with the numbers centred. Commented Jan 29, 2019 at 21:20

You must log in to answer this question.

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