我需要帮助在 Latex 中格式化长表格

我需要帮助在 Latex 中格式化长表格

我无法格式化超过两页的长表格。这是我当前的代码:

在此处输入图片描述

\begin{longtable}{p{5cm}p{9cm}}
    \caption{Descriptions of learning styles \citep{Hoerner2013}}\\
    \hline
    \multicolumn{1}{c}{\textbf{Learning Style}} & \multicolumn{1}{c}{\textbf{Description}} \\\hline
    \endhead 
    \multicolumn{1}{c}{1. Visual} & \parbox[c]{\hsize}{People who understand work better when it is in the form of a diagram. Knowledge and concept maps are good tools for such learners.} \vspace{1mm} \\\hline
    \multicolumn{1}{c}{2. Aural} &  \parbox[c]{\hsize}{\vspace{1mm} People who dislike reading, but enjoys hearing someone else say something aloud. Hearing the information is key for such students and group discussions can be of great aid.} \vspace{1mm}  \\\hline
    \multicolumn{1}{c}{3. Verbal} & \parbox[c]{\hsize}{Verbal learners are people who express themselves easier through writing and speaking. Mnemonics, scripting and role playing are some great techniques to helps those learners.} \vspace{1mm} \\\hline
    \multicolumn{1}{c}{4. Physical} &   \parbox[c]{\hsize}{Hands-on activities rather than lectures or demonstrations appeal to these learners. They are a small percentage of the population, but they learn better through practical experience.} \vspace{1mm} \\\hline
    \multicolumn{1}{c}{5. Logical} &    \parbox[c]{\hsize}{People who are good with numbers and using logic to understand. They easily recognize patterns and often tend to group information to further their understanding.}  \vspace{1mm} \\\hline
    \multicolumn{1}{c}{6. Social} & \parbox[c]{\hsize}{When communicating and socialising with others come easy, someone is a social learner. Studying in group formats and learning from others are their speciality and is how they excel.}   \vspace{1mm} \\\hline
    \multicolumn{1}{c}{7. Solitary} &   \parbox[c]{\hsize}{People who are more comfortable studying in private and introspective.  The concentration of these students are at their peak when they can focus on their own thoughts without the distractions of others around them.} \vspace{1mm} \\\hline
    \label{learningstyles}
\end{longtable}

其显示效果与附图类似。可以看出,在表格的每一行中,hline 非常接近每个段落的顶部。我在每个 \hline 后插入了 \,这样可以,但每个段落上方和下方的间距大小不一样,并且在表格第二页的 3. Verbal 上方添加了一个空行。我尝试在每个 \hline 后添加 \vspace{1mm} 而不是 \,这样间距大小就会相同,但程序会崩溃。

我还能做些什么让它看起来更好吗?

答案1

不要使用\hline\cline;而是加载包并booktabs使用其\toprule、、\midrule和画线命令。\bottomrule\addlinespaces

我还会用空格替换内部的水平线,不会将列的内容居中设置,也不会过度使用粗体。

在此处输入图片描述

\documentclass{article} % select a suitable document class
\usepackage{natbib, longtable, booktabs}

\newlength\mylen
\settowidth\mylen{Learning Style}
% Calculate maximal permissible width of second column:
\setlength\mylen{\dimexpr\textwidth-\mylen-2\tabcolsep\relax}

