0

I am facing some problems with xltabular. I have used the below commands to do a table to describe the variables used in mys study. Firstly, although I am using the command \newpage some tables are included in the middle of the xltabular. Next, the name of the table is presented in the list of figure instead of tables. I tried to include the xltabular in a table but that didn't work. Can someone tell me how can I solve this problem?

This xltabular code (P.S. the variable description is far longer than that. Below I just show one variable.):

\newpage

\begin{xltabular}{\linewidth}{ l | X }
  \caption{Description of Variables used in this Study} 
 \label{table: vardescription}\\
 \hline \hline

\textbf{\normalsize Code} & \textbf{\normalsize Definition and source}  \\
 \hline 
\endfirsthead
 \hline \hline

\textbf{\normalsize Code} & \textbf{\normalsize Definition and source}  \\
 \hline 
\endhead


\textbf{var2} & {blabla} \\  \hline 

\textbf{var1} & blabla\\  \hline 

\end{xltabular}

and the main body is:

\documentclass[a4paper,12pt]{report}

\usepackage[USenglish]{babel}   % language, change USenglish to german if writing in German
\usepackage{amsmath,amsfonts,amssymb,mathrsfs} % math symbols
\usepackage{graphicx}   % package for graphics
\usepackage{tabularx}   % package for tables
\usepackage{xltabular}
\usepackage{microtype} 
%\usepackage{bookmark}  % allows you to click on bookmarks in the pdf, it is commented off because it might disturb you at the beginning. Comment on to see what it can do.
\usepackage{bm}         % for bold math
\usepackage{listings}   % for inserting code
\usepackage{verbatim}   % useful for program listings
\usepackage{pdflscape}  % turning wide pages by 90°
\usepackage{color}      % package for colors
\usepackage[utf8]{inputenc}
\usepackage{geometry}   % interface of your document dimensions
\usepackage[hang]{footmisc} % option hang produces hanging footnotes, see options of package
\usepackage[capposition=top]{floatrow}  % defines the position of a caption in a floating environment
\expandafter\def\expandafter\quote\expandafter{\quote\small}
\usepackage{longtable} % for long tables
\usepackage{subcaption}
\usepackage{booktabs}
\usepackage[dvipsnames]{xcolor}
\usepackage{fancyvrb}
\usepackage{makecell} % use for bold line \hlineB{2}
\usepackage{boldline} % use for bold line \hlineB{2}
\usepackage{amsmath} 
\usepackage{rotating} % to retrun tables vertically 
\usepackage{tablefootnote}
\usepackage{footnote} 
\usepackage[natbibapa]{apacite}
\usepackage{url} %for online cite
\usepackage{hyperref}
\usepackage{ltcaption}
%% Customized options
\newlength{\tempdima}





\usepackage[onehalfspacing]{setspace}   % Either double-spaced, onehalf-spaced, or single-spaced
\clubpenalty=1000                       % prevents single lines at the end of page 
\widowpenalty=1000                      % prevents single lines at the top of page 
\displaywidowpenalty=1000               % for math mode
\interfootnotelinepenalty=10000         % prevents footnotes from breaking across pages
\newcommand{\N}{{\mathbb N}}            % shortcut for natural numbers
\newcommand{\R}{{\mathbb R}}            % shortcut for real numbers
\usepackage{booktabs}
\usepackage{pdfpages} 

%% Other stuff
\DeclareGraphicsExtensions{.pdf,.png,.jpg} % include pictures only with these endings
\setlength{\footnotemargin}{10pt}   % defines the space of hanging footnotes

\geometry{left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm} %sets margins on paper itself, check again before submitting/writing if you got the right numbers here
\definecolor{darkblue}{RGB}{51, 51, 178}    % defines colour of written text
\allowdisplaybreaks % allows page breaks in align envirnonment



\graphicspath{{C:/Users/Arbnor/Desktop/thesisn/write/fig/}}





\begin{document}
\pagenumbering{Roman}




