1

I have a two-page (long)table, on landscape orientation. I would like the first column to be centered-centered, but the remaining columns to be top-left (using makecell).

I would like each row to look like this:

Desired Table

Here is my code:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{array} \usepackage{makecell} \usepackage{geometry} \usepackage{pdflscape} \usepackage{longtable} \usepackage{setspace} \usepackage{lipsum} \usepackage{calc} \newlength{\lw} \setlength{\lw}{2\tabcolsep+\arrayrulewidth} \newcolumntype{R}[1]{>{\raggedright\arraybackslash}m{#1}} \newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}} \newcommand\tab{\hspace{10mm}}

\begin{document}

\newgeometry{margin=1in} \begin{landscape} \singlespacing \begin{longtable}{|M{1.4in-\lw}|R{2.55in-\lw}|R{2.3in-\lw}|R{2.7in-\lw}|} Test Header & Test Header & Test Header & Test Header \ \hline Long First Row Name & \makecell[tl]{Item 1 \ \tab Value 1 \ Item 2 \ \tab Value 2 \ Item 3 \ \tab Value 3 \ Item 4 with a very long name that \ needs two lines \ \tab Value 4} & \makecell[tl]{Item 5 \ \tab Value 5 \ Item 6 \ \tab Value 6} & \makecell[tl]{Item 7 \ \tab Value 7 \ Item 8 \ \tab Value 8} \hline \end{longtable} \doublespacing \end{landscape} \restoregeometry

\end{document}

Here is what it gets me:

Coded Table

What can I do to get my code to match the first table shown?

1 Answers1

2
  • Using tabularray package enable relative simple table code without use of makecell packages.
  • From example of table is not evident, why your table should be in landscape orientation.
\documentclass{article}
\usepackage{geometry}
\usepackage{pdflscape}
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage{tabularray} \newcommand\tab{\par\hspace{2em}} \usepackage{setspace} \doublespacing

\begin{document}

\newgeometry{margin=1in} \begin{landscape} \singlespacing \begin{longtblr}[ caption={longtable}, label={tab:x} ]{% rowhead=1, hlines, vlines, colspec={X[0.7,c,m] *{3}{X[1.1,l,h]}}, row{1} ={font=\bfseries} } Test Header & Test Header & Test Header
& Test Header \ Very, Very Long First Row Name & Item 1 \tab Value 1\par Item 2 \tab Value 2\par Item 3 \tab Value 2\par Item 4 with a very long name that needs two lines \tab Value 4 & Item 5 \tab Value 5\par Item 6 \tab Value 6 & Item 7 \tab Value 7\par Item 8 \tab Value 8 \
% \end{longtblr} \end{landscape}

\end{document}

In table code you may replace all \par commands with empty lines, i.e. write the first two columns as:

% ...
Very, Very Long First Row Name
    &   Item 1
        \tab    Value 1
    Item 2 
    \tab    Value 2

    Item 3
    \tab    Value 2

    Item 4 with a very long name that needs two lines
    \tab    Value 4
    &   Item 5

% rest of table code

In both cases the result of compilations are the same:

enter image description here

Zarko
  • 296,517
  • Thank you! Yes, this could work. Is there a way I can specify the caption formatting? I need it to match the rest of my thesis. – Genevieve Feb 15 '22 at 14:51
  • @Genevieve, my suggestion works for sure ... Regarding caption style: yes, it can be customized. For example, see https://tex.stackexchange.com/questions/628900/ – Zarko Feb 15 '22 at 14:59
  • I was able to format the caption using the built-in \SetTblrStyle commands for tabularray. However, I cannot figure out how to remove the hanging indent for the table caption on continued pages. Any advice? – Genevieve Feb 15 '22 at 15:40
  • @Genevieve, hm, this deserve new question. On such more people will be able to see your problem and consequently able to help you. I Thing, that your basic question is solved (and can be accepted) – Zarko Feb 15 '22 at 15:43
  • Will do. Thank you for all your help! – Genevieve Feb 15 '22 at 15:56