0

This has been answered elsewhere, but the solutions I read do not work for my code. I create a table and we can see clearly that the output is not aligned correctly across the rows and the columns. Could someone please help me figure out why this is happening?

Here is my code:

\documentclass{article}
\usepackage{array}
\usepackage[a4]{geometry}
\usepackage{longtable,pdflscape,booktabs}


\begin{document}


\begin{longtable}{m{1.2cm} m{5cm} m{2cm} m{3cm}}

\toprule
\textbf{Chapter} &\textbf{Research question} &\textbf{Data} &\textbf{Method}  \\
\bottomrule
 2 & How does X affect Y? & Facebook and Linkedin & OLS \\ 
 3 &  How does X affect Y?  & Facebook (longitudinal) & Cross-classified and Two way fixed effects \\
  & How does X affect Y?  & &  \\
 4 & How does X affect Y?   & Facebook (longitudinal) & Cross-classified and two-way fixed effects \\
   & How does X affect Y?   && \\
 5 & How does X affect Y?  & Twitter & Bayesian model and machine learning  \\ 
\bottomrule



\end{longtable}

\end{document}

Here is my output:

enter image description here

1
  • 1
    Welcome to TeX.SE.
    – Mico
    Oct 14, 2022 at 20:41

1 Answer 1

1

REVISED ANSWER (which I think does what you want).

I'm not sure what you mean by "the output is not aligned correctly across the rows and columns". You specify the columns as "m" which vertically centers the entries. I think that you want to have the entries top-aligned, in which case use "p" columns.

\begin{longtable}{p(1.2cm) p(5cm) p(3cm)}

For bottom aligned entries use "b" columns.

ORIGINAL ANSWER PLEASE IGNORE THIS as I misinterpreted your question

You specify a longtable with 4 columns. In some cases (e.g 2) you provide the data for 4 columns but in others (e.g 3) you provide data for more columns so you get a result you do not expect.

Provide data for no more than 4 columns.

2
  • I am sorry to ask again but i am not sure i understood completely. In each line i have three & which represent the switches between columns. Then, at the end of each line i have two backslashes \\ to indicate for latex to go to a new line. In some cases, i have two & next to each other without any text in-between to indicate that i want this space to be empty inside the table. Could you please show me how to tweak the code to make everything aligned?
    – Jack
    Oct 15, 2022 at 8:34
  • @Jack I have changed my answer as I think that I had misinterpreted your question. I hope it works for you. Oct 15, 2022 at 18:32

You must log in to answer this question.

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