Der Code

Der Code

Ich verwende Kile und versuche zu lernen, wie ich tabularxTabellen erstellen kann, die in die Breite meiner Seiten passen.

Ich habe jedoch zwei große Probleme:

  • Ich muss X für die Spaltengröße verwenden und kann daher die Größe meiner Spalten nicht festlegen (wenn ich beispielsweise 4 Spalten habe, möchte ich, dass Spalte A 10 % der Größe hat und die Spalten B, C und D den Rest gleichmäßig verteilen).
  • Jetzt, wo meine Tabelle endlich in die Breite der Seite passt, wird die Seitenhöhe nicht beachtet ...

Um dies zu beheben, habe ich die Dokumentation gelesen und das folgende MWE verwendet:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}

\begin{document}
\begin{table}
{%
\newcommand{\mc}[3]{\multicolumn{#1}{#2}{#3}}
\begin{center}
\begin{tabularx}{\textwidth}{>{\hsize=.25\hsize}X>{\hsize=1.25\hsize}X>{\hsize=1.25\hsize}X>{\hsize=1.25\hsize}X}\cline{2-4}
\textbf{} & \textbf{Hibernate OGM} & \textbf{EclipseLink NoSQL} & \textbf{DataNucleus}\\\hline
\mc{1}{|l|}{\textbf{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\\\hline
\mc{1}{|l|}{\textbf{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\\\hline
\mc{1}{|l|}{\textbf{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.\\\hline
\mc{1}{|l|}{\textbf{No support for}} & Denormalization, Complex joins and aggregations & Joins & Aggregations? (not specified in documentation)\\\hline
\mc{1}{|l|}{\textbf{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\\\hline
\mc{1}{|l|}{\textbf{Commercial support}} & Red Hat & Oracle (via TopLink) & Supported by DataNucleus team\\\hline
\mc{1}{|l|}{\textbf{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\\\hline
\end{tabularx}
\end{center}
}%
\end{table}


\end{document}

Obwohl die Präambel korrekt zu sein scheint (für einen Fall mit 4 Spalten, in dem die Spalten B, C und D 6x größer als A sein sollten), passiert jedoch nichts.

Was will ich genau? Nehmen wir an, die Gesamtbreite der Tabelle beträgt 100 %. Ich möchte, dass Spalte A 10 % dieser Breite hat und die Spalten B, C und D jeweils 30 %.

Ich möchte diese Tabelle auch auf eine Seite bringen, ohne sie auf zusätzliche Seiten auszudehnen. Also nein, ich kann longtable nicht verwenden ...

Das MWE generiert derzeit etwa Folgendes:

Bildbeschreibung hier eingeben

Die Dokumentation, die ich gelesen habe, finden Sie hier:

Wie kann ich meine Probleme beheben?

Antwort1

So kann man das tun:

  • p{<width>}Für alle Spalten in einer regulären verwenden tabular.
  • Erstellen Sie dazu eine neue Länge \tabularlengthund stellen Sie diese auf die Gesamtbreite der Tabelle ein. Ich habe sie .975\linewidthhier verwendet.
  • Definieren Sie dann jede der Spalten beispielsweise anhand \tabularlengthvon p{.1\tabularlength}.
  • Um die erste Spalte zum Funktionieren zu bringen, verzichten Sie auf, multicolumndamit die Zeilen unterbrochen werden können.
  • Dies bedeutet, dass wir eine Silbentrennung wünschen, also laden wir babel.
  • Dies reicht nicht ganz aus, da hierdurch die Silbentrennung des ersten Wortes in der Spalte nicht möglich ist. Trennen Sie diese Wörter daher manuell mit \-.
  • Verwenden Sie es geometry, um das richtige Seitenlayout zu erhalten.
  • Verwenden Sie es >{\bfseries}für die erste Spalte, um zu vermeiden, dass jede Zeile fett gedruckt werden muss.
  • Wir brauchen dennoch eine \multicolumnfür die allererste Zeile, damit wir keine unechten vertikalen Regeln erhalten.
  • Verwenden Sie \centeringanstelle der Umgebung, centerda letztere zusätzlichen Abstand hinzufügt, den wir hier nicht möchten.

Das passt tatsächlich mit (etwas) Spielraum. Wäre die Tabelle größer, könnte man \smallinnerhalb der tableUmgebung mit die Schriftgröße etwas kleiner einstellen. Oder man passt die Ränder etc. mit an geometry. Das ist für das ganze Dokument oder, falls nötig, für eine einzelne Seite möglich.

Der Code

\documentclass[a4paper,10pt,british]{article}
\usepackage{babel,geometry}
\usepackage[utf8]{inputenc}
\usepackage{tabularx}

\begin{document}

\begin{table}
  \newlength{\tabularlength}
  \setlength{\tabularlength}{.975\linewidth}
  \centering
  \begin{tabular}{|>{\bfseries}p{.1\tabularlength}|*{3}{p{.3\tabularlength}}}
  \cline{2-4}
  \multicolumn{1}{l}{} & \textbf{Hibernate OGM} & \textbf{EclipseLink NoSQL} & \textbf{DataNucleus}\\\hline
  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\\\hline
  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\\\hline
  Oper\-ations 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.\\\hline
  No support for & Denormalization, Complex joins and aggregations & Joins & Aggregations? (not specified in documentation)\\\hline
  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\\\hline
  Com\-mer\-cial support & Red Hat & Oracle (via TopLink) & Supported by DataNucleus team\\\hline
  Docu\-ment\-ation & 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\\\hline
  \end{tabular}
\end{table}

\end{document}

Die Ausgabe

Tabellarisch an Seite angepasst

Ein alternatives Layout

Ich denke, Sie sollten auch erwägen, die Tabellen im Querformat bereitzustellen, da dies für die Benutzer leichter verständlich sein könnte. Beispiel:

Tabellarisch im Querformat

Ich habe in diesem Fall eine zusätzliche Formatierungsanweisung für die erste Spalte verwendet, \raggedrightdamit es vernünftig aussieht.

Code für tabellarisches Querformat

\documentclass[a4paper,10pt,british]{article}
\usepackage{babel,geometry}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{pdflscape}

\begin{document}

\begin{landscape}

\begin{table}
  \newlength{\tabularlength}
  \setlength{\tabularlength}{.975\linewidth}
  \centering
  \begin{tabular}{|>{\bfseries\raggedright}p{.1\tabularlength}|*{3}{p{.3\tabularlength}}}
    \cline{2-4}
    \multicolumn{1}{l}{} & \textbf{Hibernate OGM} & \textbf{EclipseLink NoSQL} & \textbf{DataNucleus}\\\hline
    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\\\hline
    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\\\hline
    Oper\-ations 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.\\\hline
    No support for & Denormalization, Complex joins and aggregations & Joins & Aggregations? (not specified in documentation)\\\hline
    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\\\hline
    Com\-mer\-cial support & Red Hat & Oracle (via TopLink) & Supported by DataNucleus team\\\hline
    Docu\-ment\-ation & 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\\\hline
  \end{tabular}
\end{table}

\end{landscape}

\end{document}

Zentrierte Spalten und vertikale Linien

Wie von Flame_Phoenix in den Kommentaren angemerkt, m{<width>}ergibt dies eine vertikal zentrierte Spalte mit angegebener Breite. Dieser Spezifizierer erfordert das arrayPaket.

Das Hinzufügen einer vertikalen Linie vor „Hibernate OGM“ ist lediglich eine Frage der Anpassung \multicolumnfür den ersten Eintrag der Tabelle. Das horizontale und vertikale Zentrieren aller Zellen kann durch Hinzufügen >{\centering}in der Tabellenkonfiguration erfolgen. Dies ist jedoch etwas mühsam und schwieriger konsistent anzupassen. Eine bessere Lösung nutzt die Möglichkeit, arrayeinen neuen Spaltentyp zu definieren.

\newcolumntype{M}{>{\centering}m{.3\tabularlength}}

Da mein Beispiel das Layout sowohl für Hoch- als auch für Querformat zeigt, muss ich die Addition auch \tabularlengthaus den tabularUmgebungen herausziehen, sodass ich nicht versuche, eine bereits definierte Länge zu definieren.

\newlength{\tabularlength}

Der mSpaltentyp behandelt es \\als neue Zeile innerhalb der Spalte und nicht als Zeilenende. Ich muss es daher \\\hlinedurch ersetzen \tabularnewline\hline.

Zum Schluss habe ich der Übersichtlichkeit halber ganz rechts eine vertikale Linie hinzugefügt.

Der Code

\documentclass[a4paper,10pt,british]{article}
\usepackage{babel,geometry}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{pdflscape}
\newlength{\tabularlength}
\newcolumntype{M}{>{\centering}m{.3\tabularlength}}

\begin{document}

\begin{table}
  \setlength{\tabularlength}{.975\linewidth}
  \centering
  \begin{tabular}{|>{\centering\bfseries}m{.1\tabularlength}|*{3}{M}|}
  \cline{2-4}
  \multicolumn{1}{l|}{} & \textbf{Hibernate OGM} & \textbf{EclipseLink NoSQL} & \textbf{DataNucleus}\tabularnewline\hline
  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\tabularnewline\hline
  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\tabularnewline\hline
  Oper\-ations 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.\tabularnewline\hline
  No support for & Denormalization, Complex joins and aggregations & Joins & Aggregations? (not specified in documentation)\tabularnewline\hline
  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\tabularnewline\hline
  Com\-mer\-cial support & Red Hat & Oracle (via TopLink) & Supported by DataNucleus team\tabularnewline\hline
  Docu\-ment\-ation & 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\tabularnewline\hline
  \end{tabular}
\end{table}

\begin{landscape}

\begin{table}
  \setlength{\tabularlength}{.975\linewidth}
  \centering
  \begin{tabular}{|>{\bfseries\centering}m{.1\tabularlength}|*{3}{M}|}
    \cline{2-4}
    \multicolumn{1}{l|}{} & \textbf{Hibernate OGM} & \textbf{EclipseLink NoSQL} & \textbf{DataNucleus}\tabularnewline\hline
    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\tabularnewline\hline
    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\tabularnewline\hline
    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.\tabularnewline\hline
    No support for & Denormalization, Complex joins and aggregations & Joins & Aggregations? (not specified in documentation)\tabularnewline\hline
    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\tabularnewline\hline
    Commercial support & Red Hat & Oracle (via TopLink) & Supported by DataNucleus team\tabularnewline\hline
    Document\-ation & 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\tabularnewline\hline
  \end{tabular}
\end{table}

\end{landscape}

\end{document}

Die Ausgabe

Alle zentrierten Tabellen

Antwort2

Bildbeschreibung hier eingeben

Ihr Hauptfehler war die Mehrspaltigkeit, die die Spalte mit der angegebenen Breite durch eine lSpalte mit natürlicher Breite ersetzte.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array}

\begin{document}
\begin{table}
\centering\small
\newcommand{\mc}[3]{\multicolumn{#1}{#2}{#3}}
\setlength{\dimen0}{\dimexpr\textwidth-6\tabcolsep\relax}
\begin{tabular}{@{}>{\hspace*{0pt}\bfseries}p{.1\dimen0}*3{p{.3\dimen0}}}
 & \textbf{Hibernate OGM} & \textbf{EclipseLink NoSQL} & \textbf{DataNucleus}\\\hline
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\\\hline
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\\\hline
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.\\\hline
No support for & Denormalization, Complex joins and aggregations & Joins & Aggregations? (not specified in documentation)\\\hline
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\\\hline
Commercial support & Red Hat & Oracle (via TopLink) & Supported by DataNucleus team\\\hline
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\\\hline
\end{tabular}

\end{table}


\end{document}

verwandte Informationen