0

Background

I'm using Overleaf (compiler = XeLaTeX; TexLive version 2021) to write a document. In it, I put tables that I transfer from Excel into TablesGenerator.com that I then drop into my Overleaf document.

Here's a workable example of a table I'm trying to make (ignore the content, it's gibberish on purpose):

\begin{landscape}
\begin{table}[]
\small
\centering
\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{}llll@{}}
\toprule
\multicolumn{1}{c}{Name} & \multicolumn{1}{c}{Label} & \multicolumn{1}{c}{Description}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                & \multicolumn{1}{c}{Code} \\ \midrule
Cars                     & Manufacturers             & Audi, Kia,Volkswagen                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           & 23579                    \\
Providence               & Rhode Island              & \begin{tabular}[c]{@{}l@{}}Immigrant labor powered one of the nation's largest industrial manufacturing centers. Providence was a major manufacturer of industrial products, \\ from steam engines to precision tools to silverware, screws, and textiles. Giant companies were based in or near Providence, such as Brown \& Sharpe,\\  the Corliss Steam Engine Company, Babcock \& Wilcox, the Grinnell Corporation, the Gorham Manufacturing Company, Nicholson File, and the Fruit \\ of the Loom textile company. From 1975 until 1982, \$606 million of local and national community development funds were invested throughout the city. \\ In the 1990s, the city pushed for revitalization, realigning the north–south railroad tracks, removing the huge rail viaduct that separated Downtown from\\  the capitol building, uncovering and moving the rivers (which had been covered by paved bridges) to create Waterplace Park and river walks along the\\  rivers' banks, and constructing the Fleet Skating Rink (now the Alex and Ani City Center) and the Providence Place Mall.\end{tabular} & 2346                     \\ \bottomrule
\end{tabular}
}
\end{table}
\end{landscape}

The problem

I'd like to have the content of the 2nd and 3rd rows be top-aligned inside each cell, and not centered vertically, like they are now.

In other words, I'd like a table that looks like this:

enter image description here

Is there a simple way to do this using tabular, like I am now?

What I've tried

I've searched Tex.SE for solutions to this, and there are dozens of posts about this problem. Most of the ones I read, though, seem to suggest using a different table environment, such as tabularx, which I've attempted to adapt to my example to no avail. I'd prefer to stick with tabular, which even though I don't understand perfectly, I can usually make work.

I seem to have closed the browser tab, but there was another post that suggested using [t] or [p] somewhere in the tabular code, but I can't recall exactly what it was. It's a moot point, sorta, because I tried it and it didn't work.

Is there a straightforward way of doing this in tabular?

5
  • 1
    You would just need to change the inner \begin{tabular}[c] to \begin{tabular}[t] so that the top of the inner table, rather than the middle of the inner table, is aligned with the row's baseline. But why are you using a tabular within a tabular rather than just using a p-type column? And why didn't the tabularx solutions work?
    – frabjous
    Jun 29, 2022 at 19:41
  • 1
    "But why are you using a tabular within a tabular rather than just using a p-type column?" This was the only way I knew how to chop up the text in that cell beginning "Immigrant labor" so that it wouldn't run off the page. The tabularx solutions compiled, but led to a blank space where the table should've been, leaving only the title visible.
    – logjammin
    Jun 29, 2022 at 19:45
  • So like use another inner tabular for each cell, e.g. \begin{tabular}[t]{l} Providence \end{tabular} ? This doesn't seem to do anything.
    – logjammin
    Jun 29, 2022 at 19:48
  • 1
    No. No need for that. Just change the one inner tabular you already have from [c] to [t]. This is what's causing the other cells in the row to be pushed down to its center, rather than aligning with its top.
    – frabjous
    Jun 29, 2022 at 19:52
  • Wow, that did it -- or should I say "oh frabjous day"? Please by all means write that up as an answer, if you like, and I'll close it out.
    – logjammin
    Jun 29, 2022 at 19:55

2 Answers 2

3

When you have multiple cells in the same row, where one of the cells has multiple lines and the others a single line, what determines the vertical placement of the single line cells relative to the one with multiple lines is the vertical placement of the material in the multiline cells relative to the baseline of the row.

In your case, your "big" cell is made up of an inner tabular environment using the [c] option. That means the vertical center of its contents are aligned with the baseline of the row, which is where the other cells will align.

To get the other lines to be aligned with the top of the inner tabular, you need to set its vertical placement to [t] instead of [c], so its top line is aligned with the baseline of the row, and the other cells will align to its top rather than to its middle. (Or you can just remove the [c], since [t] is default for tabulars.)

