如何縮小表格使其適合一頁的長度?

如何縮小表格使其適合一頁的長度?

我見過一個與此類似的問題:

但是,我不想調整表格大小,使其適合頁面的寬度(我已經這樣做了,但沒有將其轉換為圖像),我想縮小表格的高度,使其不佔用兩頁(或更多) 。

我看到了一些可能的解決方案,例如longtable但他們將我的桌子分成了 2 個,我不希望這樣。

\resizebox我是否被迫使用包中的將表格轉換為圖像graphicsx,或者我還有其他選擇嗎?

答案1

\resizebox儘管該命令是由套件提供的,但您不必強制使用圖像中的長表進行轉換graphicx。桌子仍然是桌子。

您可以使用此命令定義調整大小的表格的寬度和/或高度。請注意,固定字體的兩種尺寸可能不會按比例減小,因此通常最好將一維保留為{!}

您還可以減少垂直間距\arraystretch以盡可能減少字體,並且可以使用其他字體來\tiny稍微改變字體比例。

垂直線總是邪惡的,但在這種情況下,水平線也出於同樣的原因,特別是當\arraystretch減少 時,除了標題線和底線。該軟體包booktabs很好地完成了這項任務。嘗試這個最小的工作範例:

\documentclass{article}
\usepackage{graphicx,booktabs}
\begin{document}
\centering
{\tiny\renewcommand{\arraystretch}{.8}
\resizebox{!}{.35\paperheight}{%
\begin{tabular}{ccccc}
\toprule
    11 & 12 & 13 & 14 & 15\\
\midrule
    21 & 22 & 23 & 24 & 25\\
    31 & 32 & 33 & 34 & 35\\
    41 & 42 & 43 & 44 & 45\\
    51 & 52 & 53 & 54 & 55\\
    61 & 62 & 63 & 64 & 65\\
    71 & 72 & 73 & 74 & 75\\
    81 & 82 & 83 & 84 & 85\\
    91 & 92 & 93 & 94 & 95\\
    101 & 102 & 103 & 104 & 105\\
    111 & 112 & 113 & 114 & 115\\
    121 & 122 & 123 & 124 & 125\\
    131 & 132 & 133 & 134 & 135\\
    141 & 142 & 143 & 144 & 145\\
    151 & 152 & 153 & 154 & 155\\
    161 & 162 & 163 & 164 & 165\\
    171 & 172 & 173 & 174 & 175\\
    181 & 182 & 183 & 184 & 185\\
    191 & 192 & 193 & 194 & 195\\
    201 & 202 & 203 & 204 & 205\\
    211 & 212 & 213 & 214 & 215\\
    221 & 222 & 223 & 224 & 225\\
    231 & 232 & 233 & 234 & 235\\
    241 & 242 & 243 & 244 & 245\\
    251 & 252 & 253 & 254 & 255\\
    261 & 262 & 263 & 264 & 265\\
    271 & 272 & 273 & 274 & 275\\
    281 & 282 & 283 & 284 & 285\\
    291 & 292 & 293 & 294 & 295\\
    301 & 302 & 303 & 304 & 305\\
    311 & 312 & 313 & 314 & 315\\
    321 & 322 & 323 & 324 & 325\\
    331 & 332 & 333 & 334 & 335\\
    341 & 342 & 343 & 344 & 345\\
    351 & 352 & 353 & 354 & 355\\
    361 & 362 & 363 & 364 & 365\\
    371 & 372 & 373 & 374 & 375\\
    381 & 382 & 383 & 384 & 385\\
    391 & 392 & 393 & 394 & 395\\
    401 & 402 & 403 & 404 & 405\\
    411 & 412 & 413 & 414 & 415\\
    421 & 422 & 423 & 424 & 425\\
    431 & 432 & 433 & 434 & 435\\
    441 & 442 & 443 & 444 & 445\\
    451 & 452 & 453 & 454 & 455\\
    461 & 462 & 463 & 464 & 465\\
    471 & 472 & 473 & 474 & 475\\
    481 & 482 & 483 & 484 & 485\\
    491 & 492 & 493 & 494 & 495\\
    501 & 502 & 503 & 504 & 505\\
\bottomrule
\end{tabular}}}
\end{document}

微量元素

請注意,有些人喜歡:

\resizebox{!}{\textheight}{ ...}

不會產生與文字高度一樣長的表格,因為您在這裡僅定義了框的高度,但在星號形式中,它指的是高度+深度,即:

\resizebox*{!}{\textheight}{ ...}

將使表格長度為\textheight(上述 MWE 中的 556.4pt)。

您可以使用同一包中的另一個命令graphicx\scalebox。這裡的問題是,您必須對縮放應該如何進行有一定的了解,或者嘗試縮放值,直到您獲得想要的結果。要測試它,只需將 MWE 中的\resizebox命令替換為:

\scalebox{3}[2.2]{...}

編輯:您評論中的“維度太大”錯誤是表設計的問題,而不是命令的問題\resizebox。 LaTeX 無法將文字換行到 left、right 和cEntered 欄位中。對於包含長文字的列,您必須在環境中使用p{width}或 列。另一個選項是環境的、、列或環境列。這些環境需要同名的套件和表的總寬度作為第一個參數。例如:m{width}tabularLCRtabularyXtabularx

\usepackage{tabulary}
...

\begin{tabulary}{\linewidth}{RCLL}
...
\end{tabulary}

tabularx我更改了您的程式碼以與使用不同字體、顏色和理由的自訂列一起使用。我還添加了行顏色以避免垂直和大多數水平線,其餘的使用booktabs包的顏色而不是\hline.這是結果:

微量元素

\documentclass[a4paper]{article}
\usepackage{microtype}
\usepackage[margin=2.54cm]{geometry}
\usepackage{graphicx,booktabs,tabularx}
\usepackage[table]{xcolor}

\newcolumntype{R}{>{\leavevmode\color{magenta!70!black}\ignorespaces\sffamily\bfseries}p{2.5cm}}%
\newcolumntype{H}{>{\leavevmode\color{orange!30!black}\ignorespaces\raggedright\arraybackslash\sffamily}X}%
\newcolumntype{J}{>{\leavevmode\color{green!30!black}\ignorespaces\sffamily}X}%
\newcolumntype{W}{>{\leavevmode\color{blue!30!black}\ignorespaces\raggedleft\arraybackslash\sffamily}X}%

\rowcolors{2}{purple!05}{olive!05}
\begin{document}
\centering
{\resizebox*{\textwidth}{\textheight}{%
\renewcommand{\arraystretch}{2}
\begin{tabularx}{\textwidth}{RHJW}
\toprule\rowcolor{white}
    & \textbf{Hibernate OGM} & \textbf{EclipseLink NoSQL} & \textbf{DataNucleus}\\\midrule
  Goal & Complement JPA with NoSQL, key-value stores & Integrates in the father project main goal of providing a complete persistence solution & Being a standards compliant and efficient JPA and JDO platform\\
  NoSQL and Datastores supported & Infinispan, EHCache, MongoDB & MongoDB, Oracle NoSQL, Oracle AQ, JMS, XML files & Google Big Table, MongoDB, Cassandra, Excel, OOXML, ODF, XML, HBase, AppEngine/DataStore, Neo4j, JSON, Amazon S3, GoogleStorage, LDAP, NeoDatis, db4o\\
  Operations supported & Object Oriented queries (JP-QL), CRUD of entities, Polymorphic entities, Embeddable objects, Basic types (partial), Unidirectional and Bidirectional relationships (partial), Collections, Hibernate Search queries, JPA and Hibernate ORM API & Object Oriented Queries, Polymorphic entities, Basic types, Unidirectional relationships, Collections, JPA (partial), Complex hierarchical, Indexed hierarchical data, Mapped hierarchical data, CRUD operations, Embedded objects and collections, Inheritance, Subset of JP-QL and Criteria API, Denormalization & CRUD operations, Embedded objects and collections, Inheritance, Relationships (Unidirectional and Bidirectional), Queries for JP-QL, JDOQL and SQL (partial),  Basic types, Joins.\\
  No support for & Denormalization, Complex joins and aggregations & Joins & Aggregations? (not specified in documentation)\\
  Future & High performance sequence generator, parallel key fetching, support for Map/Reduce, more NoSQL classes, better mixing of NoSQL and RDBMS & ? & JPA2.1 full feature list, Official support for Cassandra, Considering a plugin for REDIS\\
  Commercial support & Red Hat & Oracle (via TopLink) & Supported by DataNucleus team\\
  Documentation & Scattered, inactive forums, official documentation lacking & Bureaucratic forums, information is complete and gathered mainly in the official website & Active forums, acceptable official documentation, but the big advantage comes from user support in form of blogs and posts scattered around the Internet\\\bottomrule
\end{tabularx}}}
\end{document}

相關內容