0

I am in the process of writing my PhD thesis in chemistry and I seem to be having a problem with the table/tabularx instances. I have a lot of tables and I also have several longtables (which seem to always break properly). I am struggling to tell if it is all of the tabularx environments that cause the problem as the issue seems to move around depending on the positions of text/tables but I seem to consistently see the content of the page continue off of the page (text and tables do it)Snapshot of Problem Table scheme

\documentclass[a4paper, draft=true,11pt, openany]{scrbook}
% !BIB TS-program = biber

\usepackage[scaled]{helvet}
    \renewcommand\familydefault{\sfdefault} 
\usepackage[T1]{fontenc}
    \fontfamily{phv}\selectfont
\usepackage{textgreek}
\usepackage[margin=2.5cm]{geometry}             % Easy page layout
\usepackage{indentfirst}  %indents the first line after a section or chapter
\usepackage[section]{placeins} %should keep tables and figures in their sections
\usepackage{setspace}
    \onehalfspacing
\usepackage{lipsum}
\usepackage{graphicx}

%%%%%%%%%%%%Crap for Tables%%%%%%%%%%%%%%
\usepackage{array}
\usepackage{booktabs}               % Better table layouts
\usepackage{tabularx}               %Package to set table widths
\usepackage{ltablex}                %For Tables that overflow a row
\keepXColumns
\usepackage[svgnames,table]{xcolor} % note the table option

\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}} %\rownum is a counter for table rows

