具有大列条目的多行表

具有大列条目的多行表

我制作了这个表格,但它不适合这个页面。我试过了,\adjustbox但这似乎会减小条目的文本大小。我希望文本大小保持不变。

\documentclass[12pt,notitlepage,oneside]{report}

\usepackage{makecell,multirow}
\usepackage{adjustbox}

\begin{document}

\begin{table}
\def\arraystretch{3}
\centering
\begin{tabular}{|p{3cm}|c|}
\hline
Superclass & Topic Words  \\ \hline
%0
\multirow{1}{*}{ruby} & \makecell[l]{block gems/redis lib/redis/client.rb         call gems/sidekiq lib/ruby/gems lib/redis.rb app/vendor/bundle/ruby tmp/build     c/vendor/bundle/ruby \\gems/railties vendor/bundle/ruby gems/activesupport         dda lib/ruby levels error actionpack lib/redis/connection/ruby.rb lt;top}\\
\hline

%1
\multirow{5}{*}{data-type} & \makecell[l]{key keys redis hash values set     data list store field string command hashes fields stored delete match array     pattern type}\\
\cline{2-2}
   &  \makecell[l]{list item items rpush lpush element lists default type     client lrange llen \\pop collection elements empty push true doctrine     mylist}\\
\cline{2-2}

& \makecell[l]{set sorted score sets list zadd member members elements         zset sadd element result timestamp sort scores order items time number}\\
\cline{2-2}

& \makecell[l]{string data json redis object bytes type int array length     byte strings store bit key convert size python result serialized}\\
\cline{2-2}

& \makecell[l]{val anonfun case def scala string play actor plugin future     sbt apply jar:na anon extends akka://application/user implicit\\ application-    akka.actor.default-dispatcher akka map}\\
\hline

%2
\multirow{2}{*}{commands} & \makecell[l]{info jan bytes total keys memory     time apr connected clients slaves hgets timer.caching volatile slots     usr/local/bin/php\\ usec\_per\_call usec used\_memory\_human stat}\\
\cline{2-2}
& \makecell[l]{key set keys time expire redis ttl counter exists count     command incr expiration expired expiry increment remove delete check     deleted}\\
\hline

\end{tabular}
\caption{A test caption}
\label{table2}
\end{table}

\end{document}

输出:桌子

有任何潜在的解决方案吗?提前致谢。

编辑:解决了单页表的问题。当表跨越多页时,它似乎不起作用。

答案1

像这样?

在此处输入图片描述

使用表格环境tabularx及其列类型时X,长文本单元格会自动分成多行。使用ragged2e包时,第二个表格列中的单元格中的文本会“智能”地向左对齐。

与您的表格相比,代码中的更改标记为% <---

\documentclass[12pt,notitlepage,oneside]{report}
\usepackage{ragged2e}                   % <---
\usepackage{makecell, multirow,
            tabularx}                   % <---
\newcolumntype{L}{>{\RaggedRight}X}

\begin{document}
    \begin{table}
    \setcellgapes{3pt}\makegapedcells   % <--- for more vertica space in cells
\begin{tabularx}{\linewidth}{|l|L|}     % <---
    \hline
Superclass & Topic Words  \\ \hline
%0
\multirow[t]{5}{*}{ruby}
    &   block gems/redis lib/redis/client.rb
        call gems/sidekiq lib/ruby/gems lib/redis.rb app/vendor/bundle/ruby tmp/build     c/vendor/bundle/ruby gems/railties vendor/bundle/ruby gems/activesupport dda lib/ruby levels error actionpack lib/redis/connection/ruby.rb lt;top \\   % <--- "makecell" is removed
    \hline
%1
\multirow[t]{15}{*}{data-type}
    &   key keys redis hash values set data list store field string command hashes fields stored delete match array pattern type             \\ % <--- "makecell" is removed
    \cline{2-2}
    &  list item items rpush lpush element lists default type client lrange llen pop collection elements empty push true doctrine mylist    \\ % <--- "makecell" is removed
    \cline{2-2}
    &   set sorted score sets list zadd member members elements zset sadd element result timestamp sort scores order items time number         \\ % <--- "makecell" is removed
    \cline{2-2}
    & string data json redis object bytes type int array length byte strings store bit key convert size python result serialized               \\ % <--- "makecell" is removed
    \cline{2-2}
    &   val anonfun case def scala string play actor plugin future sbt apply jar:na anon extends akka: application/user implicit application- akka.actor.default-dispatcher akka map \\ % <--- "makecell" is removed
    \hline%2
\multirow[t]{6}{*}{commands}
    &   info jan bytes total keys memory time apr connected clients slaves hgets timer.caching volatile slots usr/local/bin/php usec\_per\_call usec used\_memory\_human stat      \\ % <--- "makecell" is removed
\cline{2-2}
    &   key set keys time expire redis ttl counter exists count command incr expiration expired expiry increment remove delete check deleted    \\ % <--- "makecell" is removed
    \hline
\end{tabularx}
\caption{A test caption}
\label{table2}
    \end{table}

附录:

根据您下面的评论(上述解决方案不适用于多页表),需要考虑以下事项:

  • 多页上的表格不能位于浮动内table
  • 对于这样的表,已经开发了特殊的表包,如longtable、、ltablexxltabular(结合longtabletabularx)。
  • 单元格的使用multirow可能很脆弱,因为它可能会分解成几页,并且在开始时没有任何单元格内容的迹象。

使用多页表的示例ltablex

\documentclass[12pt,notitlepage,oneside]{report}
\usepackage{ragged2e}                   % <---
\usepackage{ltablex,
            makecell, multirow,
            tabularx}                   % <---
\keepXColumns                           % <---
\newcolumntype{L}{>{\RaggedRight}X}     % <---

\usepackage{lipsum}
\begin{document}
    \begingroup
\setcellgapes{3pt}
\makegapedcells                         % <--- 
\begin{tabularx}{\linewidth}{|l|L|}     % <--- 
\caption{A test caption} 
\label{table2}                                  \\ 
    \hline 
Superclass                      & Topic Words   \\  
    \hline
\endfirsthead
\caption[]{A test caption (cont.)}              \\
    \hline
Superclass                      & Topic Words   \\
    \hline
\endhead
    \multicolumn{2}{r}{\footnotesize\textit{Continue on the next page}}
\endfoot
\endlastfoot
% table body
\multirow[t]{5}{*}{ruby}        & \lipsum[1]    \\  \hline
    \pagebreak
\multirow[t]{5}{*}{data-type}   & \lipsum[2]    \\  \cline{2-2}                 
                                & \lipsum[3]    \\  \cline{2-2} 
                                & \lipsum[4]    \\  \hline 
\multirow[t]{6}{*}{commands}    & \lipsum[5]    \\  \cline{2-2} 
                                & last row      \\ 
    \hline 
\end{tabularx} 
    \endgroup 
\end{document}

相关内容