创建一个有 3 列的长表,文本宽度大小可以跨越 2 页,并且仍然可以阅读

创建一个有 3 列的长表,文本宽度大小可以跨越 2 页,并且仍然可以阅读

我需要创建一个有 3 列且三列中都有许多可读的单词的表格。我正在使用 tabularray 环境并为每一列添加颜色。不幸的是,由于单词的原因,我的表格超出了文本宽度限制,无法清晰显示。如果我使用 resizebox 命令,它可以工作,但表格中的字体太小,无法再阅读。主要的想法是为每段文本输入创建表格,以便它可以垂直遵循方向,例如在 Illustrator 或 Powerpoint 中。这增加了字体大小,但仍然很小。我搜索了一下,发现一种可能的方法是创建一个 longtable。不幸的是,我不知道如何正确地做到这一点。当我尝试在彩色表格中使用 longtable 时,它​​按我的意愿扩展到第二页,但无法容纳文本的尺寸(因此文本宽度超过了它应该的大小)。

我编写的、现在可以运行的代码如下所示

\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{mathpazo} % Use the Palatino font by default
\usepackage[english]{babel}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{chemformula}
\usepackage{siunitx}
\graphicspath{{Images/}}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
%margins remove huge, outdated printing margins
\setlength{\voffset}{-1in}
\setlength{\hoffset}{-1in}
%set vertical margins
\setlength{\topmargin}{2cm}
\setlength{\textheight}{24cm}
\setlength{\headheight}{0cm}
\setlength{\textwidth}{16,5cm}
\usepackage{cite}%Βιβλιογραφία
\usepackage{tabularray} %pinakes
\UseTblrLibrary{booktabs}%pinakes

\begin{document}
    \listoftables
    \centering
    \begin{table}[h!]
        \centering
        \resizebox{\textwidth}{!}{\begin{tblr}{
                    colspec={|l|c|c|}, hlines={1pt, black}, vlines={1pt, black}, column{1} = {yellow!50}, column{2} = {blue!40},
                    column{3} = {magenta!20}
                }   
                \toprule
                \textbf{XXXX} & \SetCell[c=1]{c} \textbf{XXXX} & \SetCell[c=1]{c} \textbf{XXXX} \\ 
                \midrule
                \begin{tabular}{l} XXXX\\ XXXX \\ \end{tabular} & \begin{tabular}{l} XXXX \\ \end{tabular} & \begin{tabular}{l} XXXX \\ XXXX\\ \end{tabular} \\
                \hline  
                \begin{tabular}{l}XXXX\textsuperscript{\textregistered} XXXX\\ \end{tabular} & \begin{tabular}{l} XXXX\\ \end{tabular} & \begin{tabular}{l}XXXX \\ XXXX\\ \end{tabular} \\ 
                \hline
                \begin{tabular}{l}XXXX, XXXX \end{tabular} \\  & \begin{tabular}{l} XXXX\\ \end{tabular}  & \begin{tabular}{l}XXXX \\ \end{tabular} \\
                \hline
                \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} & \begin{tabular}{l} XXXX \\ \end{tabular} \\ \hline
                \begin{tabular}{l}XXXX, 99\% \\ \end{tabular} & \begin{tabular}{l} XXXX \\ \end{tabular} & \begin{tabular}{l} XXXX \\ \end{tabular} \\ 
                \hline 
                \begin{tabular}{l}\texttrademark{XXXX} XXXX \\ \end{tabular} & \begin{tabular}{l} XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ XXXX \\ \end{tabular} \\ 
                \hline
                \begin{tabular}{l}\texttrademark{XXXX} XXXX \\ \end{tabular} & \begin{tabular}{l} XXXX \\ \end{tabular} & \begin{tabular}{l} XXXX\\ XXXX \\ \end{tabular} \\
                \hline
                \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} \\ 
                \hline
                \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l} XXXX\\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} \\ 
                \hline 
                \begin{tabular}{l}XXXX\textsuperscript{\textregistered} Pro \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} &\begin{tabular}{l}XXXX\\ XXXX\\ \end{tabular} \\
                \hline
                \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} \\ 
                \hline
                \begin{tabular}{l}XXXX,\\XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} \\
                \hline
                \begin{tabular}{l}XXXX,\\ XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} \\
                \hline
                \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} \\ 
                \hline
                \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ XXXX\\ \end{tabular} \\
                \hline
                \begin{tabular}{l}\texttrademark{XXXX} XXXX, XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} \\ 
                \hline
                \begin{tabular}{l}XXXX\textsuperscript{\textregistered}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX \\ \end{tabular} & \begin{tabular}{l}XXXX\\ \end{tabular} \\ 
                \hline         
                \bottomrule
            \end{tblr}
        }
        \caption{Guybrush Threepwood is a mighty pirate}
        \label{Table C}