\begin{titlepage} 



    \newcommand{\HRule}{\rule{\linewidth}{0.5mm}} 

    \center 

    \includegraphics{logo.pdf}


    \textsc{\LARGE }\\[1.5cm] 


    \textsc{\Large Thesis}\\[0.5cm] 



    \HRule\\[0.4cm]

    {\huge\bfseries }\\[0.4cm] 

    \HRule\\[1.5cm]


    \begin{minipage}{0.4\textwidth}
        \begin{flushleft}
            \large
            \textit{Author}\\
            \textsc{} % Your name
        \end{flushleft}
    \end{minipage}
    ~
    \begin{minipage}{0.4\textwidth}
        \begin{flushright}
            \large
            \textit{Supervisor}\\
            \textsc{} % Supervisor's name
        \end{flushright}
    \end{minipage}



    \vfill\vfill\vfill 

    {\large\today} 


    \vfill 

\end{titlepage}







\newpage


\clearpage\null\newpage

\newpage

\include{chapters/abstract}
\newpage

\tableofcontents

\listoffigures

\listoftables


\newpage

\pagenumbering{arabic}
\include{chapters/introduction}



\include{chapters/Literature}

\include{chapters/data}

\include{chapters/Analysis}


\include{chapters/conclusion}


%----------------------------------------------------------------------------------------





\bibliographystyle{apacite}
\bibliography{references/references}

\newpage
\include{chapters/appendix}



\include{originality/originality}
\end{document}

And that gives me the following:

enter image description here

Furthermore, the next pages doesn't contain a caption (I want smoothing like: Table 5.2: continued from next page). And the strange thing is that although this is at the end of the appendix page that doesn't stay there and there two previous tables that goes after it. (I want this to be at very and of the appendix.)

New:

I have also tried to use longtable but I can't wrap the text there and the equation are not allowed in longtable.

\begin{longtable}{ l|l }

  \hline \hline
\textbf{\normalsize Code} & \textbf{\normalsize Definition and source}  \\
 \hline 

 \textbf{e} & {Domestic Currency per U.S. Dollar, End of Period, Rate is retrieved from IMF.} \\  \hline 

\textbf{exportsgr} & Exports of goods and services (annual \% growth) retrieved from World Bank. \\  \hline 

\textbf{gr\_tot} & Terms of trade change over previous year (in \%).  Data for terms of trade are collected from theglobaleconomy.com  and Kaminsky and Reinhart online database. Since variables have two different base years, the base year for both was changed to 2000 to have the same base year. And then the change is calculated as below.  \\


\\   \hline 

\end{longtable}


If the following command it shows en error for the equation.

\textbf{gr\_tot} & Terms of trade change over previous year (in \%).  Data for terms of trade are collected from theglobaleconomy.com  and Kaminsky and Reinhart online database. Since variables have two different base years, the base year for both was changed to 2000 to have the same base year. And then the change is calculated as below.  \\

\begin{equation}
gr$\_tot_{i,t} = (\frac{tot_{i,t}- tot_{i,t-1}}{tot_{i,t-1}})100
\end{equation}
\\   \hline 
\end{longtable}

Whereas when using long text it does not fit on the page like below.

enter image description here

Instead it should be something like in this photo:

enter image description here

17
  • Please extend your code fragment to complete small document, which reproduce your problem. In normal circumstances your problem should not happen. – Zarko Jan 16 '20 at 9:25
  • What do you mean by "extend your code fragment"? – Arbnor Jan 16 '20 at 9:36
  • 1
    @Arbnor they mean you need to edit the code in your main asked question to make a complete compilable document. – Diaa Jan 16 '20 at 10:57
  • 1
    please make a document that we can run to see the problem. You have posted a lot of code but most of it is unrelated to tables and contains \include{chapters/Literature}\include{chapters/data}\include{chapters/Analysis}\include{chapters/conclusion} and other references that we don't have. – David Carlisle Jan 16 '20 at 13:32
  • 1
    @Arbnor: Nobody wants you to include all of your thesis here. Intead, make a copy of the document and comment out everything that is unrelated to the appendix. Recompile and see if the problem persists, if so, replace \include{chapters/appendix} with the actual contents of the file appendix.tex. Now start commenting out parts of what you just included. Recompile and see if the problem persists, If so, comment out more unitl you have the smallest possible document that still reproduces the problem. Then delete all lines that you previously commented out. .... – leandriis Jan 16 '20 at 13:51