\begin{document}
\frenchspacing
\begin{longtable}{@{}lp{\mylen}@{}}
    \caption{Descriptions of learning styles \citep{Hoerner2013}}
    \label{learningstyles} \\
    \toprule
    Learning Style & Description \\    
    \midrule
    \endhead 
    
    \bottomrule
    \endfoot
    
    1. Visual & People who understand work better when it is in the form of a diagram. Knowledge and concept maps are good tools for such learners.  \\ 
    \addlinespace
    2. Aural &  People who dislike reading, but enjoys hearing someone else say something aloud. Hearing the information is key for such students and group discussions can be of great aid.   \\ 
    \addlinespace
    3. Verbal & Verbal learners are people who express themselves easier through writing and speaking. Mnemonics, scripting and role playing are some great techniques to helps those learners.  \\ 
    \addlinespace
    4. Physical &   Hands-on activities rather than lectures or demonstrations appeal to these learners. They are a small percentage of the population, but they learn better through practical experience.  \\ 
    \addlinespace
    5. Logical &    People who are good with numbers and using logic to understand. They easily recognize patterns and often tend to group information to further their understanding.  \\ 
    \addlinespace
    6. Social & When communicating and socialising with others come easy, someone is a social learner. Studying in group formats and learning from others are their speciality and is how they excel.    \\ 
    \addlinespace
    7. Solitary &   People who are more comfortable studying in private and introspective.  The concentration of these students are at their peak when they can focus on their own thoughts without the distractions of others around them.  \\ 
    
\end{longtable}

\end{document}

答案2

使用时xltabular可以自动确定列的宽度:

\documentclass{article}

\usepackage{booktabs, makecell, xltabular}
\renewcommand\theadfont{\normalsize\bfseries}

\usepackage{lipsum}

\begin{document}
\lipsum[1-3]

\begin{xltabular}{\linewidth}{@{} lX @{}}
    \caption{Descriptions of learning styles}
    \label{learningstyles}                              \\
    \toprule
\thead{Learning\\ Style}  & \thead{Description}         \\
    \midrule
\endfirsthead
    \caption[]{Descriptions of learning styles (cont.)} \\
    \toprule
\thead{Learning\\ Style}  & \thead{Description}         \\
    \midrule
\endhead
    \midrule
    \multicolumn{2}{r}{%
        \footnotesize\textit{Continue on the next page}}\\    
\endfoot
    \bottomrule
\endlastfoot
1. Visual
    &   People who understand work better when it is in the form of a diagram. Knowledge and concept maps are good tools for such learners.\\
    \addlinespace
2. Aural
    &   People who dislike reading, but enjoys hearing someone else say something aloud. Hearing the information is key for such students and group discussions can be of great aid.\\
    \addlinespace
3. Verbal
    &   Verbal learners are people who express themselves easier through writing and speaking. Mnemonics, scripting and role playing are some great techniques to helps those learners.\\
    \addlinespace
4. Physical
    &   Hands-on activities rather than lectures or demonstrations appeal to these learners. They are a small percentage of the population, but they learn better through practical experience.\\
    \addlinespace
5. Logical
    &   People who are good with numbers and using logic to understand. They easily recognize patterns and often tend to group information to further their understanding.\\
    \addlinespace
6. Social
    &   When communicating and socialising with others come easy, someone is a social learner. Studying in group formats and learning from others are their speciality and is how they excel.\\
    \addlinespace
7. Solitary
    &   People who are more comfortable studying in private and introspective.  The concentration of these students are at their peak when they can focus on their own thoughts without the distractions of others around them.\\
\end{xltabular}

\end{document}

在此处输入图片描述

答案3

考虑删除\parbox造成奇怪间距的罪魁祸首,并将其替换为包m的列array

我还使用该booktabs包来制作更漂亮的水平线条。

\documentclass{article}

\usepackage{longtable}
\usepackage{array}
\usepackage{booktabs}

\begin{document}

