如何制作包含很长文本的长表?

如何制作包含很长文本的长表?

我想longtable从中得到一些启发文件

首先,我尝试这样做:

\documentclass[12pt, a4paper, onecolumn, oneside, final]{report}
\makeatother

\usepackage{array}
\setlength\extrarowheight{4pt}

\usepackage{tabto}
\newenvironment{tabs}[1]
{\TabPositions{#1}}

\usepackage{longtable}  
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\usepackage{multicol}
\usepackage{multirow}
\usepackage{musicography}

\begin{document}
\begin{small}
    \begin{longtable}{|c|l|l|r|}
        \caption{Hasil pengujian \textit{threshold} pada lagu Twinkle-Twinkle Little Star di model pertama}
        \label{tab:dtw-thres-twinkle}\\     
        \hline
        \multicolumn{1}{|r|}{\textbf{No}} & 
        \multicolumn{1}{c|}{\textbf{\textit{Unique pitch}}} &
        \multicolumn{1}{c|}{\textbf{\textit{Pitch class}}} &
        \multicolumn{1}{c|}{\textbf{\textit{Distance}}} \bigstrut\\
        \hline
        \endhead
        
        \textbf{1} & [0, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58] & [A$\sharp$2 / B$\flat$2, B2, C3, C$\sharp$3 / D$\flat$3, D3, D$\sharp$3 / E$\flat$3, E3, F3, F$\sharp$3 / G$\flat$3, G3, G$\sharp$3 / A$\flat$3, A3, A$\sharp$3 / B$\flat$3] & 2 \bigstrut\\
        
        \hline
    \end{longtable}
\end{small}
\begin{document}

输出结果不太令人满意,因为它超出了边距(您可以忽略表格上方的文本)。这是从 Adob​​e Reader 打开的示例输出。 示例输出

我该怎么做才能修改我的表格,让其更好地适合我的页面?

答案1

我建议您加载该包,因为它可以让您结合(可以跨越多页的表格)和(允许自动换行,自动计算列宽)环境xltabular的功能。longtabletabularx

我还会放弃在数学模式中放置\flat\sharp。接下来,我会通过 (a) 删除所有垂直规则和 (b) 省略大多数水平规则,让表格看起来更加开放。对于剩下的几个水平规则,我会使用booktabs-- \toprule\midrule\addlinespace\bottomrule-- 包的宏来代替\hline。最后,我会取消不必要的\makeatother指令。

在此处输入图片描述

\documentclass[12pt, a4paper, oneside]{report}
\usepackage[bahasa]{babel}
\usepackage{musicography}

\usepackage{xltabular,ragged2e,booktabs}
\newcolumntype{L}{>{\RaggedRight}X}
\setlength\LTcapwidth{\textwidth}

\begin{document}

\begin{xltabular}{\textwidth}{@{} >{\bfseries}l L L r @{}}

\caption{Hasil pengujian \textit{threshold} pada lagu 
         Twinkle-Twinkle Little Star di model pertama}
\label{tab:dtw-thres-twinkle} \\
\toprule
No & \textbf{Unique pitch} & \textbf{Pitch class} & \textbf{Distance} \\
\midrule    
\endhead

\midrule
\endfoot

\bottomrule
\endlastfoot


1 & 0, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58   
& A\sharp2 / B\flat2, B2, C3, C\sharp3 / D\flat3, D3, D\sharp3 / E\flat3, E3, F3, F\sharp3 / G\flat3, G3, G\sharp3 / A\flat3, A3, A\sharp3 / B\flat3    
& 2 \\ \addlinespace
2 & 0, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57   
& G\sharp2 / A\flat2, A2, A\sharp2 / B\flat2, B2, C3, C\sharp3 / D\flat3, D3, D\sharp3 / E\flat3, E3, F3, F\sharp3 / G\flat3, G3, G\sharp3 / A\flat3, A3    
& 521 \\ \addlinespace
3 & 0, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59   
& C3, C\sharp3 / D\flat3, D3, D\sharp3 / E\flat3, E3, F3, F\sharp3 / G\flat3, G3, G\sharp3 / A\flat3, A3, A\sharp3 / B\flat3, B3    
& 550 \\ \addlinespace
4 & 0, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55   
& A\sharp2 / B\flat2, B2, C3, C\sharp3 / D\flat3, D3, D\sharp3 / E\flat3, E3, F3, F\sharp3 / G\flat3, G3    
& 637 \\ 

\end{xltabular}
\end{document}

答案2

您可以设置表格列的宽度。为此,您需要使用包array。请看这里:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{array}

\begin{document}

\begin{table}[htbp]
    \centering
    \caption{Table caption}
    \begin{tabular}{|c|m{0.4\textwidth}|m{0.4\textwidth}|c|}
        \hline
        \textbf{No} & \textbf{\textit{Unique pitch}} & \textit{\textbf{Pitch Class}} & \textbf{\textit{Distance}} \\ \hline
        \textbf{1} & [0, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58] & [A$\sharp$2 / B$\flat$2, B2, C3, C$\sharp$3 / D$\flat$3, D3, D$\sharp$3 / E$\flat$3, E3, F3, F$\sharp$3 / G$\flat$3, G3, G$\sharp$3 / A$\flat$3, A3, A$\sharp$3 / B$\flat$3] & 2 \\ \hline
    \end{tabular}
    \label{tab:lab}
\end{table}

\end{document}

这将给出以下输出: 在此处输入图片描述

相关内容