\newcolumntype{C}[1]{>{\centering}m{#1}} %manual width column widths
\newcolumntype{Y}{>{\centering\arraybackslash}X} %Autospaced column widths with centre alignment
\newcolumntype{F}{S[table-format=2,table-space-text-post=\footnotemark]} %column aligned in center to right digit ignoring superscript

\renewcommand{\arraystretch}{1.1} 

\usepackage{siunitx}
\sisetup{detect-all}
\usepackage{multicol}   % i think this is for columnd articles, can probably disable
%%%%%%%%%%%%Crap for Tables%%%%%%%%%%%%%%

\usepackage[version=3]{mhchem}      % Formula subscripts using \ce{}

\newcommand{\SupS}[1]{\textsuperscript{#1}} %modified SuperScript command
\usepackage[font=footnotesize,labelfont=bf,hypcap=false,singlelinecheck=false]{subcaption}
\setcapindent{0pt}    %setting cation indent to 0
\newcommand{\SubCap}[1]{\unskip\parbox{\columnwidth}{\raggedright\footnotesize{#1}}}  %My own subcaption command used under tabularx within table environment  


\def\pdfshellescape{1}

\begin{document}

\lipsum

\lipsum

\begin{table}[ht]  %Table 1

    \begin{tabularx}{\textwidth}{YYYFY}
        \toprule
        \textbf{Entry\SupS{a}}&\textbf{Ligand}&\textbf{Bite angle}& \textbf{Yield(\%)\SupS{b}}  &   \textbf{E:Z}\\ 
        \midrule
        \rownumber  &\ce{P(2-furyl)3}&  --  &27 &   1:3\\
        \rownumber  &\ce{PPh3}          &   --  &22 &   1:4\\
        \rownumber  &\ce{P(2-Tol)3} &   --  &13 &   1:2\\
        \rownumber  &\ce{PPh2Cy}    &   --  &3  &   1:2\\   
        \rownumber  &\ce{P(4-F-Ph)} &   --  &37 &   1:4\\
        \rownumber  &\ce{P(4-CF3-Ph)}&  -- &35  &   1:5\\
        \rownumber  &DavePhos           &   --  &12 &   1:3\\
        \rownumber  &XPhos                  &   --  &12 &   1:1\\
        \rownumber  &dppm                   & 72    & 79    &   1:4\\
        \rownumber  &dppe                   &   85 & 80 &   1:4\\
        \rownumber  &dppp                   &   91  & 79    &   1:4\\
        \rownumber  &dppf                   &   96  & 83    &   1:4\\
        \rownumber  &DPEPhos            &   102 &86\SupS{c}&1:4\\
        \rownumber  &NixantPhos     &   {~}114  &12 &   1:2\\
        \rownumber  &BINAP                  &   92 &48  &   1:4\\
        \rownumber  &AnthPhos           &   --  &36 &   1:4\\
        \bottomrule
    \end{tabularx}
    \SubCap{Sub-caption text}
\end{table}
    \setcounter{magicrownumbers}{0}





\begin{table}[htb] %Table2

    \begin{tabularx}{\textwidth}{YC{5cm}FY}
        \toprule
        \textbf{Entry\SupS{a}}&\textbf{Pd Source}&\textbf{Yield(\%)\SupS{b}}&\textbf{E:Z}\\ 
        \midrule
        \rownumber  &\ce{Pd2(dba)3.CHCl3} (2.5 mol{\%}) &86\SupS{c} &   1:4         \\
        \rownumber  &\ce{Pd(OAc)2} (5.0 mol\%)              &79                 &   1:4         \\  
        \rownumber  &\ce{Pd(dba)2} (5.0 mol\%)              &85\SupS{c} &   1:4         \\
        \rownumber  &\ce{Pd(Cp)Cinammyl} (5.0 mol\%)&80                 &   1:5         \\
        \rownumber  &\ce{PdCl2(PPh3)2} (5.0 mol\%)      &50                 &   1:4         \\
        \rownumber  &\ce{Pd(allyl)(COD)BF4} (5.0 mol\%)&60                  &   1:4         \\
        \rownumber  &\ce{Pd(OPiv)2} (5.0 mol\%)         &36                 &   1:5         \\
        \bottomrule
    \end{tabularx}
    \SubCap{Sub-caption text}
\end{table}
\setcounter{magicrownumbers}{0}





\begin{table}[htb] %Table 3

    \begin{tabularx}{\textwidth}{YYFY}
        \toprule
        \textbf{Entry\SupS{a}}&Acetal equiv.&\textbf{Yield(\%)\SupS{b}}&\textbf{E:Z}\\ 
        \midrule
        \rownumber  &               1.5         &86\SupS{c}                 &   1:9         \\
        \rownumber  &               1.1         &78                 &   1:7         \\
        \rownumber  &               2.0         &84                 &   1:8         \\
        \rownumber  &               3.0         &72                 &   1:7         \\
        \bottomrule
    \end{tabularx}
    \SubCap{Sub-caption text}
\end{table}
\setcounter{magicrownumbers}{0}
\lipsum[1-2]



\begin{table}[ht]  %Table 4

    \begin{tabularx}{\textwidth}{YYFY}
        \toprule
        \textbf{Entry\SupS{a}}&tether premix time&\textbf{Yield(\%)\SupS{b}}&\textbf{E:Z}\\ 
        \midrule
        \rownumber  &               60 min          &80\SupS{c}                 &   1:9         \\
        \rownumber  &               10 min          &83                 &   1:9     \\
        \rownumber  &               0 min           &83\SupS{c}                 &   1:9         \\
        \rownumber  &               Direct addition         &84                 &   1:8         \\
        \bottomrule
    \end{tabularx}
    \SubCap{Sub-caption text}
\end{table}
\setcounter{magicrownumbers}{0}


\begin{table}[htb]  %Table 5

    \begin{tabularx}{\textwidth}{YYYY}
        \toprule
        \textbf{Entry\SupS{a}}&Comment&\textbf{Yield(\%)\SupS{b}}&\textbf{E:Z}\\ 
        \midrule
        \rownumber  &               Ligand: XantPhos            &   trace  &    --  \\
        \rownumber  &               Base: \ce{Cs3PO4}           &   69      &   1:6 \\
        \rownumber  &               Addition of CsOTf           &   73          &   1:7         \\
        \bottomrule
    \end{tabularx}
    \SubCap{Sub-caption text}
\end{table}
\setcounter{magicrownumbers}{0}

\lipsum

\end{document}
8
  • Please make this a minimal as possible and also make it self contained, it refers to images we do not have access to. You can instead use the images that comes with the mwe package. – daleif Oct 14 '19 at 14:08
  • 1
    You sould probably also learn to use siunitx to format units, instead of those 60 \degree C etc – daleif Oct 14 '19 at 14:17
  • I added a link to the image in the post. The scheme is an .eps and uses psfrags. I wasn't sure if it was important. – Phildgg Oct 14 '19 at 14:18
  • Erh, you added a link to a PNG. I would start by taking your MWE, then remove all the psfrag stuff, is the problem still there? It probably is. Then repeat to get this down to something minimal. – daleif Oct 14 '19 at 14:27
  • Might I suggest \newcommand{\SubCap}[1]{\unskip\parbox{\columnwidth}{\raggedright\footnotesize{#1}}}? It doesn't solve the problem, but it is related. LaTeX is getting very confused about how big the table actually is. – John Kormylo Oct 14 '19 at 14:49
2
  • Your MWE doesn't reproduce described problem
  • tabularx table, which can be fit on one page and encapsulated into table float cannot protrude out of page

Edit:

  • above statements hold as long as you not load ltablex or xltabular packages. Both can cause that tables even in tabular float environment in some circumstances can protrude through text bottom.

  • This undesired features of these package you can avoid on two ways:

    • not use these packages, i.e. stick with solution proposed @egreg
    • with use of these package you to move insertion point of a table for some text lines up or down.

Some off-topic recommendation:

  • For table is better to use standardized caption than to define own. If you not like to have them numbered and with label "table" than use it as \caption*{...}
  • Tables usually have captions above table.
  • Automated numbering of table can be simplified with the following column specification:
>{\rownumber}r<{\qquad\quad}
  • Resetting table numbering can be done with use of etoolbox facility:
\usepackage{etoolbox}
\AtBegindEnvironment{<table environmentr>}{\setcounter{magicrownumbers}{0}}
  • For notes in table is handy to use threepattable package and its macro \tnote. It also enable to add table notes and accommodate text to table width (in case when you like to have tables narrower from text width.
  • For columns with numbers I would use S columns types defined in the siunitx package. It is also usable in writing of units.

An example of MWE, which use xltabular for long table as well for standard tabularx table and consider aforementioned recommendations. Unfortunately it not solve your basic problem strictly, but avoids it quite well (see tables inserting points in text, marked by red text and positions of tables).

\documentclass{article}
\usepackage[margin=2.5cm]{geometry}     % Easy page layout
\usepackage{lipsum}                     % for dummy texts
\usepackage{graphicx}                   % for including figures
\usepackage[version=4]{mhchem}          % Formula subscripts using \ce{}
\usepackage{ragged2e}                   % ragged with smart hyphenation
\usepackage{booktabs, makecell, multirow, xltabular, threeparttable}
\renewcommand\theadfont{\bfseries\small}
\newcolumntype{C}{>{\Centering}X}
\newcolumntype{L}{>{\RaggedRight}X}
\newcolumntype{R}{>{\RaggedLeft}X}
\newcommand\mcx[1]{\multicolumn{1}{>{\bfseries}C}{#1}}
\newcommand\mccx[1]{\multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep\relax
                                      \bfseries}C}{#1}}
%
\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\themagicrownumbers}
\usepackage[table, dvipsname]{xcolor}
\usepackage{siunitx}
\usepackage[skip=1ex,
            font=footnotesize,
            singlelinecheck=false]{caption}

\usepackage{etoolbox}
\AtBeginEnvironment{xltabular}{\setcounter{magicrownumbers}{0}}

\begin{document}
\lipsum[11] \textbf{\textcolor{red}{Tab. 1 inserting point}}
    \begin{table}[ht]
\begin{threeparttable}
\begin{xltabular}{\linewidth}{%
                    >{\rownumber}r<{\qquad\qquad}
                                 X
                                 S[table-format=3]
                                 S[table-format=2,
                                   table-space-text-post={$^{m}$}]
                                 C
                                }
    \caption{My caption}
\label{my-label}                \\
    \toprule
\mcx{Entry\tnote{a}}
    &  \mcx{Ligand}
        &  \mcx{Bite angle}
            &  \mcx{Yield (\%)\tnote{b}}
                &   \mcx{E:Z}   \\
    \midrule
    & \ce{P(2-furyl)3}      & {--}  & 27    &   1:3         \\
    &   \ce{PPh3}           & {--}  & 22            &   1:4 \\
    &   \ce{P(2-Tol)3}      & {--}  & 13            &   1:2 \\
    &   \ce{PPh2Cy}         & {--}  & 3             &   1:2 \\
    &   \ce{P(4-F-Ph)}      & {--}  & 37            &   1:4 \\
    &   \ce{P(4-CF3-Ph)}    & {--}  & 35            &   1:5 \\
    &   DavePhos            & {--}  & 12            &   1:3 \\
    &   XPhos               & {--}  & 12            &   1:1 \\
    &   dppm                &  72   & 79            &   1:4 \\
    &   dppe                &  85   & 80            &   1:4 \\
    &   dppp                &  91   & 79            &   1:4 \\
    &   dppf                &  96   & 83            &   1:4 \\
    &   DPEPhos             & 102   & 86\tnote{c}   &   1:4 \\
    &   NixantPhos          & 114   & 12            &   1:2 \\
    &   BINAP               &  92   & 48            &   1:4 \\
    &   AnthPhos            & {--}  & 36            &   1:4 \\
     \bottomrule
\end{xltabular}\vspace{-\baselineskip}
    \begin{tablenotes}[para, flushleft]
    \item[a]    text;
    \item[b]    text;
    \item[c]    text.
    \end{tablenotes}
\end{threeparttable}
    \end{table}
\lipsum[12] \textbf{\textcolor{red}{Tab. 2 inserting point}}
    \begin{table}[ht]
\begin{threeparttable}
\begin{xltabular}{\linewidth}{%
                    >{\rownumber}r<{\qquad\qquad}
                                 X
                                 S[table-format=3]
                                 S[table-format=2,
                                   table-space-text-post={$^{m}$}]
                                 C
                                }
    \caption{My caption}
\label{my-label}                \\
    \toprule
\mcx{Entry\tnote{a}}
    &  \mcx{Ligand}
        &  \mcx{Bite angle}
            &  \mcx{Yield (\%)\tnote{b}}
                &   \mcx{E:Z}   \\
    \midrule
    &   DPEPhos             & 102   & 86\tnote{c}   &   1:4 \\
    &   NixantPhos          & 114   & 12            &   1:2 \\
    &   BINAP               &  92   & 48            &   1:4 \\
    &   AnthPhos            & {--}  & 36            &   1:4 \\
     \bottomrule
\end{xltabular}\vspace{-\baselineskip}
    \begin{tablenotes}[para, flushleft]
    \item[a]    text;
    \item[b]    text;
    \item[c]    text.
    \end{tablenotes}
\end{threeparttable}
    \end{table}
\lipsum[13]
    \begin{figure}[ht]
      \centering
      \includegraphics[width=0.5\linewidth]{example-image-duck}
      \caption{My lovely duck}\label{fig:duck}
    \end{figure}
\lipsum[1]
    \begin{figure}[ht]
      \centering
      \includegraphics[width=\linewidth]{example-image-duck}
      \caption{My lovely big duck}\label{fig:bigduck}
    \end{figure}
\lipsum[2] \textbf{\textcolor{red}{Tab. 3 inserting point}}
    \begin{table}[ht]
\begin{threeparttable}
\begin{xltabular}{\linewidth}{%
                    >{\rownumber}r<{\qquad\qquad}
                                 X
                                 S[table-format=3]
                                 S[table-format=2,
                                   table-space-text-post={$^{m}$}]
                                 C
                                }
    \caption{My caption}
\label{my-label}                \\
    \toprule
\mcx{Entry\tnote{a}}
    &  \mcx{Ligand}
        &  \mcx{Bite angle}
            &  \mcx{Yield (\%)\tnote{b}}
                &   \mcx{E:Z}   \\
    \midrule
    & \ce{P(2-furyl)3}      & {--}  & 27    &   1:3         \\
    &   \ce{PPh3}           & {--}  & 22            &   1:4 \\
    &   \ce{P(2-Tol)3}      & {--}  & 13            &   1:2 \\
    &   \ce{PPh2Cy}         & {--}  & 3             &   1:2 \\
    &   \ce{P(4-F-Ph)}      & {--}  & 37            &   1:4 \\
    &   \ce{P(4-CF3-Ph)}    & {--}  & 35            &   1:5 \\
    &   DavePhos            & {--}  & 12            &   1:3 \\
    &   XPhos               & {--}  & 12            &   1:1 \\
    &   dppm                &  72   & 79            &   1:4 \\
    &   dppe                &  85   & 80            &   1:4 \\
    &   dppp                &  91   & 79            &   1:4 \\
    &   dppf                &  96   & 83            &   1:4 \\
    &   DPEPhos             & 102   & 86\tnote{c}   &   1:4 \\
    &   NixantPhos          & 114   & 12            &   1:2 \\
    &   BINAP               &  92   & 48            &   1:4 \\
    &   AnthPhos            & {--}  & 36            &   1:4 \\
     \bottomrule
\end{xltabular}\vspace{-\baselineskip}
    \begin{tablenotes}[para, flushleft]
    \item[a]    text;
    \item[b]    text;
    \item[c]    text.
    \end{tablenotes}
\end{threeparttable}
    \end{table}
\lipsum[3] \textbf{\textcolor{red}{Tab. 4 inserting point}}
    \begin{table}[ht]
\begin{threeparttable}
\begin{xltabular}{\linewidth}{%
                    >{\rownumber}r<{\qquad\qquad}
                                 X
                                 S[table-format=3]
                                 S[table-format=2,
                                   table-space-text-post={$^{m}$}]
                                 C
                                }
    \caption{My caption}
\label{my-label}                \\
    \toprule
\mcx{Entry\tnote{a}}
    &  \mcx{Ligand}
        &  \mcx{Bite angle}
            &  \mcx{Yield (\%)\tnote{b}}
                &   \mcx{E:Z}   \\
    \midrule
    & \ce{P(2-furyl)3}      & {--}  & 27    &   1:3         \\
    &   \ce{PPh3}           & {--}  & 22            &   1:4 \\
    &   \ce{P(2-Tol)3}      & {--}  & 13            &   1:2 \\
    &   \ce{PPh2Cy}         & {--}  & 3             &   1:2 \\
    &   \ce{P(4-F-Ph)}      & {--}  & 37            &   1:4 \\
    &   \ce{P(4-CF3-Ph)}    & {--}  & 35            &   1:5 \\
    &   DavePhos            & {--}  & 12            &   1:3 \\
    &   XPhos               & {--}  & 12            &   1:1 \\
    &   dppm                &  72   & 79            &   1:4 \\
    &   dppe                &  85   & 80            &   1:4 \\
    &   dppp                &  91   & 79            &   1:4 \\
    &   dppf                &  96   & 83            &   1:4 \\
    &   DPEPhos             & 102   & 86\tnote{c}   &   1:4 \\
    &   NixantPhos          & 114   & 12            &   1:2 \\
    &   BINAP               &  92   & 48            &   1:4 \\
    &   AnthPhos            & {--}  & 36            &   1:4 \\
     \bottomrule
\end{xltabular}\vspace{-\baselineskip}
    \begin{tablenotes}[para, flushleft]
    \item[a]    text;
    \item[b]    text;
    \item[c]    text.
    \end{tablenotes}
\end{threeparttable}
    \end{table}
\lipsum  \textbf{\textcolor{red}{Tab. 5 inserting point}}
\begin{xltabular}{\linewidth}{%
                    >{\rownumber}r<{\qquad\qquad}
                                 X
                                 S[table-format=3]
                                 S[table-format=2,
                                   table-space-text-post={$^{m}$}]
                                 C
                                }
    \caption{Long table caption}
    \label{my-label}                
    \addtocounter{table}{-1}      \\
    \toprule
\mcx{Entry}
    &  \mcx{Ligand}
        &  \mcx{Bite angle}
            &  \mcx{Yield (\%)}
                &   \mcx{E:Z}   \\
    \midrule
\endfirsthead
    \caption{Long table caption (Cont.)}  \\
    \toprule
\mcx{Entry}
    &  \mcx{Ligand}
        &  \mcx{Bite angle}
            &  \mcx{Yield (\%)}
                &   \mcx{E:Z}   \\
    \midrule
\endhead
    \midrule
\multicolumn{5}{r}{\textit{Continue on the next page}}
\endfoot
    \bottomrule
\endlastfoot
%%%% table body
\multicolumn{5}{l}{First test}                             \\
    \midrule
    & \ce{P(2-furyl)3}      & {--}  & 27    &   1:3         \\
    &   \ce{PPh3}           & {--}  & 22            &   1:4 \\
    &   \ce{P(2-Tol)3}      & {--}  & 13            &   1:2 \\
    &   \ce{PPh2Cy}         & {--}  & 3             &   1:2 \\
    &   \ce{P(4-F-Ph)}      & {--}  & 37            &   1:4 \\
    &   \ce{P(4-CF3-Ph)}    & {--}  & 35            &   1:5 \\
    &   DavePhos            & {--}  & 12            &   1:3 \\
    &   XPhos               & {--}  & 12            &   1:1 \\
    &   dppm                &  72   & 79            &   1:4 \\
    &   dppe                &  85   & 80            &   1:4 \\
    &   dppp                &  91   & 79            &   1:4 \\
    &   dppf                &  96   & 83            &   1:4 \\
    &   DPEPhos             & 102   & 86            &   1:4 \\
    &   NixantPhos          & 114   & 12            &   1:2 \\
    &   BINAP               &  92   & 48            &   1:4 \\
    &   AnthPhos            & {--}  & 36            &   1:4 \\
    \midrule
\multicolumn{5}{l}{Second test}                             \\
    \midrule
    & \ce{P(2-furyl)3}      & {--}  & 27            &   1:3 \\
    &   \ce{PPh3}           & {--}  & 22            &   1:4 \\
    &   \ce{P(2-Tol)3}      & {--}  & 13            &   1:2 \\
    &   \ce{PPh2Cy}         & {--}  & 3             &   1:2 \\
    &   \ce{P(4-F-Ph)}      & {--}  & 37            &   1:4 \\
    &   \ce{P(4-CF3-Ph)}    & {--}  & 35            &   1:5 \\
    &   DavePhos            & {--}  & 12            &   1:3 \\
    &   XPhos               & {--}  & 12            &   1:1 \\
    &   dppm                &  72   & 79            &   1:4 \\
    &   dppe                &  85   & 80            &   1:4 \\
    &   dppp                &  91   & 79            &   1:4 \\
    &   dppf                &  96   & 83            &   1:4 \\
    &   DPEPhos             & 102   & 86            &   1:4 \\
    &   NixantPhos          & 114   & 12            &   1:2 \\
    &   BINAP               &  92   & 48            &   1:4 \\
    &   AnthPhos            & {--}  & 36            &   1:4 \\
    \midrule
\multicolumn{5}{l}{Third test}                             \\
    \midrule
    & \ce{P(2-furyl)3}      & {--}  & 27            &   1:3 \\
    &   \ce{PPh3}           & {--}  & 22            &   1:4 \\
    &   \ce{P(2-Tol)3}      & {--}  & 13            &   1:2 \\
    &   \ce{PPh2Cy}         & {--}  & 3             &   1:2 \\
    &   \ce{P(4-F-Ph)}      & {--}  & 37            &   1:4 \\
    &   \ce{P(4-CF3-Ph)}    & {--}  & 35            &   1:5 \\
    &   DavePhos            & {--}  & 12            &   1:3 \\
    &   XPhos               & {--}  & 12            &   1:1 \\
    &   dppm                &  72   & 79            &   1:4 \\
    &   dppe                &  85   & 80            &   1:4 \\
    &   dppp                &  91   & 79            &   1:4 \\
    &   dppf                &  96   & 83            &   1:4 \\
    &   DPEPhos             & 102   & 86            &   1:4 \\
    &   NixantPhos          & 114   & 12            &   1:2 \\
    &   BINAP               &  92   & 48            &   1:4 \\
    &   AnthPhos            & {--}  & 36            &   1:4 \\
    \midrule
\multicolumn{5}{l}{Fourth test}                             \\
    \midrule
    & \ce{P(2-furyl)3}      & {--}  & 27            &   1:3 \\
    &   \ce{PPh3}           & {--}  & 22            &   1:4 \\
    &   \ce{P(2-Tol)3}      & {--}  & 13            &   1:2 \\
    &   \ce{PPh2Cy}         & {--}  & 3             &   1:2 \\
    &   \ce{P(4-F-Ph)}      & {--}  & 37            &   1:4 \\
    &   \ce{P(4-CF3-Ph)}    & {--}  & 35            &   1:5 \\
    &   DavePhos            & {--}  & 12            &   1:3 \\
    &   XPhos               & {--}  & 12            &   1:1 \\
    &   dppm                &  72   & 79            &   1:4 \\
    &   dppe                &  85   & 80            &   1:4 \\
    &   dppp                &  91   & 79            &   1:4 \\
    &   dppf                &  96   & 83            &   1:4 \\
    &   DPEPhos             & 102   & 86            &   1:4 \\
    &   NixantPhos          & 114   & 12            &   1:2 \\
    &   BINAP               &  92   & 48            &   1:4 \\
    &   AnthPhos            & {--}  & 36            &   1:4 \\
\end{xltabular}
\lipsum[4]
\end{document}

which gives:

enter image description here

enter image description here

enter image description here

8
  • It did not run of the page for you? I just added the demo option to graphicx and ran the MWE and at least on one page the lipsum text continued down over the page number. – daleif Oct 15 '19 at 8:06
  • @daleif, n it didn't. I extent for my text showed MWE with two images and repeat showed tables twice, add lipsum twice and result was correct. I will extend my answer with this not so short example asap. – Zarko Oct 15 '19 at 10:03
  • Interesting, though I did see some changes when I did not use the OPs fontsetup – daleif Oct 15 '19 at 10:51
  • I notice that when I turned off the ltablex package the problem seems to disappeare. Unfortunately i need several longtables in my thesis. I was using <\keepXColumns> is there any way to only have ltablex on for the long tables? – Phildgg Oct 15 '19 at 11:43
  • @Phildgg, I can confirm, that your problems have roots in ltablex. I try to test now some alternative solutions, but temporary I'm on tight with time. Hopefully at evening I will return to your problem. – Zarko Oct 15 '19 at 12:33
0

Assuming you really need that the table are as wide as the text block, you can better use tabular* instead of tabularx and ltablex (they can be confused when several floats appear in the same page).

In the code below I removed some wrong settings and reorganized the preamble.

Note that:

  1. \fontfamily{phv}\selectfont is wrong and should be omitted.
  2. \def\pdfshellescape{1} is something that should never appear. Ever.
  3. The p placement option should always be given.
  4. With heightrounded you ensure an integral number of lines.
\documentclass[a4paper,11pt, openany]{scrbook}

\usepackage[scaled]{helvet}
\usepackage[T1]{fontenc}
\usepackage{textgreek}
\usepackage[margin=2.5cm,heightrounded]{geometry}             % Easy page layout
\usepackage{indentfirst}  %indents the first line after a section or chapter
\usepackage[section]{placeins} %should keep tables and figures in their sections
\usepackage{setspace}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage[font=footnotesize,labelfont=bf,hypcap=false,singlelinecheck=false]{subcaption}

%% tables
\usepackage{array}
\usepackage{booktabs}               % Better table layouts
%\usepackage{tabularx}               %Package to set table widths
%\usepackage{ltablex}                %For Tables that overflow a row
\usepackage[svgnames,table]{xcolor} % note the table option

%\usepackage{multicol}   % i think this is for columnd articles, can probably disable

%% chemistry
\usepackage{siunitx}
\usepackage[version=3]{mhchem}      % Formula subscripts using \ce{}

%% settings
\onehalfspacing
\renewcommand{\arraystretch}{1.1} 
\renewcommand\familydefault{\sfdefault} 
\setcapindent{0pt}    %setting caption indent to 0

%\keepXColumns

\newcounter{magicrownumbers}
\newcommand\rownumber{\stepcounter{magicrownumbers}\arabic{magicrownumbers}} %\rownum is a counter for table rows

%\newcolumntype{C}[1]{>{\centering}m{#1}} %manual width column widths
%\newcolumntype{Y}{>{\centering\arraybackslash}X} %Autospaced column widths with centre alignment
\newcolumntype{F}{S[table-format=2,table-space-text-post=\footnotemark]} %column aligned in center to right digit ignoring superscript

\sisetup{detect-all}

%% personal commands

\newcommand{\SupS}[1]{\textsuperscript{#1}} %modified SuperScript command
\newcommand{\SubCap}[1]{\par\parbox[t]{\columnwidth}{\raggedright\footnotesize{#1}}}  %My own subcaption command used under tabularx within table environment  

%%%%\def\pdfshellescape{1} <----  ????????????????

\begin{document}

\lipsum

\lipsum

\begin{table}[htp]  %Table 1

    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}\hspace{\tabcolsep}}cccFc}
        \toprule
        \textbf{Entry\SupS{a}}&\textbf{Ligand}&\textbf{Bite angle}& \textbf{Yield(\%)\SupS{b}}  &   \textbf{E:Z}\\ 
        \midrule
        \rownumber  &\ce{P(2-furyl)3}&  --  &27 &   1:3\\
        \rownumber  &\ce{PPh3}          &   --  &22 &   1:4\\
        \rownumber  &\ce{P(2-Tol)3} &   --  &13 &   1:2\\
        \rownumber  &\ce{PPh2Cy}    &   --  &3  &   1:2\\   
        \rownumber  &\ce{P(4-F-Ph)} &   --  &37 &   1:4\\
        \rownumber  &\ce{P(4-CF3-Ph)}&  -- &35  &   1:5\\
        \rownumber  &DavePhos           &   --  &12 &   1:3\\
        \rownumber  &XPhos                  &   --  &12 &   1:1\\
        \rownumber  &dppm                   & 72    & 79    &   1:4\\
        \rownumber  &dppe                   &   85 & 80 &   1:4\\
        \rownumber  &dppp                   &   91  & 79    &   1:4\\
        \rownumber  &dppf                   &   96  & 83    &   1:4\\
        \rownumber  &DPEPhos            &   102 &86\SupS{c}&1:4\\
        \rownumber  &NixantPhos     &   {~}114  &12 &   1:2\\
        \rownumber  &BINAP                  &   92 &48  &   1:4\\
        \rownumber  &AnthPhos           &   --  &36 &   1:4\\
        \bottomrule
    \end{tabular*}
    \SubCap{Sub-caption text}
\end{table}
    \setcounter{magicrownumbers}{0}





\begin{table}[htbp] %Table2

    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}\hspace{\tabcolsep}}ccFc}
        \toprule
        \textbf{Entry\SupS{a}}&\textbf{Pd Source}&\textbf{Yield(\%)\SupS{b}}&\textbf{E:Z}\\ 
        \midrule
        \rownumber  &\ce{Pd2(dba)3.CHCl3} (2.5 mol{\%}) &86\SupS{c} &   1:4         \\
        \rownumber  &\ce{Pd(OAc)2} (5.0 mol\%)              &79                 &   1:4         \\  
        \rownumber  &\ce{Pd(dba)2} (5.0 mol\%)              &85\SupS{c} &   1:4         \\
        \rownumber  &\ce{Pd(Cp)Cinammyl} (5.0 mol\%)&80                 &   1:5         \\
        \rownumber  &\ce{PdCl2(PPh3)2} (5.0 mol\%)      &50                 &   1:4         \\
        \rownumber  &\ce{Pd(allyl)(COD)BF4} (5.0 mol\%)&60                  &   1:4         \\
        \rownumber  &\ce{Pd(OPiv)2} (5.0 mol\%)         &36                 &   1:5         \\
        \bottomrule
    \end{tabular*}
    \SubCap{Sub-caption text}
\end{table}
\setcounter{magicrownumbers}{0}





\begin{table}[htbp] %Table 3

    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}\hspace{\tabcolsep}}ccFc}
        \toprule
        \textbf{Entry\SupS{a}}&Acetal equiv.&\textbf{Yield(\%)\SupS{b}}&\textbf{E:Z}\\ 
        \midrule
        \rownumber  &               1.5         &86\SupS{c}                 &   1:9         \\
        \rownumber  &               1.1         &78                 &   1:7         \\
        \rownumber  &               2.0         &84                 &   1:8         \\
        \rownumber  &               3.0         &72                 &   1:7         \\
        \bottomrule
    \end{tabular*}
    \SubCap{Sub-caption text}
\end{table}
\setcounter{magicrownumbers}{0}
\lipsum[1-2]



\begin{table}[htp]  %Table 4

    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}\hspace{\tabcolsep}}ccFc}
        \toprule
        \textbf{Entry\SupS{a}}&tether premix time&\textbf{Yield(\%)\SupS{b}}&\textbf{E:Z}\\ 
        \midrule
        \rownumber  &               60 min          &80\SupS{c}                 &   1:9         \\
        \rownumber  &               10 min          &83                 &   1:9     \\
        \rownumber  &               0 min           &83\SupS{c}                 &   1:9         \\
        \rownumber  &               Direct addition         &84                 &   1:8         \\
        \bottomrule
    \end{tabular*}
    \SubCap{Sub-caption text}
\end{table}
\setcounter{magicrownumbers}{0}


\begin{table}[htbp]  %Table 5

    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}\hspace{\tabcolsep}}cccc}
        \toprule
        \textbf{Entry\SupS{a}}&Comment&\textbf{Yield(\%)\SupS{b}}&\textbf{E:Z}\\ 
        \midrule
        \rownumber  &               Ligand: XantPhos            &   trace  &    --  \\
        \rownumber  &               Base: \ce{Cs3PO4}           &   69      &   1:6 \\
        \rownumber  &               Addition of CsOTf           &   73          &   1:7         \\
        \bottomrule
    \end{tabular*}
    \SubCap{Sub-caption text}
\end{table}
\setcounter{magicrownumbers}{0}

\lipsum

\end{document}

enter image description here

2
  • \def\pdfshellescape{1} was in there because I was using chemsstyle and psfrag and it solved an issue I had a long time ago. I need longtables for other tables in my thesis that are over a page long. While I like the way the tables look with tabularx, I will have a go with out. – Phildgg Oct 15 '19 at 11:27
  • @Phildgg I think you missed egreg's point that \def\pdfshellescape{1} never does anything useful, it just breaks any code that is testing whether shell escape has been used. Whatever effect that you wanted to have on psfrag, that can not be the way to do it. For longtables the natural package to use is longtable, not ltablex – David Carlisle Oct 15 '19 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.