Graphics, Figures & TablesLinebreak inside multirow environment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Linebreak inside multirow environment

Post by ptrcao »

I want to do a \\ or \par or something to equivalent effect inside the text argument of the multirow environment. In the table below, after "Light" I want to enter down a line so "Photo-" begins on a new line.

I use TexWorks. The table in question:

Code: Select all

\documentclass[12pt]{article}

\usepackage{a4wide} %yeah, I know it's obsolete; just until I learn how to use geometry

\usepackage{booktabs} %for top, middle and bottomline

\usepackage{multirow} %multi column and row spanning

\usepackage{rotating} %enables sidewaystable

\begin{document}

\begin{sidewaystable}[h]
\centering
\begin{tabular}{l l l l}
 \toprule
\multicolumn{4}{c}{Nutritional Modes}\\
\midrule
Energy source & Reducing equivalent source & Carbon source & Name\\
\cmidrule(r){1-1} \cmidrule(l r){2-2}  \cmidrule(l r){3-3}  \cmidrule(l){4-4}
\multirow{4}{*}{Light {\it Photo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Photoorganoheterotroph\\
& & Carbon dioxide -autotroph & Photoorganoautotroph \\
\cmidrule(l r){2-4}
&  \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Photolithoheterotroph\\
& & Carbon dioxide -autotroph & Photolithoautotroph \\ 
\midrule
\multirow{4}{*}{Chemical compounds {\it Chemo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Chemoorganoheterotroph\\
& & Carbon dioxide -autotroph & Chemoorganoautotroph \\
\cmidrule(l r){2-4}
&  \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Chemolithoheterotroph\\
& & Carbon dioxide -autotroph & Chemolithoautotroph\\ 
\bottomrule
\end{tabular}
\end{sidewaystable}


\end{document}
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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

Linebreak inside multirow environment

Post by localghost »

You could use a \parbox of a certain width.


Thorsten
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Linebreak inside multirow environment

Post by ptrcao »

localghost wrote:You could use a \parbox of a certain width.


Thorsten
Since the width argument is mandatory, how would I make the parbox adapt exactly and automatically to the width of the column?

The column width is itself liable to change so I prefer not to specify a fixed width for parbox.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Linebreak inside multirow environment

Post by localghost »

You can use the \linewidth length parameter.
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Linebreak inside multirow environment

Post by ptrcao »

localghost wrote:You can use the \linewidth length parameter.
Thanks, tried it, but it appears both \linewidth and \textwidth are not interpreted as the width of the column but the width of the page or something wider than the column itself... Any suggestions?
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Linebreak inside multirow environment

Post by localghost »

My fault, of course. This would only work in a table cell with a specified width like the »p{…}« colum type. So either use this type or set up your tables with the quite new tabu package and use its »X« column types.
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Linebreak inside multirow environment

Post by ptrcao »

localghost wrote:My fault, of course. This would only work in a table cell with a specified width like the »p{…}« colum type. So either use this type or set up your tables with the quite new tabu package and use its »X« column types.
Ah ok, well that would explain it then. :roll:

In general, I really try to avoid setting fixed widths for anything. I would rather not have to make these decisions about typesetting; I mean LaTEX algorithms should be deciding the optimum width, not me. It also creates an inflexible situation where there is no automatic readjustment on modifying the table contents and I edit my tables a lot. I want a way of telling Latex to "use as much space as needed, optimise the widths for a balanced appearance, and don't bother me for micromanagement details". At the same time, I want to maintain to full range of functionalities of tables that some specialist packages don't have.

I haven't studied it at depth, but the tabu package seems to require manual setting of parameters; I apparently have to supply column ratios...

Word processors seem to make these decisions effectively, automanaging table dimensions and column widths to good effect. But like many who peruse these forums, I'm committed to LaTEX...

Any other ideas? The original problem of linebreaking was resolved, but not without introducing the problem of having to manually set a width for \parbox, which I want to be the width of the column, but there doesn't appear to be a way to specify "the width of the column" whatever it has been set to by tabular or other packages.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Linebreak inside multirow environment

Post by localghost »

The only thing I can come up with is what I think a workaround. That is to say a table within a table.

Code: Select all

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage[margin=1in]{geometry}
\usepackage{booktabs,multirow}
\usepackage{rotating}

\begin{document}
  \begin{sidewaystable}
    \centering
    \begin{tabular}{*4l}\toprule
      \multicolumn{4}{c}{Nutritional Modes} \\ \midrule
      Energy source & Reducing equivalent source & Carbon source & Name\\
      \cmidrule(r){1-1} \cmidrule(l r){2-2}  \cmidrule(l r){3-3}  \cmidrule(l){4-4}
      \multirow{4}{*}{\begin{tabular}{@{}l@{}} Light \\ \emph{Photo-}\end{tabular}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Photoorganoheterotroph \\
      & & Carbon dioxide -autotroph & Photoorganoautotroph \\ \cmidrule(l r){2-4}
      &  \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Photolithoheterotroph \\
      & & Carbon dioxide -autotroph & Photolithoautotroph \\ \midrule
      \multirow{4}{*}{Chemical compounds \emph{Chemo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Chemoorganoheterotroph \\
      & & Carbon dioxide -autotroph & Chemoorganoautotroph \\ \cmidrule(l r){2-4}
      &  \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Chemolithoheterotroph \\
      & & Carbon dioxide -autotroph & Chemolithoautotroph \\ \bottomrule
    \end{tabular}
  \end{sidewaystable}
\end{document}
Finally some remarks to your example.
  • Even if you have not learned yet how to use geometry (although you should), using a4wide (setup for A4 paper) contradicts with your chosen paper format (letter paper). The package does not set the correct paper dimensions.
  • We are using LaTeX2e, so you should abstain from using the old LaTeX2.09 syntax like \it or similar. Use the correct syntax like \emph{…} or \textit{…} for setting font styles.
Post Reply