2
  • With request for providing a complete small document, which reproduces your problem is meant that we need MWE (Minimal Working Example), a document which begins with \documentclass{...} and end with \end{document}. In the preamble of this document should be loaded only packages which are relevant to your problem and similarly contain only necessary definitions of the document's elements. Example of the MWE is below.
  • Many times it happens that during preparation of an MWE the problem is resolved, so the effort of constructing it is (very) worth.
  • From your code fragments I constructed the MWE (see below), with which I didn't succeed to reproduce any of your mentioned problems (note, for final document you need to compile it at least twice).
\documentclass[a4paper,12pt]{report}
\usepackage[margin=2.5cm]{geometry} 
\usepackage[USenglish]{babel}           % change USenglish to german if writing in German
\usepackage{amsmath, amssymb, mathrsfs} % math stuff
\usepackage{graphicx}                   % package for graphics
\usepackage{array, booktabs, xltabular} % tables
\usepackage{microtype} 
\usepackage[skip=1ex,font={small,sf}, labelfont=bf]{caption}

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}

\begin{document}

\tableofcontents
\listoftables
\listoffigures

\chapter{Fitst chapter}
\section{first section}
\section{second section}
    \begin{xltabular}{\linewidth}{ >{\bfseries}l   X }
\caption{Description of Variables used in this Study}
\label{table: vardescription}                                  
\addtocounter{table}{-1}                                        \\
    \toprule
\textbf{Code} & \textbf{Definition and source}                  \\
    \midrule
\endfirsthead
\caption[]{Description of Variables used in this Study (Cont.)} \\
    \toprule
\textbf{Code} & \textbf{Definition and source}                  \\
%    \midrule
\endhead
    \multicolumn{2}{r}{\footnotesize\textit{Continue on the next page}}
\endfoot
    \bottomrule
\endlastfoot
% table body
var1        &   \lipsum[1]  \\  \midrule
var2        &   \lipsum[2]  \\  \midrule
var3        &   \lipsum[3]  \\  \midrule
var4        &   \lipsum[4]  \\  \midrule
var5        &   \lipsum[5]  \\  \midrule
var6        &   \lipsum[6]  \\  \midrule
var7        &   \lipsum[7]  \\  
\end{xltabular}
Test of referencing, see Tab.~\ref{table: vardescription} 

\section{third section}
    \begin{figure}[htb]
    \centering
\includegraphics{example-image-duck}
    \caption[Figure caption text for \texttt{listoffigures}]{Figure}
    \label{fig:figure-1}
    \end{figure}
Test of referencing, see Fig.~\ref{fig:figure-1} 
\end{document}

(result is 6 page long, so I left generating of the document to you)

Note:

  • Use of the xltabular, which is combination of longtable and tabularx make sense only if table is longer than one page, otherwise is better to use tabularx encapsulated in the float table.
  • xltabular is not intended to be enclosed into floats. It can begins anywhere on page (at point of its inserting in document).
  • Breaks of table between pages can be only between table rows, (and not in middle of them), consequently can be some empty vertical space on bottom of page.
  • in which listof... (LoF, LoT) will appear some caption is depend where caption is. Caption in float figure will appear on LoF, caption in float table in LoT. This means that caption fromxltabular` will appear in the LoT.

Suggestion:

As you can see from test of my MWE, it not reproduce your problems, so I suggest you to extend it within step by step manner with your preamble and look, if your problems will arise. Also on the same way copy to it contents of your real document.

4
  • Is there any other way to create a table with data description? – Arbnor Jan 16 '20 at 20:33
  • @Arbnor, of coure. This can be done on many different ways. Depends on what you like to have/achieve. A more specific answer requires knowledge of the document and the purpose of that description. As guessing, description list may be good solution..However, I wonder, if my answer help you find what is going wrong in your document? – Zarko Jan 16 '20 at 21:03
  • Not that much Zarko. Actually the xltabular is quite ok but because it creates this problems I can't use it. I was trying to find another way to do it and this is very time consuming. I am searching for new method and hope I can find one very soon because I don't have that much time. – Arbnor Jan 16 '20 at 21:20
  • 1
    @Arbnor, sorry, but your responses don't clarify your problems nor given any information, what is wrong with suggestion you got. On such a way is not possible to help you. – Zarko Jan 16 '20 at 21:36

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.