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 want to vertically align (best would be to center) the text ("TEST") in the left (yellow) column of the following table. It works fine with multirow when every row has exactly the hight of one line:

\documentclass[ngerman,a4paper,12pt,pdftex]{report}
\usepackage[utf8]{inputenc}
\usepackage{rotating}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{colortbl}

\begin{document}
\begin{longtable}{|p{0.025\textwidth}|p{0.775\textwidth}|>{\centering arraybackslash}m{0.2\textwidth}|}
 & \textbf{foo} & \textbf{bar} \\
\hline
\hline 
\endfirsthead
 & \textbf{foo} & \textbf{bar} \\
\hline
\hline
\endhead
\cellcolor{yellow}& short text & 1 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 2 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 3 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 4 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 5 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 6 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 7 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 8\\
\cline{2-3} 
\cellcolor{yellow} & short text & 9 \\
\cline{2-3} 
\multirow{-10}{*}{\cellcolor{yellow}\begin{sideways}TEST\end{sideways}}  & short text &  10 \\
\hline
\end{longtable}

\end{document}

enter image description here

When there is a long text in one of the cells, the text of the left cell ("TEST") is aligned somewhere:

\documentclass[ngerman,a4paper,12pt,pdftex]{report}
\usepackage[utf8]{inputenc}

\usepackage{rotating}
\usepackage{multirow}
\usepackage{longtable}
\usepackage{colortbl}

\begin{document}
\begin{longtable}{|p{0.025\textwidth}|p{0.775\textwidth}|>{\centering\arraybackslash}m{0.2\textwidth}|}
 & \textbf{foo} & \textbf{bar} \\
\hline
\hline 
\endfirsthead
 & \textbf{foo} & \textbf{bar} \\
\hline
\hline
\endhead
\cellcolor{yellow}& short text & 1 \\
\cline{2-3} 
\cellcolor{yellow} & medium text ........ ....... ....... ....  ........ ....... ....... .... ........ ....... ....... ....needs two lines & 2 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 3 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 4 \\
\cline{2-3} 
\cellcolor{yellow} & medium text ........ ....... ....... ....  ........ ....... ....... .... ........ ....... ....... ....needs two lines & 5 \\
\cline{2-3} 
\cellcolor{yellow} & very long text ....... ......... ........ ....... ....... ....... ........ ............. ....... ........ ...... ....... ....... ........ ...... ....... ....... ........ ...... ....... ....... ........ ...... ....... ....... ........ ...... ....... ....... ........ ...... ....... ....... ........ ...... needs lots of lines & 6 \\
\cline{2-3} 
\cellcolor{yellow} & short text & 7 \\
\cline{2-3} 
\cellcolor{yellow} & medium text ........ ....... ....... ....  ........ ....... ....... .... ........ ....... ....... ....needs two lines & 8\\
\cline{2-3} 
\cellcolor{yellow} & short text & 9 \\
\cline{2-3} 
\multirow{-10}{*}{\cellcolor{yellow}\begin{sideways}TEST\end{sideways}}  & short text &  10 \\
\hline
\end{longtable}

\end{document}

enter image description here

How can I align the text of the left column in the second example?

share|improve this question
    
Is your tabular really a longtable which could break across pages? If yes what should happen if the page break is at the places of TEST? –  Ulrike Fischer Aug 10 '12 at 8:02
    
It's a two page table which I break manually after the "TEST" section using the \newpage command –  Philipp Aug 10 '12 at 8:05
    
Here are the images of the two tables (I am not allowed to add them in the question) dropbox.com/s/z24or3i6795w3vk/test1.png and dropbox.com/s/exdfcvfw9q9dr5c/test2.png –  Philipp Aug 10 '12 at 8:10
2  
In general I try to avoid multirow. I would in your case probably use tikz with [remember picture] to place nodes in the corners and then connect them. But it would be some fine tuning to get the size correct. Another way is to nest tabulars, but this could get a bit difficult due to the headers. Beside this I would much less lines ;-). –  Ulrike Fischer Aug 10 '12 at 9:02
add comment

1 Answer

up vote 4 down vote accepted

From my experience multirow is not capable of a correct vertical alignment, if it spans multi-line cells. You can, however, adjust the alignment manually using the fixup-parameter:

% \multirow{nrows}[bigstruts]{width}[fixup]{text}
\multirow{-10}{*}[3em]{\cellcolor{yellow}\begin{sideways}TEST\end{sideways}}

Other possibilities for solving this problem are discussed in "Centering mutirow text in a table whose cells contain several lines of text" and "How can I achieve proper vertical spacing for long blocks of text within a \multirow?".

share|improve this answer
    
thx - it's not the solution I hoped but it seems the best way to use the fixup-parameter –  Philipp Aug 14 '12 at 9:17
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.