\end{table}

这或多或少就是我想要实现的 在此处输入图片描述

答案1

您的问题不完全清楚,因此我(仅)猜测,您想获得类似于下表示例的内容(其中单元格的文本使用包生成的虚拟文本lipsum):

在此处输入图片描述

\documentclass{article}
\usepackage[margin=25mm]{geometry}
\usepackage{lipsum}

\usepackage{xcolor}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{table}[h!]
\begin{tblr}{hlines={1pt, fg=white}, vlines={1pt, fg=white}, 
            colspec={X[l,bg=yellow!80] 
                     X[c,bg=blue!40] 
                     X[c,bg=magenta!20]},
             row{1}={font=\bfseries, c, fg=white}
             }
column 1        &  columm 2         & column 3          \\
%
\lipsum[1][1-1] &\lipsum[1][1-1]    &\lipsum[1][1-1]    \\
\lipsum[1][1-1] &\lipsum[1][1-1]    &\lipsum[1][1-1]    \\
\lipsum[1][1-1] &\lipsum[1][1-1]    &\lipsum[1][1-1]    \\
\lipsum[1][1-1] &\lipsum[1][1-1]    &\lipsum[1][1-1]    \\
\lipsum[1][1-1] &\lipsum[1][1-1]    &\lipsum[1][1-1]    \\
\end{tblr}
\caption{
 GUYBRUSH THREEPWOOD IS A MIGHTY PIRATE or THE PIRATE i WAS MEANT TO BE}
    \end{table}
\end{document}

如果你的表格真的很长,需要跨越几页,那么你需要使用longtblr。例如使用以下序言:

\begin{document}
\noindent
\begin{longtblr}[
caption = {A caption at long table is usual on the top of table},
  label ={tab:long?}
                ]{
        hlines={1pt, fg=white}, vlines={1pt, fg=white}, 
        colspec={X[l,bg=yellow!80] 
                 X[c,bg=blue!40] 
                 X[c,bg=magenta!20]},
        row{1}={font=\bfseries, c, fg=white},
        rowhead=1
                }
column 1        &  column 2         & column 3          \\
%
% table body
%
\end{longtblr}
\end{document}

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

笔记:

  • 如您所见,示例中未使用构造,\begin{table}{l} ... \end{table}它仅覆盖列的设置。如果您喜欢手动拆分单元格中的文本,则使用tabularray此语法{text in the first line\\ text in the second line}

  • 请考虑您问题下方的评论。表格书写的基本知识,例如维基百科:表格,软件包tabularray有很好的简短文档。值得一读。

编辑:
提供的解决方案使用tabularray@cabohah 在其回答中使用的包,该回答比我的早 28 分钟发布。他的回答很有趣,但两个答案的共同点在于都使用同一个包来编写表格。

这两个建议之间的主要区别在于表格前言中的样式定义,而不是\midrule表格主体中的行之间使用,因此获得的表格样式(到目前为止)非常不同(在我看来更接近 OP 喜欢得到的)。

答案2

您可以使用longtblr带分页符的表格。但您不能将这样的表格放在浮动元素内,如table

tabularray为带换行符的列提供列类型X。但为了能够分列,文本应该允许连字符。由于您的文本通常不允许,因此我添加了几个连字符标记\-

\documentclass{article}
\usepackage{xcolor}
\usepackage{subcaption}% Loads caption
\usepackage{tabularray} 
\UseTblrLibrary{booktabs}

