关于表格格式的多个问题

关于表格格式的多个问题

问题 1

不久前,我使用了一些来自这里的代码,这些代码完全符合我的要求。但是,我想要一个不同的表格,并且尝试了代码(我对 Latex 还很陌生)并没有产生任何令人鼓舞的结果。基本上,我想要一个像下面这样的表格(在 Excel 中生成,因为我目前无法在 Latex 中生成它):

在此处输入图片描述

目前我得到以下信息 - 注意注释中的数字来自旧表

在此处输入图片描述

我的 MWE(当它出现在文章类中时,不必担心对齐问题 - 我使用的是自定义模板,其中已经设置了所有边距等)。我还希望 Notes 列的宽度比其他列稍大一些,因为我将在其中放入更多文本。此外,您可能注意到(参见附录 ??) - 这是我第二个问题。

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\renewcommand\arraystretch{1.2}
\usepackage{threeparttable}
\begin{document}
\begin{table}[H]
\centering
\renewcommand\arraystretch{1.2}
\begin{threeparttable}
\caption{Description of Independent Variables}
\begin{tabular}{@{}p{0.20\textwidth}*{4}{L{\dimexpr0.20\textwidth-2\tabcolsep\relax}}@{}}
\toprule
& {\bfseries Independent Variable} & {\bfseries Code} & {\bfseries Units} &    \bfseries{Notes} \\
\midrule
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
Adjusted Matric GPA & AMGPA & Continuous & The average includes the top four subjects,  excluding Mathematics, Additional Mathematics, Mathematics Paper 3 and English (First or Second Language. See Appendix~\ref{chapter:AppendixB}). & 11 -- 14 \\
\bottomrule
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

问题2

我有一个“章节”,实际上是附录。我按以下方式标记了附录:

\chapter{Appendix B}
\label{AppendixB}
\lhead{Appendix B \emph{Adjusted Matric GPA }}

现在,当我想在文本中交叉引用此附录时,我得到了一个??。我的交叉引用如下:

See Appendix~\ref{chapter:AppendixB})

为什么 Latex 没有拿起标签?

问题 3

一旦我把所有变量都放进去,我的表格就会扩展到一页以上。我发现 longtable 包是推荐的。但是,简单地将 MWE 中的 \begin{table}...\end{table} 替换为 \begin{longtable}...\end{longtable} 会导致一大堆其他错误(例如,它不喜欢 \centering 命令,并显示 \caption -> \noalign)。在使用 longtable 包而不是 table 包时,我应该注意什么?

答案1

使用该包的解决方案ltablex,扩展longtabletabularx environment. I don't know what you want to do with athreeparttable environment (you don't really use it here), but anyway, it doesn't work with longtables. For long tables, you have to load thethreeparttablex package, and the environment isThreePartTable`。

要进行交叉引用,您必须在标题后放置一个标签。我认为此代码满足您的所有要求:

\documentclass[11pt, a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}

\usepackage[showframe, nomarginpar]{geometry} %
\usepackage{ragged2e}
\usepackage{booktabs}
\usepackage{array}
\usepackage{ltablex}%
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hsize=1.25\hsize}X}
\newcolumntype{C}{>{\centering\arraybackslash\hsize=0.75\hsize}X}
\usepackage{threeparttablex}
\usepackage{makecell}
\renewcommand*{\theadfont}{\bfseries}
\renewcommand*{\theadalign}{{C}c}

\begin{document}

\begin{ThreePartTable}
\centering
\renewcommand\arraystretch{1.25}
\begin{tabularx}{\linewidth}{@{}X*{2}{C}*{2}{L}@{}}
\caption{Description of Independent Variables}\\
\toprule
& \thead{Independent \\ Variable} & \thead{Code} & \thead{Units} &    \thead{Notes} \\
\midrule
\endhead
\midrule
\multicolumn{5}{r}{\itshape continued}
\endfoot
\bottomrule
\endlastfoot
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
Adjusted Matric GPA & AMGPA & Continuous & The average includes the top four subjects,  excluding Mathematics, Additional Mathematics, Mathematics Paper 3 and English (First or Second Language. See Appendix~\ref{chapter:AppendixB}). & 11 -- 14 \\
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
Adjusted Matric GPA & AMGPA & Continuous & The average includes the top four subjects,  excluding Mathematics, Additional Mathematics, Mathematics Paper 3 and English (First or Second Language. See Appendix~\ref{chapter:AppendixB}). & 11 -- 14 \\
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
First-year GPA & FYGPA & Continuous & Overall first-year Grade Point Average & 5 -- 6  \\
Adjusted Matric GPA & AMGPA & Continuous & The average includes the top four subjects, excluding Mathematics, Additional Mathematics, Mathematics & 11 -- 14 \\
 &  & & Paper 3 and English (First or Second Language. See Appendix~\ref{chapter:AppendixB}). & %\\
\end{tabularx}
\end{ThreePartTable}

\appendix
\section{First Appendix}
\section{Second Appendix} \label{chapter:AppendixB}
\end{document} 

在此处输入图片描述

相关内容