xltabular 作为表格

xltabular 作为表格

我在使用 xltabular 时遇到了一些问题。我使用以下命令制作了一个表格来描述我的研究中使用的变量。首先,尽管我使用了命令 \newpage,但一些表格包含在 xltabular 的中间。接下来,表格的名称显示在图表列表中,而不是表格中。我尝试将 xltabular 包含在表格中,但没有成功。有人能告诉我如何解决这个问题吗?

这个 xltabular 代码(PS 变量描述远比这长。下面我只显示一个变量。):

\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}

主体内容如下:

\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}

这给了我以下信息:

在此处输入图片描述

此外,下一页不包含标题(我希望像表 5.2 那样平滑:下页继续)。奇怪的是,虽然这是在附录页的末尾,但它并没有留在那里,后面还有两个表格。(我希望它位于附录的最后面。)

新的:

我也尝试过使用 longtable,但是我无法在那里换行,并且 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}

而当使用长文本时,它并不适合下面的页面。

在此处输入图片描述

相反,它应该像照片中的那样:

在此处输入图片描述

答案1

  • 要求提供完整的小文档来重现您的问题意味着我们需要 MWE(最小工作示例),即以 开头\documentclass{...}和以 结尾的文档\end{document}。在此文档的序言中,应仅加载与您的问题相关的包,并且同样仅包含文档元素的必要定义。MWE 的示例如下。
  • 很多时候,在准备 MWE 期间问题就得到了解决,因此构建它的努力是(非常)值得的。
  • 我从您的代码片段构建了 MWE(见下文),但我没有成功重现您提到的任何问题(请注意,对于最终文档,您需要至少编译两次)。
\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}

(结果长达 6 页,因此我将文档的生成工作留给了你)

笔记:

  • 使用,它是和xltabular的组合,仅当表格长度超过一页时才有意义,否则最好使用封装在浮动 中的。longtabletabularxtabularxtable
  • xltabular不打算包含在浮动元素中。它可以从页面的任何位置开始(从其插入文档的位置开始)。
  • 页面之间的表格分隔符只能位于表格行之间(而不是行中间),因此页面底部可以有一些空白的垂直空间。
  • 其中listof...(LoF, LoT) 会出现一些标题,这取决于标题的位置。浮点型标题figure会出现在 LoF 上,浮点型table in LoT. This means that caption fromxltabular` 标题会出现在 LoT 上。

建议:

从我对 MWE 的测试中可以看出,它不会重现您的问题,因此我建议您逐步扩展它,看看是否会出现问题。同样,将您的真实文档的内容复制到其中。

相关内容