Lines with same height in table in the Latex

8

I need to reproduce in Latex a table with 3 columns and 5 rows. It should use the full width of the paragraph, center the contents of the cells both horizontally and vertically, and auto-adjust longer texts. But above all, it must have the same height for all lines .

I used tabularx (to have the table more easily in the width of the paragraph), I redefined the type of column X to center the contents of the cells horizontally and vertically, and I got to this result:

Code with Minimum Compileable 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}

Resultant Table

Ijusthavenotbeenabletoleavealltherowswiththesameheight(ideallythefirstrow,sinceitwastheleastpossibletoincludetherightcellcontent).I'vealreadytried specify extra spacing at the end of each line , but this solution requires a lot of trial and error and the end result is not is good because it only adds spaces in the last column. I've also tried package easytable , but it does not allow you to set the width of the paragraph and ends up extrapolating the limits of the page, as well as not wrapping long texts. And finally I also tried changing the vertical spacing (or arraystretch ) , but the result was not expected because apparently this command only increases the inner margin of the cells and does not guarantee that the rows have the same height.

Does anyone have a solution to this problem?

    
asked by anonymous 07.07.2014 / 19:40

1 answer

3

As you have also used, the package tabularx is best for dealing with tables with large rows, as it does the line break by itself.

To get all cells of the same height I used the command \parbox . This command creates a paragraph inside a box and the general syntax is:

\parbox[pos][height][contentpos]{width}{text}

pos can be b,c or t and controls the alignment of the box, relative to the baseline of the text. height and height, which I used to control the height of each cell. contentpos controls the position of the text, which I know used to leave centered with c . width and box size. As we are inside the table, \linewidth and 1/3 of the line, since we have 3 columns. Then comes the text.

A parbox and basically a minipage .

Your example table was quite large, however: P

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{.85\linewidth}{|X|X|X|}
\hline
\parbox[b][\linewidth][c]{\linewidth}{\centering Linha 1}
& \parbox[b][\linewidth][c]{\linewidth}{\centering  Lorem ipsum dolor sit amet.}
& \parbox[b][\linewidth][c]{\linewidth}{\centering  Aenean suscipit,
  nunc ac sodales bibendum, massa lacus iaculis augue, ut suscipit
  mauris libero in velit.}\
\hline
\parbox[b][\linewidth][c]{\linewidth}{\centering Linha 2}
& \parbox[b][\linewidth][c]{\linewidth}{\centering Vivamus quis justo ac elit condimentum molestie.}
& \parbox[b][\linewidth][c]{\linewidth}{\centering Etiam ultrices a
  libero sed semper.}\
\hline
\parbox[b][\linewidth][c]{\linewidth}{\centering Linha 3}
& \parbox[b][\linewidth][c]{\linewidth}{\centering Morbi ultrices sodales justo, et dictum quam sodales eget.}
& \parbox[b][\linewidth][c]{\linewidth}{\centering Cras tortor libero,
  volutpat eget erat eu, blandit tempus nunc.}\
\hline
\parbox[b][\linewidth][c]{\linewidth}{\centering Linha 4}
& \parbox[b][\linewidth][c]{\linewidth}{\centering Pellentesque
  gravida, odio sed aliquet tempus, metus lectus sodales sapien.}
& \parbox[b][\linewidth][c]{\linewidth}{\centering Fusce fermentum
  malesuada eros.}\
\hline
\parbox[b][\linewidth][c]{\linewidth}{\centering Linha 5}
& \parbox[b][\linewidth][c]{\linewidth}{\centering Etiam commodo interdum dictum. In sit amet semper leo. In non auctor mauris.}
& \parbox[b][\linewidth][c]{\linewidth}{\centering Vivamus ultrices
  augue non enim pulvinar feugiat.}\
\hline
\end{tabularx}
\end{document}
\end{document}

Generates:

References about parbox on wikipedia .

    
09.07.2014 / 20:22