1

I'm doing my PhD thesis, I'm new on LaTeX and I'm struggling with my tables. As seen here: https://i.stack.imgur.com/LL6sH.jpg my table spans two pages, but in the second page it doesnt align properly.

I already used tabularx, longtable and \setlength\LTleft{-1cm} but nothing seems to help, also read other Q&A about it, and the problem persists. I need my tables to span multiple pages, the table must be centered and the caption start at the left. The table is wide, but I need it to shrink it into a portrait layout.

I have the next code which gives me a table spanning two pages, but in the second one, the table doesn't align properly, it moved about certain pixels towards the right:

\documentclass[a4paper,12pt,times,numbered,print,index]{Classes/PhDThesisPSnPDF}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PREAMBLE: Contains packages and user-defined commands and settings
\usepackage{booktabs}
\usepackage{ltablex}
\usepackage{dcolumn,tabularx,booktabs}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{adjustbox} %para ajustar las tablas
\usepackage{ltablex}
\usepackage{textcomp}
\usepackage{siunitx}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% APPENDICES

\begin{appendices} % Using appendices environment for more functunality
\include{Appendix2/appendix2}
\end{appendices}


%%%%%%%%%%%%%%%%%%%%
%appendix2.tex file
\subsection{CSH table for peptide xxxx in xxxx mM DPC}
\label{table:CSH-xxxxx-DPC} 
\setlength\LTleft{-1cm}
\begin{tabularx}{\linewidth}{lllll lllll lll}
\caption{chemical shifts (ppm from DSS)  for peptide ----}\\  

\endfirsthead
 \endhead

\toprule
\multicolumn{2}{l}{\textbf{Residue}}   &
\textbf{HN}  & 
\textbf{ H\textalpha }& 
\textbf{H\textbeta}  &   
\textbf{H\textgamma }   &
\textbf{H\textdelta }   &
\textbf{H\textepsilon }     &   
\textbf{H\textzeta }   &
\textbf{C\textalpha  } 
\\[6pt]
\midrule


Arg &   845 &   7.37    &   7.37    &   7.37    ,   7.37    &   7.37    ,   7.37            &   7.37    ,   7.37    &   7.37        7.37    &   6.70    ,   6.57    &   56.76   \\


\bottomrule
\end{longtable}
\clearpage

Thank you

7
  • Welcome to TeX SX! Why do you use tabularx since you have no X column? Also, did you compile twice?
    – Bernard
    Oct 9, 2017 at 9:51
  • Thank you for the welcome: I used tabularx because it was what it was working for me to span the table into multiple pages, I tried tabular alone and got several errors. I compiled twice and the problem persists. Thanks for the help
    – DNA
    Oct 9, 2017 at 9:54
  • you not use longtable but tabularx. if you like to have it over two (or more) pages, you need to load ltablex package. to help you, we need to see complete small document with related packages in preamble no just code snippet.
    – Zarko
    Oct 9, 2017 at 9:55
  • Thank you, I will try. When I used longtable I got several errors too. I will attach now more code.
    – DNA
    Oct 9, 2017 at 9:57
  • @Zarko I already tried with longtable, but the problem persists.
    – DNA
    Oct 9, 2017 at 10:03

2 Answers 2

1

edit:

after your response i second review my answer again ... and find some glitches in code, which arise from not understanding of table context. now i suspect, that table actually has nine columns. in answer for document class i use book instead PhDThesisPSnPDF which i haven't.

you can use tabularx, but in this case at least one column had to be of X type:

\documentclass[a4paper,12pt,times,numbered,print,index]{report}%{Classes/PhDThesisPSnPDF}
\usepackage[showframe]{geometry}

\usepackage{booktabs, ltablex}
\newcommand\mcbf[1]{\multicolumn{1}{c}{\textbf{#1}}}    % <-- added

\usepackage{textcomp}
\usepackage{siunitx}

\usepackage[version=4]{mhchem}    % <-- added

\begin{document}
\setlength\LTcapwidth{\linewidth}  % <-- added
\keepXColumns                      % <-- added
\small                             % <-- added
\setlength\tabcolsep{5pt}          % <-- added 
\begin{tabularx}{\linewidth}{*{10}{X}}
\begin{tabularx}{\linewidth}{@{} X*{8}{l} @{}}
\caption{\ce{^1H} and \ce{^13 C\alpha} chemical shifts (ppm from DSS)  for peptide --- in \ce{H2O}/\ce{D2O} (9:1 v/v), \SI{30}{mM} DPC, pH 3.5, \SI{35}\degreeCelsius}\\
    \toprule
 \textbf{Residue}       &
\mcbf{HN}               &
\mcbf{\ce{H\alpha}}     &
\mcbf{\ce{H\beta}}      &
\mcbf{\ce{H\gamma}}     &
\mcbf{\ce{H\delta}}     &
\mcbf{\ce{H\epsilon}}   &
\mcbf{\ce{H\zeta}}      &
\mcbf{\ce{C\alpha}}   \\
     \midrule
\endfirsthead
% table headers on the next page
\caption{\ce{^1H} and \ce{^13 C\alpha} chemical shifts \dots (cont.) }  \\
    \toprule
 \textbf{Residue}       &
\mcbf{HN}               &
\mcbf{\ce{H\alpha}}     &
\mcbf{\ce{H\beta}}      &
\mcbf{\ce{H\gamma}}     &
\mcbf{\ce{H\delta}}     &
\mcbf{\ce{H\epsilon}}   &
\mcbf{\ce{H\zeta}}      &
\mcbf{\ce{C\alpha}}   \\
     \midrule
\endhead
    \bottomrule
\multicolumn{9}{r}{\footnotesize\itshape continue on the next page} % <-- added
\endfoot
\endlastfoot
%%%% table body
Arg 845 &   7.37    &   7.37    &   7.37, 7.37    &   7.37, 7.37    &   7.37, 7.37
    &   7.37 7.37   &   6.70, 6.57  &   56.76   \\
Arg 845 &   7.37    &   7.37    &   7.37, 7.37    &   7.37, 7.37    &   7.37, 7.37
    &   7.37 7.37   &   6.70, 6.57  &   56.76   \\
% ... 
    \bottomrule    
\end{tabularx}

\end{document}

this code need to be compiled three times that it obtain correct form.

  • changes in code are indicated by % <-- added.
  • i suggest to use
    • mhchem packages for chemistry formulas,
    • siunity package for units.
  • because the table is slightly wider than text width two measures are considered (if this is not the case with original document case, you can remove this change):
    • \small font size is used
    • reduced is distance between columns from default value of 6pt to 5pt

enter image description here

enter image description here

enter image description here

enter image description here

2
  • Thank you very much for your help, that works perfectly. Also thank you for the suggestions in using the SI units and the "continue on the next page".
    – DNA
    Oct 10, 2017 at 7:01
  • @DNA, see edited answer. if answer solve your problem, you can accept it by clicking on up-pen at top left side of answer :-). by the way, structure of your table is not clear to me. i suspect that the first two columns should be merged and contents of merged cells is Arg 845.
    – Zarko
    Oct 10, 2017 at 10:12
0

Thank you @Bernard and @Zarko, I finally found the problem:

I changed now to longtable and added the following lines:

\setlength\LTleft{-1cm}
\setlength\LTright{-1cm}
\begin{longtable}{lllll lllll lll}

%%%%%%content

\bottomrule
\end{longtable}
\clearpage

You must log in to answer this question.

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