The examples provided are very basic. Drop me a comment below in case you are having problems with a more complex table. Also, the color is just for illustration purposes and for simplicity reasons not part of the minimal working examples above. See here for how to color table columns or rows.

Partial horizontal line

Use \cline{columns} for a horizontal line spanning one or several table columns.

Thanks for your question. I don’t think there is a problem with the code. The error sounds like there is another problem, i.e. the file cannot be replaced. Perhaps you opened mainnew.pdf with another program which locks the file. See here for a similar question.

I assume you were asking about centering horizontally. You can achieve it by placing \centering in front of the text within \multirow.

I also took the liberty to clean up your table a bit. The main change is to define column width relative to \linewidth in order to optimally make use of space using p{\linewidth}. Let me know if you have questions.

Do you know if it’s possible to combine multirows with alternating rowcolors?
I want all the rows within one multirow to be the same color, but the “main” rows to change color every second row.
When just specifying \rowcolors{2}{white}{grey}, the rows within one multirow will also alternate colors, which I don’t want. And preferably I don’t want the multirows to have visible lines between them.
Found something similar here, but with multicolumns:http://tex.stackexchange.com/questions/40880/multicolumn-overrules-rowcolors.

Interesting question, thanks! In the example on tex.SX, usage of \cline doesn’t change the color for the subsequent row. You might want to try that instead of \multirow. To make the small lines between rows with the same color disappear, give \cline the same color:

\arrayrulecolor{gray!20}\cline{1-6}\arrayrulecolor{black}

If this doesn’t answer your question, please provide a minimal working example.

Thank you for looking into this issue. Your comments helped me one step in the right direction: I’ve managed to hide the cline by coloring it the rowcolor.
Here is a stripped example of my table, which kind of works.
As you can see there are still some issues:
1: The right vertical table border is not shown (is it affected by the cline-color perhaps?)
2: The “very long text” in my third “main” row is put within one cell (which I understand, due to multirow not being used). However, I would like it to span over the next three rows AND keep its color.

And regarding the tabular column alignment:

\begin{tabular}{|p{3cm}| p{3cm}*{1}{p{5cm}} | }

Could you please explain what the p{3cm}*{1} part means (the star (*) symbol). I stole that from the example on tex.SX, but can’t really figure out how it works.

Thanks for the example. You might have to use another trick for the last set of rows. Try the modified example below. I cannot reproduce your issue 1, the right border appears properly.

Concerning your ‘star’ question: The star belongs to the column definition on the right. You can define column-repetitions this way and save some typing especially for more complex columns. Say you have 5 left-aligned columns, so instead of lllll you could use *{5}{l} . In your example, it doesn’t make sense, because you only have one column :-). See here for some more information.

Thank you! Works perfectly for the provided example. However, as the example was a bit stripped, it’s still an issue: The text which I provided as “color1” in my example is actually a little longer in my real table (so it forces some line breaks in the cell, due to the “p” horizontal alignment). By using \specialcell, the texts in the two “specialcell” columns, are not properly aligned, as they would have been using multirow.

I modified the \specialcell command slightly (to use “p” instead of “l”):

Thanks for getting in touch. I removed your table, it was quite bulky. Here is an example of how to color every alternate row in a table. The problem in your case will be that you are using \multirow. These can be coloured with either this trick and/or manually.

Hello Tom,
thank you very much for this very helpfull blog!
I’ve got a problem with multirow which i’m unable to solve. Any help would be much appreciated.
The text in the multirow is not centerd but goes over the lower cell-boundary:

Thanks for your question. Next time, please provide a complete minimal example. Otherwise, you risk that I won’t be able to help because I can’t reproduce the problem. For example the column-type C is not defined by default. I assume you copied the style from here. Hope you can understand.

Anyway, below is an example that works. If this doesn’t solve your problem, please provide a minimal working example.

I am a LaTeX idiot so I’m really struggling. I’m trying to recreate your example “multiple rows and columns”. If I do it as you did, the text carries over to the next line, but the very start of the next line. It does not carry on below the line I want it to in the last column

From the example, I’m having a hard time to see how you’d like to structure your table. Here are a few suggestions that may be useful:

You don’t need to specify \multicol{1}{}{}, for single-column cells just add the content.

It seems you added an extra column to set the row color. Use \headcol{}Cell-text...&... instead

You can specify a fixed column width, globally and in multicolumn, using for example m{0.2\linewidth} instead of c This is documented in the array package. I got the impression you used \multicolumn to add extra column space.

I wasn’t able to find \topline, \midline, \bottomline. Did you define these commands or should they rather be \toprule, etc. as defined in booktabs?

If you need more help, please provide a minimal working example, which includes a preamble and 1-2 lines of table content.

Hello Tom. Thanks for your helpful blog. I have a question about this multicolumn and multirow problem. What about if I want to do this not for header row but within some data cells of my csv imported table? Is this possible?

That’s an interesting question. Depending on the package you use to import your CSV file, it may or may not be possible. My suggestion would be to use an online service such as this to convert your CSV file to a LaTeX table.

Thanks for your answer. In fact, yesterday I decided to try the excel add-in excel2latex and inputed the resulting file in my .tex project. With some inner code adjustments I’m being able to do several things I was intending but not achieving before… Like multi column/row.

Your LaTeX Table Generator suggestion looks much alike what I’m doing with the mentioned converted file and it seems a very interesting option. Thank you very much!

Hey there. Such an interesting helpful blog. There is a question. I have a table; the eshould be multiple in second column, but the first one is single ones. Then 3-4 columns are single too.
Like:
\begin (table)
Xxx & multirow (2)(*)(Yyy) & pop & poop \\ \cline (0-1)(3-4)
Qqq & & you & ttt \glide
End
Don’t pay attention to grammar. I’m texting from phone

See code below. Next time, please read the article first. Then, provide a minimal working example and try to formulate a problem or a question. With that, I’m happy to help. If you just ask me to write code for you, I may not reply.

My suggestion would be to insert a tabular environment in each cell with three columns. Alternatively, you can also use the multicol package as in your example. But you have to be careful to use the same number of columns in each row. In the example, you define a table with 5 columns (\begin{tabular}{|c|c|c|c|c|}), but the first row occupies 9 columns (\multicolumn{9}{c}{...}).

You re brilliant, thanks so much. I have modified the code according to your suggestion, it is working perfectly now. But I have another problem that is, I would want my table to be smaller. The one that I have now is taking the space of my A4. Here is my modified code:

One possibility to make it smaller is to reduce the font size (e.g. with \begin{small}…\end{small}). But what you want is to define fixed width columns. This is defined in the array package. Please see the documentation for more details. Below is a quick fix that gives every column the same width (0.2\linewidth). This still slightly reaches into the margin. You can define a different width for every column so that it fits nicely.

In this case, I think it makes more sense to do it the hard way and write everything out (see below). If you have several rows of table content, it might be a good idea to have a full-page table on a landscape page. This way, there is more horizontal space. You might find my short post on landscape useful.

Thank you for this very succinct guide. I am having problems implementing any multicolumns in my document (part of a thesis) . My document compiles without the table. I copied in your first example and i get an error:

If I comment out the row with the multicolum then it compiles. I have looked everywhere online and while I see some results saying that if the contents are math only commands then this error shows up but obviously that’s not the case here.

I’m hoping you have seen something like this before. The thesis does have a custom style file so I’m worried that the source of this problem lies in there.

Obviously I’m trying to put a more interesting table in but this is currently my minimal case reproducing the problem.