
Tengo una tabla con títulos cortos y largos. Estoy usando el tipo de columna X
del tabularx
paquete. Los títulos están alineados en la parte superior, ¿cómo puedo alinear los títulos horizontalmente en el medio?
\documentclass[12pt,a4paper]{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}[htb]
\centering
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{*2{>{\centering\arraybackslash}X}}
\toprule
\textbf{Short heading\newline(units)} &
\textbf{This is a long long, very very long heading\newline(units)}\\%
\midrule
416,09 & 194,30 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
Respuesta1
Suponiendo que desea lograr entradas centradas horizontal y verticalmente, puede utilizar la siguiente redefinición de X
columnas de tipo. Normalmente se derivan de p
columnas de tipo alineadas en la parte superior. Con \renewcommand{\tabularxcolumn}[1]{m{#1}}
podemos cambiar eso para que x
las columnas de tipo se deriven de las m
columnas de tipo centradas verticalmente.
\documentclass[12pt,a4paper]{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{array}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}
\begin{table}[htb]
\centering
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{*2{>{\centering\arraybackslash}X}}
\toprule
\textbf{Short heading\newline(units)} &
\textbf{This is a long long, very very long heading\newline(units)}\\%
\midrule
416,09 & 194,30 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
Si desea utilizar X
columnas tipográficas centradas horizontal y verticalmente con más frecuencia en todo el documento, también puede agregarlas \newcolumntype{Y}{>{\centering\arraybackslash}X}
al preámbulo y usar \begin{tabularx}{\linewidth}{*2{Y}}
.
Si desea mantener la definición original de X
columnas de tipo alineadas superiormente y tener un tipo de columna separada derivada y centrada verticalmente, es posible que desee echar un vistazo aCopie la columna tabularx X como una nueva columna centrada verticalmente
Si solo desea cambiar la alineación vertical de una sola tabla, puede utilizar la siguiente redefinición local de la X
columna de tipo. Aquí he añadido \renewcommand{\tabularxcolumn}[1]{m{#1}}
justo después \begin{table}
de la tabla correspondiente.
\documentclass[12pt,a4paper]{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}[htb]
\centering
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{*2{>{\centering\arraybackslash}X}}
\toprule
\textbf{Short heading\newline(units)} &
\textbf{This is a long long, very very long heading\newline(units)}\\%
\midrule
416,09 & 194,30 \\
\bottomrule
\end{tabularx}
\end{table}
\begin{table}[htb]
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\centering
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{*2{>{\centering\arraybackslash}X}}
\toprule
\textbf{Short heading\newline(units)} &
\textbf{This is a long long, very very long heading\newline(units)}\\%
\midrule
416,09 & 194,30 \\
\bottomrule
\end{tabularx}
\end{table}
\begin{table}[htb]
\centering
\caption{My caption}
\label{my-label}
\begin{tabularx}{\linewidth}{*2{>{\centering\arraybackslash}X}}
\toprule
\textbf{Short heading\newline(units)} &
\textbf{This is a long long, very very long heading\newline(units)}\\%
\midrule
416,09 & 194,30 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}