Graphics, Figures & TablesTable with long entries spanning multiple rows

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
barakkhazad
Posts: 7
Joined: Wed Jul 22, 2009 9:54 pm

Table with long entries spanning multiple rows

Post by barakkhazad »

Hello everybody,
I need help with a table that, as the title of the post says, contains some long entries which span multiple rows.

I am using the landscape environment to get some more space so that the entries can fit, but still i have the problem that the {*} specification for the multirow command simply assigns the natural width of the text to the column. What I need is that the text of the entry is distributed along the different rows that the cell takes, AND, that when doing this, the text remains centered.

This is my code:

Code: Select all

\documentclass[12pt,spanish,a4paper]{letter}
\usepackage{multirow}
\usepackage[latin1]{inputenc}
\usepackage[spanish]{babel}
\usepackage{pdflscape}
\newcommand{\anchocol}{*}
\newcommand{\sesa}{Loooooong text which must be fit into one cell because it's the title of a session}
\newcommand{\sesb}{Not so long text, but it's also not short either}
\newcommand{\sesc}{Long title of a session which should span several rows and still fit nicely}
\newcommand{\sesd}{another semi-long text which could be longer}
\pagestyle{empty}

\begin{document}
\begin{landscape}
\begin{tabular}{cccc}
	Día & 13 & 20 & 27 \\ \hline
	16'00 - 16'30 & Opening & \multirow{2}{\anchocol}{\sesa} & \multirow{2}{\anchocol}{\sesb} \\
	16'30 - 17'00 & \multirow{3}{\anchocol}{\sesd} & & \\
	17'00 - 17'30 & & Session 1 b & Session 2 b \\
	17'30 - 18'00 & & Pausa & Pausa \\ \hline
	18'00 - 18'30 & Pausa & \multirow{4}{\anchocol}{Workshop 1} & \multirow{4}{\anchocol}{Workshop 2} \\
	18'30 - 19'00 & \multirow{3}{\anchocol}{\sesc} & & \\
	19'00 - 19'30 & & & \\
	19'30 - 20'00 & & & \\ \hline
\end{tabular}
\end{landscape}
\end{document}
That produces as I said, cells which titles are fit into one line, which is extended and makes the table too wide, impossible to fit in a page. If I change the preamble for this:

Code: Select all

\newcommand{\anchocol}{10cm}
\newcommand{\sesa}{Loooooong text which must be fit into one cell\\because it's the title of a session}
\newcommand{\sesb}{Not so long text, but it's also not short either}
\newcommand{\sesc}{Long title of a session which should\\span several rows and still fit nicely}
\newcommand{\sesd}{another semi-long text which could be longer}
\pagestyle{empty}
what I get is still unsatisfactory since the titles of the entries are dragged to the left, and don't look nice.

This:

Code: Select all

\newcommand{\anchocol}{0.5\textwidth}
also has the same problem. Texts don't fit...

Any idea about how to format it so that it looks OK? I'm going crazy!
Thanks for your help and any answer! :roll:

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table with long entries spanning multiple rows

Post by localghost »

Just choose other column types for the tabular environment. Enhancements for this environment are provided by the array package. Tables which fit the line width can be created with the tabularx package. Nice looking tables are produced with booktabs. The rotating package offers some more options to rotate floats.


Best regards
Thorsten
Post Reply