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.

Editted to provide a clearer example

Basically I want to make a table that in one column has a series of dates and the second and third columns have a series of objectives for that date. However the number of elements in the second and third column are not the same, and do not share a common factor, however I want all three columns to be equally spaced vertically. In other words the vertical distance between the 2011-2012 should be the same to both Training 1 and Training 2, and they should be between the Objectives.

So, for example, what I want to do is:

\begin{tabular}{|l c c|}
    \hline
    Year & Objective & Training \\
    \hline
    \multirow{5}{*}{2011-2012} & Objective 1 & \multirow{1.5}{*}{Training 1} \\
                         & Objective 2 &                               \\
                         & Objective 3 & \multrow{1.5}{*}{Training 2}  \\
    \hline
\end{tabular}

To look something like:

             Year         Objective     Training
                          Objective 1
                                        Training 1
             2011-2012    Objective 2
                                        Training 2
                          Objective 3

But with the vertical space between Objectives compressed. Obviously this doesn't work as multirow expects an integer number. Is there another command where a non-integer number would work, or a work around to get the effect that I desire.

What is the best way of doing something like this?

Additional edit

This needs to be scalable, so that I can take any three numbers I choose and be able to make an evenly spaced table e.g.

enter image description here

The colours do not need to be replicated, they are merely illustrative (plus are easy enough to do via colorx). The top row are the titles, the multi-coloured segments are columns with a different number of elements (the number of elements in each column is stated in the title).

share|improve this question

migrated from stackoverflow.com Aug 16 '12 at 9:02

This question came from our site for professional and enthusiast programmers.

    
Oh - and it would be nice if the solution worked within tabularx - or some other format that allowed each section to span multiple rows, but even outside that I am curious if there is a work around. –  David Duncan Aug 15 '12 at 11:21
add comment

1 Answer

up vote 6 down vote accepted

Exactly what you're doing is fine, but your use of the multirow package and associated \multirow command is incorrect:

enter image description here

\documentclass{article}
\usepackage{multirow}% http://ctan.org/pkg/multirow
\begin{document}
\begin{tabular}{|l c c|}
    \hline
    Year & Objective & Training \\
    \hline
    \multirow{5}*{2011-2012} & Objective 1 & \multirow{2}*{Training 1} \\
                         & Objective 2 &                               \\
                         & Objective 3 & \multirow{3}*{Training 2}  \\
                         & Objective 4 &                               \\
                         & Objective 5 &                               \\
    \hline
\end{tabular}
\end{document}​

In its simplest form, the use is \multirow{<num rows>}{<width>}{<stuff>} where <num rows> is an integer denoting the number of rows to spread <stuff> across. A <width> of * denotes the natural width of <stuff>.

Just in terms of presentation, you could also use booktabs. The motivation being that vertical lines are not required since the structure inherent in a table is columnar, so there's no need to pursue the use of vertical rules:

enter image description here

\documentclass{article}
\usepackage{multirow}% http://ctan.org/pkg/multirow
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\begin{document}
\begin{tabular}{l c c}
    \toprule
    Year & Objective & Training \\
    \midrule
    \multirow{5}*{2011-2012} & Objective 1 & \multirow{2}*{Training 1} \\
                         & Objective 2 &                               \\
                         & Objective 3 & \multirow{3}*{Training 2}  \\
                         & Objective 4 &                               \\
                         & Objective 5 &                               \\
    \bottomrule
\end{tabular}
\end{document}​

Following your edit, you can still specify integer values to have \multirow entries in the way you present:

enter image description here

\documentclass{article}
\usepackage{multirow}% http://ctan.org/pkg/multirow
\begin{document}
\begin{tabular}{|l c c|}
    \hline
    Year & Objective & Training \\
    \hline
    \multirow{3}*{2011-2012} & Objective 1 & \multirow{2}*{Training 1} \\
                         & Objective 2 & \multirow{2}*{Training 2} \\
                         & Objective 3 & \\
    \hline
\end{tabular}
\end{document}​

Moreover, the same output as above is obtained if you even use a negative number of rows for \multirow. That is, to use the following tabular setup:

\begin{tabular}{|l c c|}
    \hline
    Year & Objective & Training \\
    \hline
    \multirow{3}*{2011-2012} & Objective 1 & \multirow{2}*{Training 1} \\
                         & Objective 2 & \\
                         & Objective 3 & \multirow{-2}*{Training 2}\\
    \hline
\end{tabular}

Final edit update:

Centering content within a table is also possible via the m-column type from the array package. So, in order to duplicate the result (without colours and lines/rules), here's one way of doing it:

enter image description here

\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\newcolumntype{C}{@{}c@{}}
\begin{document}
\begin{tabular}{*{10}{>{\centering\arraybackslash}m{2em}}}
  \toprule
  A & B & C & D & E & F & G & H & I & J \\
  \midrule
  \begin{tabular}{C}1\end{tabular} &
  \begin{tabular}{C}1\\2\end{tabular} &
  \begin{tabular}{C}1\\2\\3\end{tabular} &
  \begin{tabular}{C}1\\2\\3\\4\end{tabular} &
  \begin{tabular}{C}1\\2\\3\\4\\5\end{tabular} &
  \begin{tabular}{C}1\\2\\3\\4\\5\\6\end{tabular} &
  \begin{tabular}{C}1\\2\\3\\4\\5\\6\\7\end{tabular} &
  \begin{tabular}{C}1\\2\\3\\4\\5\\6\\7\\8\end{tabular} &
  \begin{tabular}{C}1\\2\\3\\4\\5\\6\\7\\8\\9\end{tabular} &
  \begin{tabular}{C}1\\2\\3\\4\\5\\6\\7\\8\\9\\10\end{tabular} \\
  \bottomrule
\end{tabular}
\end{document}​
share|improve this answer
    
I'm afraid that is not what I want - I want the third column to be evenly spaced, as is the case in the 1st and 2nd column. I want Training 1 to be halfway between Objective 2 and Objective 3, similarly Training 2 to be halfway between Objective 3 and Objective 4. I have now edited the initial question in an attempt to be more clear. –  David Duncan Aug 16 '12 at 15:12
    
I have now amended the question to try and be more clear - also realised that what I suggested in the previous comment is incorrect, the even spacing would have Training 1 in line with Objective 2, and Training 2 in line with Objective 3. Therefore for this case there is a direct work around, without the need for \multirow. However, this was just the simplest case I had in my table - and happened to also have a simple answer. –  David Duncan Aug 16 '12 at 15:26
    
@DavidDuncan: See the end of my answer for an update on this. Does it address your question? –  Werner Aug 16 '12 at 15:57
    
I'm afraid not - that method doesn't scale - this 1 / 3 / 2 is merely the simplest possible example, I want something that is a general solution for any feasible combination. Additionally, cosmetically the spacing isn't right - the spacing between Training 1 and Training 2 is smaller than the spacing above and below. –  David Duncan Aug 16 '12 at 16:32
    
I have now updated the question to include a link to an image (which due to only have a rating of 6 on Tex I cannot put the image here directly) showing a table with 10 columns, increasing in the number of elements per column. –  David Duncan Aug 16 '12 at 17:09
show 3 more comments

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.