\begin{document}
\centering
\begin{longtblr}{
    colspec={|X|X|X|},
    hlines={1pt, black},
    vlines={1pt, black},
    column{1} = {yellow!50},
    column{2} = {blue!40},
    column{3} = {magenta!20},
    caption = {GUYBRUSH THREEPWOOD IS A MIGHTY PIRATE or THE PIRATE i WAS
      MEANT TO BE},
    label = {tab:first}
}   
\toprule
\textbf{xixiixxi} & \SetCell[c=1]{c} \textbf{xa\-xa\-xa\-xa\-xa\-} & \SetCell[c=1]{c} \textbf{solsolsolsolsol} \\ 
\midrule
blahhahhhhhhhhhhhhh & blAHHHHHHHHHHHH & BLA\-HHHHHHHHH \\
\midrule
blahhh\textsuperscript{\textregistered} BLA\-HHHHHHHHH & blahhhhhhh & blahhhhhhhhhhhhhhhh \\ 
\midrule
blahhhhhhhhhhhhhhhhhhhhhhhhhhhhhh  \\  & Iblahhhhhhhh  & blahhhhhhhhhhh  \\
\midrule
blajjjjjjjjjjjjjjjjjjjjjjj & blahhhhhhhhhhhhhhhhhhhhhh  & BLA\-HHHHHHHHHH  \\ \midrule
blahhhhhhhhhh  & BLA\-HHHHHHHHHHHHHHHHHH  & BLA\-HHHHHHHHHH  \\ 
\midrule 
\texttrademark{blahhhhhh} xa\-xa\-xa\-xa\-xa\-xa\-xa\-xa\-xa\-xa\-xa\-  & xa\-xa\-xa\-xa\-xa\-xa\-xa\-xa\- & xo\-xo\-xo\-xo\-xo\-oxo\-xo\-xo\-xxo\- HIHIHIHIHIHIHHII  \\ 
\midrule
\texttrademark{solalalalal} ka\-ka\-ka\-ka\-ka\-ka\-ka\-ka\-  & kokokokokokookokok & KI\-KI\-KI\-KI\-KI\-KKI\-KI\-KI\-KI\-RIRIRIRRIRIRIKOU  \\
\midrule
LA\-LA\-LA\-LA\-LA\-LA\-ALA\-LA\-LA\-L  & LA\-LA\-LA\-LA\-ALA\-LA\-LA\-LA\-LA\-ALA\-L  & FFA\-FA\-FA\-FA\-FA\-FA\-FA\-FA\-FA\-FA\-A \\ 
\midrule
ISSSSSS\-SSSSSS\-SSSSS  & SSSSSS\-SSSSSS\-SSSSSS\-SSSSSS\-SS & SSSSSS\-SSSSSS\-SSSSSS\-SSSSSS\-SSSSSS\-SSS \\ 
\midrule 
AAAA\-AAAA\-AAAA\-AAAA\-AA\textsuperscript{\textregistered} AAA  & AAAA\-AAAA\-AAAA\-AA
&AAAA\-AAAA\-AAAA\-AAAA\-AA \\
SSSSSS\-SSSSSS\-SSSSSS\- & & \\
\midrule
oooooooooooooooo  & bambamabmabamabam & OLA\-LA\-LA\-LA\-ALA\-LA\-LA\-LA\-LA\-LA\-ALA\-LA\-LA\-LA\-LA\-LA\-LA\-LA\-LA\-LA\-ALA\-LA\-LA\-L \\ 
\midrule
SADASDSADSADSADSADASDSA & & \\
DADADADADADADADADADA  & DADADADADADADADADA & XXXX\-XXXX\-XXXX\-XXXX\-XXXX\-XXXX\-XXXX\-XXXX\-XX \\
\midrule
kkkk\-kkkk\-kkkk\-kkkk\-kkkk\-kkkk\-kkkk\-kkkk\-  & llllllllllllllll & yyyy\-yyyy\-yyyy\-yyyy\-yyyy\-yyyy\-yyyy\-y \\
\midrule
SSSSSS\-SSSSSS\-SSSSSS\-  & gaga\-gaga\-gaga\-gaga\-gaga\-ga & TIROUR\-IROIRORU\-TORU\-TORUT \\ 
\midrule
LA\-LA\-LA\-LA\-LA\-LA\-ALA\-LA\-LA\-  & LA\-LA\-LA\-LA\-LA\-LA\-LA\-LA\-ALA\-LA\-LA\- & keke\-keke\-keke\-keke\-keke\-keke\-k \\
\midrule
\texttrademark{sssssssn}poppopppppppppppppp  & aaaaaa\-aaaaaa\-aaaaaaa & xxxxx\-xxxx\-xxxxx \\ 
\midrule
SADASDASDASDASD\textsuperscript{\textregistered}20 SSSSSS\-SSD.  & AAAA\-\-AAAA\-AAAA\- & dSSSSSS\-SSSSSS\-SSSSSS\-SS \\ 
\bottomrule
\end{longtblr}

\end{document}

tabularray有关列类型X、标题、带分页符的重复标题等的更多信息,请参阅手册。

相关内容