テーブルを縮小して 1 ページの長さに収めるにはどうすればよいでしょうか?

テーブルを縮小して 1 ページの長さに収めるにはどうすればよいでしょうか?

私はこれに似た質問を見たことがあります:

ただし、テーブルのサイズをページの幅内に収まるように変更するのではなく (画像に変換せずに既に変更しています)、テーブルの高さを縮小して 2 ページ (またはそれ以上) を占有しないようにします。

いくつかの解決策を見ましたがlongtable、テーブルが 2 つに分割されており、それを望んでいません。

\resizeboxパッケージの を使用してテーブルを画像に変換する必要がありますかgraphicsx、それとも他のオプションがありますか?

答え1

\resizeboxこのコマンドはパッケージによって提供されていますが、長い表をイメージに変換する必要はありませんgraphicx。表は表のままです。

このコマンドを使用して、サイズ変更されたテーブルの幅と高さを定義できます。両方の寸法を固定すると、フォントが比例して縮小されない可能性があるため、通常は 1 つの寸法を として残す方がよいことに注意してください{!}

垂直方向の間隔を狭めて\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]{...}

編集:コメントの「寸法が大きすぎます」というエラーは、コマンドの問題ではなく、テーブル設計の問題です。LaTeX は、eft、ight、および入力された列\resizebox内のテキストを折り返すことができません 。長いテキストを含む列の場合は、環境のまたは columnsを使用する必要があります。別のオプションは、環境の、、列、または環境の列です。これらの環境では、同じ名前のパッケージと、最初の引数としてテーブルの合計幅が必要です。例:lrcp{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}

関連情報