\begin{landscape}
\begin{table}[]
\small
\centering
\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{}llll@{}}
\toprule
\multicolumn{1}{c}{Name} & \multicolumn{1}{c}{Label} & \multicolumn{1}{c}{Description} & \multicolumn{1}{c}{Code} \\ \midrule
Cars & Manufacturers & Audi, Kia,Volkswagen & 23579 \\
Providence & Rhode Island & \begin{tabular}{@{}l@{}}Immigrant labor powered one of the nation's largest industrial manufacturing centers. Providence was a major manufacturer of industrial products, \\ from steam engines to precision tools to silverware, screws, and textiles. Giant companies were based in or near Providence, such as Brown \& Sharpe,\\ the Corliss Steam Engine Company, Babcock \& Wilcox, the Grinnell Corporation, the Gorham Manufacturing Company, Nicholson File, and the Fruit \\ of the Loom textile company. From 1975 until 1982, \$606 million of local and national community development funds were invested throughout the city. \\ In the 1990s, the city pushed for revitalization, realigning the north–south railroad tracks, removing the huge rail viaduct that separated Downtown from\\ the capitol building, uncovering and moving the rivers (which had been covered by paved bridges) to create Waterplace Park and river walks along the\\ rivers' banks, and constructing the Fleet Skating Rink (now the Alex and Ani City Center) and the Providence Place Mall.\end{tabular} & 2346 \\ \bottomrule
\end{tabular}
}
\end{table}
\end{landscape}

However, since the contents of your "big cell" is basically a paragraph of text, and not really a table in its own right, it's odd that you're using an inner tabular environment at all. Instead of using l for its column specifier you could typeset the contents of that in a parbox of a given width using p{5in} or similar instead of l for the third column.

This would have a similar effect to using [t] for the inner tabular, but you wouldn't have to manually add line breaks in the paragraph.

Even better, you could use the tabularx package and use the X column specifier. This way, the column will expand to fill the available room, and there likely wouldn't be a need for the resizebox.

You said you were having trouble with that package, but it's not clear why you were having trouble.

Here's the code I would suggest:

\documentclass{article}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}

\begin{landscape}
\begin{table}[htb]
\small
\centering
\begin{tabularx}{\columnwidth}{@{}llp{5in}l@{}}
\toprule
\multicolumn{1}{c}{Name} & \multicolumn{1}{c}{Label} & \multicolumn{1}{c}{Description} & \multicolumn{1}{c}{Code} \\ \midrule
Cars & Manufacturers & Audi, Kia,Volkswagen & 23579 \\
Providence & Rhode Island & \raggedright Immigrant labor powered one of the nation's largest industrial manufacturing centers. Providence was a major manufacturer of industrial products, from steam engines to precision tools to silverware, screws, and textiles. Giant companies were based in or near Providence, such as Brown \& Sharpe, the Corliss Steam Engine Company, Babcock \& Wilcox, the Grinnell Corporation, the Gorham Manufacturing Company, Nicholson File, and the Fruit of the Loom textile company. From 1975 until 1982, \$606 million of local and national community development funds were invested throughout the city. In the 1990s, the city pushed for revitalization, realigning the north–south railroad tracks, removing the huge rail viaduct that separated Downtown from the capitol building, uncovering and moving the rivers (which had been covered by paved bridges) to create Waterplace Park and river walks along the rivers' banks, and constructing the Fleet Skating Rink (now the Alex and Ani City Center) and the Providence Place Mall.& 2346 \\ \bottomrule
\end{tabularx}
\end{table}
\end{landscape}
\end{document}

tabularx output

1
  • This is extremely helpful, not just for being what I was looking for, but for opening the door wide open to make LaTeX tables in a better way. Thank you so much again.
    – logjammin
    Jun 29, 2022 at 20:06
1

I would use tabularray package and not nested tabular in cell:

\documentclass{article}
\usepackage{microtype}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\usepackage{pdflscape}

\begin{document}
\begin{landscape}
    \begin{table}[]
    \small
\begin{tblr}{colspec={@{} ll X[j] c @{}},
             row{1}={font=\bfseries, c}
             }
    \toprule
Name    &   Label       &   Description         &   Code    \\ 
    \midrule
Cars    & Manufacturers & Audi, Kia,Volkswagen  & 23579     \\
Providence               
        & Rhode Island  & Immigrant labor powered one of the nation's largest industrial manufacturing centers. Providence was a major manufacturer of industrial products, from steam engines to precision tools to silverware, screws, and textiles. Giant companies were based in or near Providence, such as Brown \& Sharpe, the Corliss Steam Engine Company, Babcock \& Wilcox, the Grinnell Corporation, the Gorham Manufacturing Company, Nicholson File, and the Fruit of the Loom textile company. From 1975 until 1982, \$606 million of local and national community development funds were invested throughout the city.  In the 1990s, the city pushed for revitalization, realigning the north–south railroad tracks, removing the huge rail viaduct that separated Downtown from the capitol building, uncovering and moving the rivers (which had been covered by paved bridges) to create Waterplace Park and river walks along the rivers' banks, and constructing the Fleet Skating Rink (now the Alex and Ani City Center) and the Providence Place Mall.
                                                & 2346      \\ 
    \bottomrule
\end{tblr}
    \end{table}
\end{landscape}
\end{document}

enter image description here

You must log in to answer this question.

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