我需要幫助在 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}

相關內容