\begin{longtable}{m{5cm}m{9cm}}
    \caption{Descriptions of learning styles}\\
    \toprule
    \multicolumn{1}{c}{\textbf{Learning Style}} & \multicolumn{1}{c}{\textbf{Description}} \\
    \midrule
    \endhead 
    \multicolumn{1}{c}{1. Visual} 
        & People who understand work better when it is in the form of a diagram. Knowledge and concept maps are good tools for such learners.\\
    \midrule
    \multicolumn{1}{c}{2. Aural} 
        & People who dislike reading, but enjoys hearing someone else say something aloud. Hearing the information is key for such students and group discussions can be of great aid.\\
    \midrule
    \multicolumn{1}{c}{3. Verbal} 
        & Verbal learners are people who express themselves easier through writing and speaking. Mnemonics, scripting and role playing are some great techniques to helps those learners.\\
    \midrule
    \multicolumn{1}{c}{4. Physical} 
        & Hands-on activities rather than lectures or demonstrations appeal to these learners. They are a small percentage of the population, but they learn better through practical experience.\\
    \midrule
    \multicolumn{1}{c}{5. Logical} 
        & People who are good with numbers and using logic to understand. They easily recognize patterns and often tend to group information to further their understanding.\\
    \midrule
    \multicolumn{1}{c}{6. Social} 
        & When communicating and socialising with others come easy, someone is a social learner. Studying in group formats and learning from others are their speciality and is how they excel.\\
    \midrule
    \multicolumn{1}{c}{7. Solitary} 
        & People who are more comfortable studying in private and introspective.  The concentration of these students are at their peak when they can focus on their own thoughts without the distractions of others around them.\\
    \bottomrule
    \label{learningstyles}
\end{longtable}


\end{document}

在此处输入图片描述

编辑

总的来说,我同意 Mico 的建议,但如果您更喜欢您提供的表格样式(我复制了),我仍然建议使用最长的条目来计算 Mico 建议的列宽。

\documentclass{article}

\usepackage{longtable}
\usepackage{array}
\usepackage{booktabs}

\newlength\colOne
\newlength\colTwo
\settowidth\colOne{Learning Style}
% Calculate maximal permissible width of second column:
\setlength\colTwo{\dimexpr\textwidth-\colOne-2\tabcolsep\relax}

\begin{document}

\begin{longtable}{m{\colOne}m{\colTwo}}
    \caption{Descriptions of learning styles}\\
    \toprule
    \multicolumn{1}{c}{\textbf{Learning Style}} & \multicolumn{1}{c}{\textbf{Description}} \\
    \midrule
    \endhead 
    \multicolumn{1}{c}{1. Visual} 
        & People who understand work better when it is in the form of a diagram. Knowledge and concept maps are good tools for such learners.\\
    \midrule
    \multicolumn{1}{c}{2. Aural} 
        & People who dislike reading, but enjoys hearing someone else say something aloud. Hearing the information is key for such students and group discussions can be of great aid.\\
    \midrule
    \multicolumn{1}{c}{3. Verbal} 
        & Verbal learners are people who express themselves easier through writing and speaking. Mnemonics, scripting and role playing are some great techniques to helps those learners.\\
    \midrule
    \multicolumn{1}{c}{4. Physical} 
        & Hands-on activities rather than lectures or demonstrations appeal to these learners. They are a small percentage of the population, but they learn better through practical experience.\\
    \midrule
    \multicolumn{1}{c}{5. Logical} 
        & People who are good with numbers and using logic to understand. They easily recognize patterns and often tend to group information to further their understanding.\\
    \midrule
    \multicolumn{1}{c}{6. Social} 
        & When communicating and socialising with others come easy, someone is a social learner. Studying in group formats and learning from others are their speciality and is how they excel.\\
    \midrule
    \multicolumn{1}{c}{7. Solitary} 
        & People who are more comfortable studying in private and introspective.  The concentration of these students are at their peak when they can focus on their own thoughts without the distractions of others around them.\\
    \bottomrule
    \label{learningstyles}
\end{longtable}


\end{document}

在此处输入图片描述

编辑2

正如 Mico 在他的评论中所建议的那样,我们必须计算粗体字体版本的文本的宽度,因为它与正常字体粗细宽度不同。此外,\tabcolsep与 Mico 的例子相比,此示例中还有两个。一个在表格的最左侧,另一个在最右侧。Mico 通过编写 来抑制它们@{}lp{\mylen}@{},其中@{}用于将\tabcolsep本地重置为括号之间的任何尺寸,因此在这种情况下,什么都没有。

因此,计算列宽的代码应该被下面的代码替换:

\newlength\colOne
\newlength\colTwo
\settowidth\colOne{\textbf{Learning Style}}
% Calculate maximal permissible width of second column:
\setlength\colTwo{\dimexpr\textwidth-\colOne-4\tabcolsep\relax}

相关内容