8
I need to play in Latex a table with 3 columns and 5 rows. It should use the entire paragraph width, center the cell contents both horizontally and vertically, and auto-adjust longer texts. But most of all, you need to have same height for all lines.
I used the tabularx
(to more easily have the table in paragraph width), I reset the type of column X to center the contents of the cells horizontally and vertically and I arrived at this result:
Code with Minimal Compilable Example
\documentclass[10pt,a4paper]{article}
\usepackage[portuguese]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tabularx}
\usepackage{ragged2e}
\begin{document}
% Redefine a coluna do tipo X para centralizar horizontal e verticalmente seu conteúdo
\renewcommand\tabularxcolumn[1]{>{\Centering}m{#1}}
\begin{table}[!h]
\begin{center}
\begin{tabularx}{\textwidth}{|X|X|X|}
\hline
Linha 1 & Lorem ipsum dolor sit amet. & Aenean suscipit, nunc ac sodales bibendum, massa lacus iaculis augue, ut suscipit mauris libero in velit. \\
\hline
Linha 2 & Vivamus quis justo ac elit condimentum molestie. & Etiam ultrices a libero sed semper. \\
\hline
Linha 3 & Morbi ultrices sodales justo, et dictum quam sodales eget. & Cras tortor libero, volutpat eget erat eu, blandit tempus nunc. \\
\hline
Linha 4 & Pellentesque gravida, odio sed aliquet tempus, metus lectus sodales sapien. & Fusce fermentum malesuada eros. \\
\hline
Linha 5 & Etiam commodo interdum dictum. In sit amet semper leo. In non auctor mauris. & Vivamus ultrices augue non enim pulvinar feugiat. \\
\hline
\end{tabularx}
\end{center}
\end{table}
\end{document}
Resulting Table
I just haven’t been able to leave all the lines at the same height yet (ideally the first line, since it was the least possible to include the contents of the rightmost cell). I’ve tried to specify additional spacing at the end of each line, but this solution requires a lot of trial and error and the end result is not good because it adds spaces only in the last column. I also tried use the package easytable
, but it does not allow to fix the width of the paragraph and ends up extrapolating the page limits, and also does not make the automatic breaking of long texts. And finally I tried to do it too the change in vertical spacing (or arraystretch), but the result was not expected because apparently this command only increases the internal margin of the cells and does not guarantee that the lines have the same height.
Does anyone have a solution to this problem?
There is a website for Tex.
– user2692
@Lucashenrique I know (so much so that I even referenced in the question itself some information directly from there). I just wanted to post the question here to stimulate Tex content on Sopt.
– Luiz Vieira