Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm having trouble doing vertical alignment in tables with multirow in Lyx. I have data that is in a 'tree' format that I need to present in tables. I would like Category 1, Subcategory 1.1 and Value 1 to all align vertically, same for Category 2, subcategory 2.1 etc. Any tips? The normal 'align top' option is disabled in Lyx as soon as I use multirow.

Example of problem

This is the latex source created by my lyx file:

% Preview source code

%% LyX 2.0.0 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[english]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{multirow}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

\makeatother

\usepackage{babel}
\begin{document}
\begin{tabular*}{1\columnwidth}{@{\extracolsep{\fill}}>{\raggedright}m{0.33\columnwidth}>{\raggedright}m{0.33\columnwidth}>{\centering}p{0.33\columnwidth}}
Column 1 & Column 2 & Column 3\tabularnewline
\multirow{4}{0.33\columnwidth}{Category 1 With very long text that wraps} & \multirow{2}{0.33\columnwidth}{Subcategory 1.1} & Value 1\tabularnewline
 &  & Value 2\tabularnewline
 & \multirow{2}{0.33\columnwidth}{Subcategory 1.2} & Value 3\tabularnewline
 &  & Value 4\tabularnewline
\multirow{2}{0.33\columnwidth}{Category 2} & Subcategory 2.1 & Value 5\tabularnewline
 & Subcategory 2.2 & Value 6\tabularnewline
\end{tabular*}
\end{document}
share|improve this question
add comment

1 Answer

I am not sure about the alignment that you desire; perhaps something like this?

\documentclass[english]{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{multirow}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
%% Because html converters don't know tabularnewline
\providecommand{\tabularnewline}{\\}

\makeatother

\usepackage{babel}
\begin{document}

\begin{tabular*}{1\columnwidth}{@{\extracolsep{\fill}}>{\raggedright}m{0.33\columnwidth}>{\raggedright}m{0.33\columnwidth}>{\centering}p{0.33\columnwidth}}
Column 1 & Column 2 & Column 3\tabularnewline
\multirow{2}{0.33\columnwidth}{Category 1 With very long text that wraps} & Subcategory 1.1 & Value 1\tabularnewline
 &  & Value 2\tabularnewline
 & Subcategory 1.2 & Value 3\tabularnewline
 &  & Value 4\tabularnewline
Category 2 & Subcategory 2.1 & Value 5\tabularnewline
 & Subcategory 2.2 & Value 6\tabularnewline
\end{tabular*}

\end{document}
share|improve this answer
    
medina Thanks. That works. It is a little clunky though having to manually chose the number of lines to make each multirow depending on the length of text - means redoing in case of changing the font size for example. In the past, vertical alignment did seem to work in multirow cells in Lyx, so not sure what has change. Thanks though - sorted for now! –  moabi2000 Jun 18 '11 at 15:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.