0

I've read several forum posts on longtable package, but I'm still really struggling.

I'm trying to insert a table into my thesis, I've used https://www.tablesgenerator.com/ to convert my excel table into Latex and from here I'm manually editing.

The problem is, the table is too wide and too tall. I've used scriptsize text and I've added in the longtable package. I don't want the table in landscape, so that's not an option. It's now breaking over two pages, which I'm happy with. However, I can't see half of the 3rd column and the 4th one at all.

\begin{centering}
\scriptsize
\begin{longtable}{|c|c|c|c|}
\noalign{\vspace*{\fill}}

data here \noalign{\vspace*{\fill}} \end{longtable} \end{centering}

Additionally, is there a way to centre the text in the middle of the box and make the first column narrower? Table in thesis Sorry if I've missed something obvious, I've read the documentation but still can't get my head around it

  • Take a look at the xltabular package. It combines the features of longtable (mid-table page breaks) and tabularx(adjust table to textwidth while allowing linebreaks inside of cells). – leandriis Jul 24 '20 at 17:02
  • Apart from that, you should take a look as one of the packages dedicated to chemical formulae such as chemforumla or mhchem as the current representation of phosphate without proper super- and subscripts just looks wrong. – leandriis Jul 24 '20 at 17:03
  • Thank you, I'll check it out. Yes I am planning to sort out the formulas, I wanted to get the table in thesis first! – Sammie Davies Jul 24 '20 at 17:15
  • @leandriis the xltabular documentation isn't the clearest, how would I begin to build the table? I currently have \begin{xltabular}{\linewidth}{@{} X {}} \centering \begin{tabular}{|l|l|l|l|} \hline *TABLE BODY *\hline \end{tabular} \end{xltabular} but it's not happy! – Sammie Davies Jul 24 '20 at 17:55
  • Replace the longtable with xltabular. Something like \begin{xltabular}{\linewidth}{cXXX} should get you started. What to do exactly depends how wide the contents of your table are. – leandriis Jul 24 '20 at 18:10
  • Additonally, I suggest adding at least one linebreak in the column header of the first column. You can save quite a lot of space here. For this, you can add \usepackage{makecell} \renewcommand{\theadfont}{\normalsize\bfseries} to your preamble and use \thead{first line \\ second line \\ of column header} inside of xltabular. – leandriis Jul 24 '20 at 18:14
  • @leandriis thank you, that worked! What do the cXXX represent for each column? – Sammie Davies Jul 24 '20 at 19:29
  • c would be a centered column that is as wide as the widest content of this column, X is the column type introduced by tabularx. This column type is as wide as the space that is needed to make the overall width of the table equal to the width you declared. (In your case, \textwidth). Linebreaks are automatically added and the text in X type columns is justified. If you want to change that, take a look here: Centering in tabularx and X columns – leandriis Jul 24 '20 at 19:36
  • If you use multiple X type columns, all of them share the same width. If you want to change that, take a look here: Table layout with tabularx (column widths: 50%|25%|25%) Although both linked questions and their answers deal with tabularx, they are applicable to xltabular as well. – leandriis Jul 24 '20 at 19:36
  • @leandriis Ah, ok that makes sense as to why I would want to introduce the line break. Where exactly would \thead{first line \ second line \ of column header} go? I'm getting errors – Sammie Davies Jul 24 '20 at 19:56
  • You could use something like \thead{Approximate \\ Raman shift\\ (cm-1)}. Don't forget to include the makecell package. – leandriis Jul 24 '20 at 19:57
  • Ah brilliant. Thank you so much, @leandriis, I would not have understood it without your help and patience! – Sammie Davies Jul 24 '20 at 20:33

0 Answers0