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.

The documentation for the multirow package implies that the content of a \multirow will be vertically centered by default. In this example (machine-generated from a Word document, hence all the poodlefaking):

  • in the first row, the first cell spans 3 rows, and the other cells are just cells;
  • in the second row, the first cell continues its spanning, and the other cells all span 2 rows;
  • the author has unwittingly added a bogus third row, but it shouldn't matter, as it has to be there to be the recipient of the spans from rows 1 and 2.

output from code below (Ignore the extra rules: I'm still working on the code to get that right)

The problem is that the text in col 1 is not vertically-centred with respect to the 3 rows that it spans. Cells 2/3/4 on row 2 are correctly vertically-centred in themselves. I can try to add the fixup optional argument to \multirow, but this is within an automated process, so working out how much to add is problematic, as for the general case, there is no easy way to calculate the amount.

\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=1in]{geometry}
\usepackage{array,multirow}
\pagestyle{empty}
\begin{document}
% code generated from Word OOXML via XSLT2
\begin{tabular}{@{}
    |>{\raggedright}p{3cm}
    |>{\raggedright}p{3cm}
    |>{\raggedright}p{3cm}
    |>{\raggedright}p{3cm}
    |@{}}\hline
% first row
\multirow{3}{3cm}[-2\baselineskip]{Tests:}
&\multicolumn{1}{|>{\raggedright}m{3cm}|}{Vortest}
&\multicolumn{1}{|>{\raggedright}m{3cm}|}{1. Nachtest}
&\multicolumn{1}{|>{\raggedright}m{3cm}|}{2. Nachtest}\\
% second row
&\multirow{2}{3cm}{Juni vor dem TSC}
&\multirow{2}{3cm}{September nach dem TSC}
&\multirow{2}{3cm}{Mai/Juni im Jahr nach dem TSC}
\\\cline{1-1} % this is line 24
% bogus third row
&&&\\\cline{1-1}\cline{2-2}\cline{3-3}\cline{4-4}
\end{tabular}
\end{document}

The other problem is that processing this document gets me the error:

! Misplaced \omit.
\@cline #1-#2\@nil ->\omit 
                       \@multicnt #1\advance \@multispan \m@ne \ifnum \@...
l.24     \\\cline{1-1}

! Leaders not followed by proper glue.
<to be read again> 
               \hfill 
l.24     \\\cline{1-1}
share|improve this question
    
How much of it is automatically generated and how much control do you have over the template? Although multirow is a good solution, it may not be appropriated for what you are trying to achieve since it has to be manually twicked to span correctly over multiline cells. Using nested tabular can also produce the same thing. –  ArTourter Aug 9 '12 at 0:37
    
Good point — I have complete control over the XSLT but not over the documents. Multirow certainly works (better since I took out the [fixup] arguments that I was trying out). I haven't tried a nested tabular yet. –  Peter Flynn Aug 9 '12 at 9:33

2 Answers 2

By default, multirow will center your text vertically, however your compiling error is what is stopping your code working. You must add \arraybackslash after your \raggedright in the column definition. Once that's done, you can remove your base line adjustment.

Also to simplify your code, you could define a couple of new column types:

\documentclass[preview,border=1px]{standalone}
\usepackage{array,multirow}
\pagestyle{empty}

\newcolumntype{P}{>{\raggedright\arraybackslash}p{3cm}}
\newcolumntype{M}{>{\raggedright\arraybackslash}m{3cm}}

\begin{document}
% code generated from Word OOXML via XSLT2
\begin{tabular}{@{}|P|P|P|P|@{}}\hline
% first row
\multirow{3}{3cm}{Tests:}
&\multicolumn{1}{M|}{Vortest}
&\multicolumn{1}{M|}{1. Nachtest}
&\multicolumn{1}{M|}{2. Nachtest}\\
% second row
&\multirow{2}{3cm}{Juni vor dem TSC}
&\multirow{2}{3cm}{September nach dem TSC}
&\multirow{2}{3cm}{Mai/Juni im Jahr nach dem TSC}
\\\cline{1-1} % this is line 24
% bogus third row
&&&\\\cline{1-1}\cline{2-2}\cline{3-3}\cline{4-4}
\end{tabular}
\end{document}

Fixing the multiple vertical lines is also done here by only adding the line after the column definition instead of both before and after:

enter image description here

However, I am not entirely sure what you are trying to achieve and the multirow in the second line are to me a bit confusing. Could you clarify what you are trying to achieve exactly?

share|improve this answer
    
IMHO the whole \multirow construct is unnecessary (except maybe for the Tests: cell), since the OP and you already use column types which allow line breaking within cells. Furthermore, if there are already some multi-line cells to be spanned the vertical alignment of multirow needs to be corrected manually (in almost all cases) by adjusting the respective optional parameters. –  hakaze Aug 8 '12 at 15:07
    
@hakaze That's what I thought. I just wanted to get confirmation. I guess the problem comes from the fact that the code is automatically generated which most of the time can created rather strange things. –  ArTourter Aug 8 '12 at 15:37
    
Thanks...I had removed the \arraybackslash which I shouldn't have done. This script has to handle an arbitrary number of documents with arbitrary numbers of tables with arbitrary numbers of column and row spans, so pregenerating new column types isn't going to be meaningful. The multirow in row 2 and the bogus 3rd row are in the Word document, the result of careless editing by the author: I cannot change that. –  Peter Flynn Aug 9 '12 at 9:36
    
How do you get hold of the fact that the cells in the second line spread over 2 lines? –  ArTourter Aug 9 '12 at 10:22
\documentclass{article}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=1in]{geometry}
\usepackage{array,multirow}
\pagestyle{empty}
\begin{document}

\begin{tabular}{|p{3cm}|p{3cm}|p{3cm}|p{3cm}|}\hline
\multirow{3}{3cm}{Tests:} & Vortest & 1.Nachtest & 2. Nachtest \\\cline{2-4}
&\multicolumn{1}{r|}{\multirow{2}{3cm}{ Juni vor dem TSC}} & \multicolumn{1}{r|}{\multirow{2}{3cm}{September nach dem TSC}} &\multicolumn{1}{r|}{ \multirow{2}{3cm}{Mai/Juni im Jahr nach dem TSC }}\\
      &      &     & \\\cline{2-4}\hline
\end{tabular}

\end{document}

This seems to work without the need for specifying tab stops.

enter image description here

share|improve this answer
    
I have kept to using multicolumn{1}'s for plain cells because the code needs to be able to handle arbitrary cell borders left and right which the author might have added or removed. But the multirow inside the multicolumn{1} seems to do the trick. I'm just slightly amazed that it works, thanks very much. –  Peter Flynn Aug 9 '12 at 9:41

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.