
Estoy usando Kile y estoy tratando de aprender cómo usarlo tabularx
para tener tablas que se ajusten al ancho de mis páginas.
Sin embargo, tengo dos grandes problemas:
- Tengo que usar X para el tamaño de la columna y por lo tanto no puedo establecer el tamaño de mis columnas (por ejemplo, si tengo 4 columnas, quiero que la columna A tenga el 10% del tamaño y las columnas B, C y D tengan el resto). igualmente distribuida).
- Ahora que mi tabla finalmente cabe dentro del ancho de la página, no respeta el alto de la página…
Ahora, para solucionar este problema, leí la documentación y utilicé el siguiente MWE:
\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}
Sin embargo, aunque el preámbulo parece correcto (para un caso con 4 columnas, donde las columnas B, C y D deberían ser 6 veces mayores que A) no sucede nada.
¿Qué quiero exactamente? Digamos que el ancho total de la mesa es del 100%. Me gustaría que la columna A tuviera el 10% de ese ancho, y las columnas B, C y D tuvieran el 30% cada una.
También me gustaría que esta tabla quepa en una página, sin extenderla a páginas adicionales. Entonces no, no puedo usar longtable...
El MWE actualmente genera algo como esto:
La documentación que leí se puede encontrar aquí:
¿Cómo puedo solucionar mis problemas?
Respuesta1
Aquí hay una forma de hacerlo:
- Úselo
p{<width>}
para todas las columnas de un archivotabular
. - Para hacer esto, cree una nueva longitud
\tabularlength
y configúrela en el ancho total de la tabla. He usado.975\linewidth
aquí. - Luego defina cada una de las columnas en términos de ,
\tabularlength
por ejemplop{.1\tabularlength}
. - Para conseguir que la primera columna se comporte, prescinde de
multicolumn
modo que se puedan romper las líneas. - Esto significa que queremos separación de palabras, así que cargue
babel
. - Esto no es suficiente ya que no permite la separación de palabras de la primera palabra de la columna. Así que separe estas palabras a mano usando
\-
. - Úselo
geometry
para obtener el diseño de página correcto. - Úselo
>{\bfseries}
para la primera columna para evitar tener que especificar negrita en cada línea. - Todavía necesitamos uno
\multicolumn
para la primera línea para no obtener reglas verticales falsas. - Use
\centering
en lugar del entorno,center
ya que este último agrega un espacio adicional que no queremos aquí.
En realidad, esto encaja con (un poco) de espacio de sobra. Si la tabla fuera más grande, podría considerar usarla \small
dentro del table
entorno para establecer el tamaño de fuente un poco más pequeño. O podrías ajustar los márgenes, etc. usando geometry
. Es posible hacer esto para todo el documento o, si es necesario, para una sola página.
El código
\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}
La salida
Un diseño alternativo
Creo que también deberías considerar incluir el formato tabular en orientación horizontal, ya que esto podría hacer que sea más fácil de digerir para las personas. Por ejemplo:
En este caso, utilicé una directiva de formato adicional para la primera columna, \raggedright
para que pareciera razonable.
Código para tabular horizontal
\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}
Columnas centradas y reglas verticales.
Como señaló Flame_Phoenix en los comentarios, m{<width>}
proporciona una columna de ancho específico que está centrada verticalmente. Este especificador requiere el array
paquete.
Agregar una regla vertical antes de 'Hibernar OGM' es solo una cuestión de ajustar la \multicolumn
primera entrada de la tabla. Se puede centrar todas las celdas horizontal y verticalmente agregando >{\centering}
la configuración tabular. Sin embargo, esto resulta un poco tedioso y es más difícil de ajustar de manera consistente. Una mejor solución utiliza la capacidad de array
definir un nuevo tipo de columna.
\newcolumntype{M}{>{\centering}m{.3\tabularlength}}
Debido a que mi ejemplo muestra el diseño tanto para retrato como para paisaje, también necesito agregar elementos \tabularlength
fuera de los tabular
entornos para no intentar definir una longitud ya definida.
\newlength{\tabularlength}
El m
tipo de columna se trata \\
como una nueva línea dentro de la columna en lugar del final de la fila. Por lo tanto necesito reemplazar \\\hline
con \tabularnewline\hline
.
Finalmente, agregué una regla vertical en el extremo derecho para mayor claridad.
El código
\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}
La salida
Respuesta2
Su principal error fue la columna múltiple que reemplazaba la columna de ancho especificado por una l
columna de ancho natural.
\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}