58 Comments

  1. AlBundy

    Hi,

    in the multiple columns and multiple rows examples, are you sure pictures match with code?. I think alignment of “X” is not “c”.

    • Right, I used a more complex column definition and changed the code to keep it as simple as possible. Also, the color is not reproduced by the example.

  2. Rachael

    Hi. Thanks for the help. I am having trouble with multiple multirows in a table. It doesn’t seem to recognise that the second multirow exists. Any ideas?

    • Hi Rachael,
      Here is an example with multiple multirows in a table. If this doesn’t help solving your issue, please provide a minimal example.

      Thanks, Tom

      \documentclass[11pt]{article}
      \usepackage{multirow}
      \begin{document}
      \begin{table}[ht]
      \caption{Multi-row table}
      \centering
      \begin{tabular}{ccc}
          \hline
          \multirow{2}{*}{Multirow}&X&\multirow{2}{*}{Multirow}\\
          &X&\\
          X&\multirow{2}{*}{Multirow}&\multirow{2}{*}{Multirow}\\
          X&&\\
          \hline
      \end{tabular}
      \label{tab:multirow}
      \end{table}
      \end{document}
      • ashish srivastava

        this code in not working every time a error occured “I can’t write on file mainnew.pdf .. pls reply

      • tom

        Hi Ashish,

        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.

        Hope this helps,
        Tom

  3. Renan

    Hi Tom,

    Thanks for the post. It helped me a lot.

    I wonder if it is possible to centralize the cell named “Sunday and Holiday” in the following example.

    Thanks, Renan

    \begin{table}[!htb]
    \caption{Schedule of electricity load level}
    \begin{center}
    \begin{tabular}{c|c|c|c|c}
    \hline
    \multirow{3}{12mm}{Load Level}  & \multicolumn{2}{|c|}{No daylight saving time} & \multicolumn{2}{|c}{In Daylight saving time} \\ [0.5ex] % inserts table
    %heading
     & \multirow{2}{22mm}{From Monday to Saturday}  & \multirow{2}{22mm}{Sunday and holidays} & \multirow{2}{22mm}{From Monday to Saturday} & \multirow{2}{22mm}{Sunday and holidays} \\
     & & & & \\
    \hline
    \multirow{2}{12mm}{Light} & \multirow{2}{22mm}{00:00 to 06:59} & \multirow{2}{22mm}{00:00 to 16:59 22:00 to 23:59}
     & \multirow{2}{22mm}{00:00 to 06:59} & \multirow{2}{22mm}{00:00 to 17:59 23:00 to 23:59} \\
     & & & & \\
    \multirow{2}{12mm}{Medium} & \multirow{2}{22mm}{07:00 to 17:59 21:00 to 23:59}
     & \multirow{2}{22mm}{17:00 to 21:59} & \multirow{2}{22mm}{07:00 to 18:59 22:00 to 23:59}
      & \multirow{2}{22mm}{18:00 to 22:59} \\
      & & & & \\
    \multirow{2}{12mm}{Heavy} & \multirow{2}{22mm}{18:00 to 20:59} & & \multirow{2}{22mm}{19:00 to 21:59} & \\
     & & & & \\
    \hline
    \end{tabular}
    \label{load level}
    \end{center}
    \end{table}
    • Hey Renan,

      Thanks, interesting 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.

      Best, Tom.

      \documentclass[11pt]{article}
      \usepackage{multirow}
      \usepackage{array}
      \begin{document}
      
      \begin{table}[!ht]
      \caption{Schedule of electricity load level}
      \begin{center}
      \renewcommand{\arraystretch}{1.5} % adds more space between rows
      \begin{tabular}{p{0.12\linewidth}|*{3}{p{0.20\linewidth}|}p{0.20\linewidth}}
      \hline
      \multirow{3}{\linewidth}{Load Level}  & \multicolumn{2}{c|}{No daylight saving time} & \multicolumn{2}{c}{In Daylight saving time} \\  % inserts table
      %heading
      & \multirow{2}{\linewidth}{\centering From Monday to Saturday}  & \multirow{2}{\linewidth}{\centering Sunday and holidays} & \multirow{2}{\linewidth}{\centering From Monday to Saturday} & \multirow{2}{\linewidth}{\centering Sunday and holidays} \\
      & & & & \\
      \hline
      \multirow{2}{\linewidth}{Light} & \multirow{2}{\linewidth}{00:00 to 06:59} & \multirow{2}{\linewidth}{00:00 to 16:59\hfill 22:00 to 23:59}
      & \multirow{2}{\linewidth}{00:00 to 06:59} & \multirow{2}{\linewidth}{00:00 to 17:59\hfill 23:00 to 23:59} \\
      & & & & \\
      \multirow{2}{\linewidth}{Medium} & \multirow{2}{\linewidth}{07:00 to 17:59 21:00 to 23:59}
      & \multirow{2}{\linewidth}{17:00 to 21:59} & \multirow{2}{\linewidth}{07:00 to 18:59 22:00 to 23:59}
      & \multirow{2}{\linewidth}{18:00 to 22:59} \\
      & & & & \\
      Heavy & 18:00 to 20:59 & & 19:00 to 21:59 & \\
      \hline
      \end{tabular}
      \label{load level}
      \end{center}
      \end{table}
      
      \end{document}
  4. Djomla

    Hello,
    I have one question
    Is there a option to prevent page break in multicolumn? Im using tabular

    \begin{xtabular}{|c|c|c|c|c|c|c|}
    \multicolumn{2}{l}{}\\
    \multicolumn{2}{l}{\bfseries\large Mixed Masters Walking}\\
    \hline
    \rowcolor[gray]{.9}
    1 & TEAM \\
    \hline
    2 & TEAM \\
    \hline
    \rowcolor[gray]{.9}
    3 & TEAM \\
    \hline
    4 & TEAM \
    \hline
    \rowcolor[gray]{.9}
    5 & TEAM \\
    \hline
    6 & \\
    \hline

    So I need to second multicolumn be on separate page, if it’s to big for one page.

  5. Louisa

    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.

    • tom

      Hi Louisa,

      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.

      Cheers, Tom

      • Louisa

        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.

        \begin{table}
        \centering
        \rowcolors{2}{white}{gray!20}
        \newcommand{\myrule}{\ifodd\rownum\arrayrulecolor{gray!20}\else\arrayrulecolor{white}\fi}
        \begin{tabular}{|p{3cm}| p{3cm}*{1}{p{5cm}} | }
        \hline
        \rowcolor{blue} \bfseries \textcolor{white}{My text} & \multicolumn{2}{c}{\bfseries \textcolor{white}{My multirow}}\\
        \hline
        text	& First row: & color1 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Second row: & color1 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Third row: & color1 \\
        text	& First row: & color2 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Second row: & color2 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Third row: & color2 \\
        this is a very long text which should span multiple rows	& First row: & color1 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Second row: & color1 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Third row: & color1 	\\
        \hline
        \end{tabular}
        \end{table}
        
      • tom

        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.

        \documentclass[11pt]{article}
        \usepackage{multirow}
        \usepackage[table]{xcolor}
        \begin{document}
        
        \newcommand{\specialcell}[2][c]{%
          \begin{tabular}[#1]{@{}l@{}}#2\end{tabular}}
        
        \begin{table}
        \centering
        \rowcolors{2}{white}{gray!20}
        \newcommand{\myrule}{\ifodd\rownum\arrayrulecolor{gray!20}\else\arrayrulecolor{white}\fi}
        \begin{tabular}{|m{4cm}| *{2}{p{3cm}} |}
        \hline
        \rowcolor{blue} \bfseries \textcolor{white}{My text} & \multicolumn{2}{c}{\bfseries \textcolor{white}{My multirow}}\\
        \hline
        text    & First row: & color1 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Second row: & color1 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Third row: & color1 \\
        text    & First row: & color2 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Second row: & color2 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        & Third row: & color2 \\
        this is a very long text which should span multiple rows & \specialcell{First row:\\Second row:\\Third row:} & \specialcell{color1\\color1\\color1} \\
        \hline
        \end{tabular}
        \end{table}
        
        \end{document}
      • Louisa

        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”):

        \newcommand{\specialcell}[2][c]{%
          \begin{tabular}[#1]{@{}p{3cm}@{}}#2\end{tabular}}
        

        And here is an example with longer text:

        \begin{table}
        \centering
        \rowcolors{2}{white}{gray!20}
        \newcommand{\myrule}{\ifodd\rownum\arrayrulecolor{gray!20}\else\arrayrulecolor{white}\fi}
        \begin{tabular}{|m{4cm}| *{2}{p{3cm}} |}
        \hline
        \rowcolor{blue} \bfseries \textcolor{white}{My text} & \multicolumn{2}{c}{\bfseries \textcolor{white}{My multirow}}\\
        \hline
        text & First row: & color1 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        		 & Second row: & color1 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        		 & Third row: & color1 \\
        text & First row: & color2 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        		 & Second row: & color2 \\ \myrule\cline{2-3}\arrayrulecolor{black}
        		 & Third row: & color2 \\
        this is a very long text which should span multiple rows & \specialcell{First row:\\Second row:\\Third row:} & \specialcell{I'm the explanation of the First row.\\I'm the explanation of Second row, and want to be aligned with second row.\\And I belong to Third row!} \\
        \hline
        \end{tabular}
        \end{table}
        
      • tom

        Hi Louisa,

        In that case, I’d color the rows manually as shown in the example below. Cheers, Tom.

        \documentclass[11pt]{article}
        \usepackage{multirow}
        \usepackage[table]{xcolor}
        \begin{document}
        \begin{table}
        \centering
        \begin{tabular}{|m{4cm}|*{2}{p{3cm}|}}
        \hline
        \rowcolor{blue} \bfseries \textcolor{white}{My text} & \multicolumn{2}{c}{\bfseries \textcolor{white}{My multirow}}\\
        \hline
        \rowcolor{gray!20}
        text & First row: & color1 \\
        \rowcolor{gray!20}
                & Second row: & color1 \\
        \rowcolor{gray!20}
                & Third row: & color1 \\
        text & First row: & color2 \\
                & Second row: & color2 \\
                & Third row: & color2 \\
        \rowcolor{gray!20}
        	&First row:& I'm the explanation of the First row. \\
        \rowcolor{gray!20}
        	\multirow{3}{*}{\begin{minipage}{\linewidth}this is a very long text which should span multiple rows\end{minipage}} & Second row: & I'm the explanation of Second row, and want to be aligned with second row.\\
        \rowcolor{gray!20}
        	& Third row: & And I belong to Third row!\\
        \hline
        \end{tabular}
        \end{table}
        \end{document}
  6. Anders Hovgaard

    Can anyone help with getting every second row colored in gray.. Really cant figure it out

    • tom

      Hi Anders,

      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.

      \documentclass{article}
      \usepackage[table]{xcolor}
      \usepackage{multirow} 
      \begin{document}
      \begin{table}[ht]
      \rowcolors{1}{}{gray}
      \begin{tabular}{cc}
      \hline
      Single-row&Single-row\\
      &Single-row\\
      %\rowcolor{gray} % Color all 3 multi-row rows
      &Single-row\\
      \multirow{-3}{*}{Multi-row (3)}&Single-row\\
      Single-row&Single-row\\
      \hline
      \end{tabular}
      \end{table}%
      \end{document}

      HTH,
      Tom

  7. Sofja

    Thank you for your tutorial! I wonder how can I spann the rows on the right side of the table? I would appreciate your helf a lot!

    • tom

      Hi Sofja,

      Below is an example of multirow-row spanning on the right.

      HTH, Tom

      \documentclass[border=10pt]{standalone}
      \usepackage{multirow}
      \begin{document}
      \begin{tabular}{cc}
          \hline
          X&\multirow{3}{*}{Multirow}\\
          X&\\
          X&\\
          \hline
      \end{tabular}
      \end{document}
  8. Hi Tom,
    Thanks for the post, it helped me hugely!
    Can you tell about how to put that vertical bar “|c|” in the multirow-line too?

    \begin{table}[!h]
        \selectlanguage{brazil}
        \caption{Tabela de erro para polarização C.A. (Em porcentagem), comparando-se as Tabelas \ref{TabelaCAcalculados} e \ref{TabelaCAmedidoscalculados}.}
        \label{TabelaErroCA}
        \begin{center}
            \begin{tabular}{|c|c|c|c|}
                \hline
                \multirow{2}{*}{Erro}   &$A_{V_{NL}}$   &$A_{V_{L}}$    &$A_{V_{S}}$    \\ \cline{2-4}
                                        &2,0            &2,0            &5,5            \\ \hline
            \end{tabular}
        \end{center}
    \end{table}
    • tom

      Hi Gabriel,

      Thanks for the example. In the code you provided, all vertical lines are produced. Would you mind to clarify the question, please?

      Tom

      • I am so sorry! Provided wrong example! This one here, it doesn’t show the vertical lines at the sides of the multicolumn. All others have.

        \begin{table}[!h]
                \caption{Caption}
                \label{Table1}
                \begin{tabular}{|c|c|c|c|c|}
                  \hline
                  \multicolumn{5}{c}{Title}\\\hline
                  X&X&X&X&X\\\hline
                  10,88&5,07&8,34&3,03&-3,24\\\hline
                  X&X&X&X&X\\\hline
                  12,96&4,62&2,53&2,53&0,108\\\hline
                \end{tabular}
        \end{table}
      • tom

        Hi Gabriel,

        You can add the vertical lines with the alignment parameter of the multicolumn command.

        \multicolumn{5}{|c|}{Title}\\\hline

        HTH,
        Tom

  9. Caspar

    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:

    \begin{tabular}{| C | C{3cm} | C{3cm}  | C{3cm} | C{3cm} |}   
        \hline
         \textbf{category} & \textbf{absolute donations} & \textbf{donations relative to wealth} & \textbf{donations relative to income} & \textbf{Bekkers \&  Wiepking} \\ \hline
        job & 1 & 6 & 4 & 5 \\  \hline
        wealth & rich > poor & poor > rich; exception: 7th decile; thoose who dont give have the least & rich > poor & \multirow{2}{*}{\parbox[c][/c]{3cm}{positive, but inelastic(growth in donations  low income & unclear pattern & unclear &   \\ \hline
        real estate & rich > poor & poor > rich; exception: 7th decile; thoose who dont give have the least  & rich > poor & 5\\ \hline
       social engagement & 5 & 6 & 4 & 5\\ \hline
      \end{tabular}
    • tom

      Hi Caspar,

      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.

      Thanks, Tom

      \documentclass[10pt]{article}
      \usepackage[T1]{fontenc}
      \usepackage{multirow}
      \usepackage{array}
      \newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
      \begin{document}
      \begin{tabular}{| *{4}{C{2cm}|} C{3cm} |}   
      	\hline
      	\textbf{category} & \textbf{absolute donations} & \textbf{donations relative to wealth} & \textbf{donations relative to income} & \textbf{Bekkers \&  Wiepking} \\ \hline
      	    job & 1 & 6 & 4 & 5 \\  \hline
           	social engagement & 5 & 6 & 4 &\multirow{2}{*}{\parbox{\linewidth}{positive, but inelastic growth in donations  low income}}\\ \cline{1-4}
      	social engagement & 5 & 6 & 4 & \\ \hline
      	social engagement & 5 & 6 & 4 & 5\\ \hline
      	\end{tabular}
      \end{document}
  10. Jessica

    Hello Tom

    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

    \begin{table}[htb!]
    	\small
    	\centering
    	\begin{tabular}{cccccccc}
    		\topline    
    		
    		\headcol\multicolumn{1}{c}{}&\multicolumn{4}{c}{ILW-silo}&\multicolumn{3}{c}{LLW-silo}\\ \midline
    		
    		\headcol\multicolumn{1}{c}{}&\multicolumn{1}{c}{Bituminised}&\multicolumn{3}{c}{Filter rods and metal scrap}&\multicolumn{3}{c}{\multirow{2}{*}{Maintenance waste, filter rods, metal}} \\ 
    	                \bottomline
    	\end{tabular}
    \end{table}

    So basically “scrap and solidified liquids” goes all the way to the left of the line and I need it to be on the right.

    • tom

      Hi Jessica,

      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.

      Thanks,
      Tom

      • Jessica

        Hi Tom,

        Thanks so much for getting back to me.

        Regarding the first 3 points: thank you I will do that!

        Regarding the last point: you are correct, it should be \toprule

        🙂

  11. Iza

    Hey Tom,

    i am having troubles with the multicol… actually it works just fine most of the time but in the row ‘concentration of nanoparticles’ the multicol does not seem to work and i cannot figure out why.. 🙁

    \begin{table}
    \caption{Key points of the applied samples and experimental configuration}
    \begin{tabular}{lcccc}
    \hline
    Type of Cell & \multicolumn{4}{c}{HeLa}\\
    \hline
    Type of Nanoparticles & \multicolumn{2}{c}{Cl$_2$ + FeCl$_3$ + Citrate} & \multicolumn{2}{c}{Cl$_2$ + FeCl$_3$ + Mannitol}\\
    Concentration of Nanoparticles & 2,4 \mu l  & \multicolumn{2}{c}{4,8 \mu l} & 7,2 \mu l\\
    Incubation time & \multicolumn{2}{c}{24 h} & \multicolumn{2}{c}{48 h}\\
    Position of the Magnet & \multicolumn{2}{c}{underneath} & \multicolumn{2}{c}{at the side}\\
    Time of Excitation & \multicolumn{4}{c}{1-6 minutes}\\
    Applied force & \multicolumn{4}{c}{400 N}\\
    \hline
    \end{tabular}
    \label{KeyPoints}
    \end{table}
  12. Carlos Santos

    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?

    • tom

      Hi Carlos,

      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.

      Hope this helps.

      Best wishes, Tom

      • Carlos Santos

        Hello again Tom.

        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!

        Best regards,
        Carlos

  13. Neeraj Sharman

    Hii Tom
    I am facing problem in this code segment :

    \begin{table}[ht]
    \caption{Multi-column table}
    \begin{center}
    \begin{tabular}{cc}
        \hline
        \multicolumn{3}{c}{Multi-column}\\
        X&X&X\\
        \hline
    \end{tabular}
    \end{center}
    \label{tab:multicol}
    \end{table}

    Here if at the place of 3 we use 2 it doesn’t make any issue but with 3 table alignment get changed.
    Thanks for your great tutorial

    • tom

      Hi Neeraj,

      Your code works for me if I add an extra column (ccc instead of cc) to tabular. Here is the complete code:

      \documentclass[11pt]{article}
      \usepackage{multicol}
      \begin{document}
      \begin{table}[ht]
      \caption{Multi-column table}
      \begin{center}
      \begin{tabular}{ccc}
          \hline
          \multicolumn{3}{c}{Multi-column}\\
          X&X&X\\
          \hline
      \end{tabular}
      \end{center}
      \label{tab:multicol}
      \end{table}
      \end{document}
  14. Bexultan

    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

    • tom

      Hi Bexultan,

      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.

      \documentclass[11pt]{article}
      \usepackage{multirow}
      \begin{document}
      \begin{table}
      \begin{tabular}{llll}
      \hline
      abc & \multirow{2}{*}{abc} & abc & abc \\ \cline{1-1}\cline{3-4}
      abc & & abc & abc\\
      \hline
      \end{tabular}
      \end{table}
      \end{document}
  15. Nadirah

    Hi Tom

    I would like to draw a table with 2 rows with 5 columns. In the second row, the second column till column number 5, it has 3 more subcolumns in each. I do not know how to draw that in table.

  16. Nadirah

    This is what I have been trying to do

    \documentclass[11pt]{article}
    \usepackage{graphicx}
    \begin{document}
    \begin{table}
    \centering
    renewcommand{\arraystretch}{1.2}
    \small
    \scalebox{0.7}
    \begin{tabular}{|c|c|c|c|c|}
    \hline
    \multicolumn{9}{c}{Module P: Power Amplifier& Module U: Up Converter & Module M: Modulator & Module T:Terrestrial Equipment}
    \hline
    &Module P: Power Amplifier & Module U: Up Converter & Module M: Modulator & Module T: Terrestrial Equipment \\
    \hline
    The column in the matrix& $1$ & $2$ & $3$ & $4$ \\
    \end{tabular}
    \end{table}
    \end{document}

    It does not want to work

    • tom

      Hi Nadirah,

      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}{...}).

      Hope this helps,
      Tom

      \documentclass[11pt]{article}
      \usepackage{array}
      
      \newcommand\subcolumn[3]{%
      \begin{tabular}{ccc}
      #1&#2&#3\\
      \end{tabular}}
      
      \begin{document}
      \begin{table}[ht]
      \caption{default}
      \begin{center}
      \begin{tabular}{|*{5}{c|}}
      \hline
      row 1&a&b&c&d\\
      row 2&\subcolumn{1}{2}{3}&\subcolumn{4}{5}{6}&\subcolumn{7}{8}{9}&\subcolumn{1}{2}{3}\\
      \hline
      \end{tabular}
      \end{center}
      \label{default}
      \end{table}
      \end{document}
  17. Nadirah

    Hi Tom

    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:

    \newcommand\subcolumn[3]{%
    \begin{tabular}{c|c|c}
    #1&#2&#3\\
    \end{tabular}}
    
    \begin{table}
    \caption {Representation of the matrix}
    \begin{center}
    \begin{tabular}{|*{5}{c|}}
    \hline
    &Module P: Power Amplifier& Module U: Up Converter & Module M: Modulator & Module T:Terrestrial Equipment \\
    \hline
    The column in the matrix&\subcolumn {1}{2}{3} & \subcolumn{4}{5}{6}&\subcolumn{7}{8}{9}&\subcolumn{10}{11}{12}\\
    \hline
    
    \end{tabular}
    \end{center}
    \label{Representation of the matrix}
    \end{table}

    When I mean smaller- means like could I make this sentence “The column in the matrix”
    Become like this:
    “The column
    in the matrix”

    How do I write that in the table?

    Thanks Tom.

    • tom

      Hi Nadirah,

      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.

      \begin{tabular}{|*{5}{>{\raggedright\arraybackslash}m{0.2\linewidth}|}}

      Best, Tom.

  18. Nadirah

    Hi Tom

    Thanks alot for your input.I have modified my code and this is how it looks like:

    […]Removed code by Tom[…]

    I find writing a table is the most difficult part for me in Latex, since I am beginner to Latex.

    My next question is, how do I want to draw a full vertical line for the subcolumn? I have included the vertical line in line 2 in the lLatex code, but cant seem to achieve it.

    • tom

      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.

      Cheers, Tom

      \documentclass[11pt]{article}
      \usepackage{array,multicol}
      \begin{document}
      \begin{table}
      \begin{small}
      \caption {Representation of the matrix}
      \setlength\columnsep{2pt}
      \begin{center}
      %\begin{tabular}{|*{5}{c|}}
      \begin{tabular}{|>{\raggedright}m{0.15\linewidth}|*{12}{>{\raggedright\arraybackslash}m{0.025\linewidth}|}}
      \hline
      &\multicolumn{3}{>{\raggedright}m{0.14\linewidth}|}{Module P: Power Amplifier}& \multicolumn{3}{>{\raggedright}m{0.14\linewidth}|}{Module U: Up Converter} & \multicolumn{3}{>{\raggedright}m{0.14\linewidth}|}{Module M: Modulator }& \multicolumn{3}{>{\raggedright}m{0.14\linewidth}|}{Module T: Terrestrial Equipment} \\
      \hline
      The column in the matrix&1&2&3 & 4&5&6&7&8&9&10&11&12\\
      \hline
      \end{tabular}
      \end{center}
      \label{Table1}
      \end{small}
      \end{table}
      \end{document}
  19. Hello Tom,

    Here is my code. I want to fix the width of table. But I fail to do this. Can you help me.

    \setlength{\tabcolsep}{1pt}

    \begin{tabular}{l*{12}{c}}
    \hline\hline

    \multicolumn{12}{l}{\hspace{8cm}\textbf{Panel B: Return and Profitability Descriptive Statistics}}\\

    \hline
    &\multicolumn{1}{c}{Non\_Dur}&\multicolumn{1}{c}{ Durable}&\multicolumn{1}{c}{Manufacturing}&\multicolumn{1}{c}{Oil \& Gas }&\multicolumn{1}{c}{Chemicals}&\multicolumn{1}{c}{Bus Eqp}&\multicolumn{1}{c}{Phone \& TV}&\multicolumn{1}{c}{Utilities}&\multicolumn{1}{c}{Whole\_Ret}&\multicolumn{1}{c}{Healthcare}&\multicolumn{1}{c}{Finance}&\multicolumn{1}{c}{Other}\\
    \hline

    ROE & 0.077& 0.057& 0.034& 0.031& 0.026& -0.069& -0.927& 1.096& 0.094& -0.281& 0.450& 0.001 \\
    & 0.119& -0.111& 0.126& -0.755& 0.117& -0.050& 0.102& 0.116& 0.059& 0.067& 0.100& -0.000 \\
    & -1.067& 6.948& -2.569& 7.551& -1.519& -0.240& -0.930& 3.766& 0.998& -8.318& 4.282& 0.053 \\
    [0.5em]
    \hline
    CF & 0.061& 0.051& 0.060& 0.059& 0.044& 0.009& 0.029& 0.029& 0.062& -0.140& 0.003& 0.038 \\
    & 0.062& 0.069& 0.058& 0.076& 0.058& 0.042& 0.054& 0.037& 0.052& -0.035& 0.021& 0.002 \\
    & -1.044& -7.180& 2.385& -6.253& -6.694& -23.859& -8.631& -6.328& 11.392& -37.083& -6.982& 7.542 \\
    [0.5em]
    \hline
    EBIT\_MAR & 0.043& -0.016& -0.066& -0.639& -0.443& -1.742& -1.598& 0.017& -0.012& -17.730& 0.018& -1.102 \\
    & 0.075& 0.050& -0.050& -5.519& 0.034& -0.254& -0.163& 0.185& 0.020& -8.070& 0.095& -0.137 \\
    & -2.244& -6.142& -0.519& 10.781& -4.773& -5.256& -1.514& -11.954& -2.024& -5.218& -0.509& -8.969 \\
    [0.5em]
    \hline
    GM & 0.340& 0.262& 0.217& 0.152& 0.146& -0.847& -0.696& 0.221& 0.277& -14.841& 0.350& -0.587 \\
    & 0.323& 0.285& 0.176& 0.042& 0.361& 0.285& 0.234& 0.279& 0.237& -7.230& 0.276& 0.165 \\
    & 2.168& -2.748& 1.644& 0.820& -5.184& -4.208& -1.029& -9.724& 5.978& -4.262& 0.583& -7.792 \\
    [0.5em]
    \hline
    TAX & 0.339& 0.309& 0.221& 0.264& 0.278& 0.141& 0.263& 0.392& 0.564& 0.249& 0.246& 0.138 \\
    & 0.300& 0.131& 0.369& 0.276& 0.344& 0.162& 0.018& 0.329& 0.306& 0.207& 0.204& 0.216 \\
    & 1.820& 5.471& -3.440& -0.289& -3.618& -1.018& 3.346& 2.985& 1.382& 0.862& 0.986& -1.205 \\
    [0.5em]
    \hline
    RET12\_L & 1.211& 1.223& 1.212& 1.240& 1.215& 1.320& 1.261& 1.166& 1.239& 1.322& 1.144& 1.232 \\
    & 1.217& 1.241& 1.208& 1.257& 1.176& 1.312& 1.293& 1.151& 1.229& 1.318& 1.212& 1.208 \\
    & -1.006& -2.006& 1.176& -2.261& 5.777& 1.258& -2.815& 6.934& 1.854& 0.631& -23.983& 6.033 \\
    \hline\hline
    \end{tabular}

    • tom

      Hi there,

      Please don’t just ask me to fix your table. I’d appreciate if you explained the problem in a little more details. The code is below. I suggest to make it a full-page landscape table.

      Best,
      Tom

      \documentclass[11pt,draft]{article}
      \usepackage{multirow,lscape,array}
      \begin{document}
      
      \begin{landscape}
      \begin{table}
      \begin{small}
      \setlength{\tabcolsep}{0pt}
      \setlength\extrarowheight{5pt}
      \centering
      \begin{tabular}{>{\raggedright}m{0.06\linewidth}*{12}{>{\centering\arraybackslash}m{0.078\linewidth}}}
      \hline\hline
      &\multicolumn{12}{c}{\textbf{Panel B: Return and Profitability Descriptive Statistics}}\\
      \hline
      &Non Durable&Durable&Manu-facturing&Oil \& Gas&Chemi-cals&Bus Eqp&Phone \& TV&Utilities&Whole Ret&Health-care&Finance&Other\\[5pt]
      \hline
      \multirow{3}{*}{ROE}& 0.077& 0.057& 0.034& 0.031& 0.026& -0.069& -0.927& 1.096& 0.094& -0.281& 0.450& 0.001 \\
      & 0.119& -0.111& 0.126& -0.755& 0.117& -0.050& 0.102& 0.116& 0.059& 0.067& 0.100& -0.000 \\
      & -1.067& 6.948& -2.569& 7.551& -1.519& -0.240& -0.930& 3.766& 0.998& -8.318& 4.282& 0.053 \\[5pt]
      \hline
      \multirow{3}{*}{CF} & 0.061& 0.051& 0.060& 0.059& 0.044& 0.009& 0.029& 0.029& 0.062& -0.140& 0.003& 0.038 \\
      & 0.062& 0.069& 0.058& 0.076& 0.058& 0.042& 0.054& 0.037& 0.052& -0.035& 0.021& 0.002 \\
      & -1.044& -7.180& 2.385& -6.253& -6.694& -23.859& -8.631& -6.328& 11.392& -37.083& -6.982& 7.542 \\[5pt]
      \hline
      \multirow{3}{*}{\begin{minipage}{\linewidth}EBIT MAR\end{minipage}} & 0.043& -0.016& -0.066& -0.639& -0.443& -1.742& -1.598& 0.017& -0.012& -17.730& 0.018& -1.102 \\
      & 0.075& 0.050& -0.050& -5.519& 0.034& -0.254& -0.163& 0.185& 0.020& -8.070& 0.095& -0.137 \\
      & -2.244& -6.142& -0.519& 10.781& -4.773& -5.256& -1.514& -11.954& -2.024& -5.218& -0.509& -8.969 \\[5pt]
      
      \hline
      \multirow{3}{*}{GM} & 0.340& 0.262& 0.217& 0.152& 0.146& -0.847& -0.696& 0.221& 0.277& -14.841& 0.350& -0.587 \\
      & 0.323& 0.285& 0.176& 0.042& 0.361& 0.285& 0.234& 0.279& 0.237& -7.230& 0.276& 0.165 \\
      & 2.168& -2.748& 1.644& 0.820& -5.184& -4.208& -1.029& -9.724& 5.978& -4.262& 0.583& -7.792 \\[5pt]
      \hline
      \multirow{3}{*}{TAX} & 0.339& 0.309& 0.221& 0.264& 0.278& 0.141& 0.263& 0.392& 0.564& 0.249& 0.246& 0.138 \\
      & 0.300& 0.131& 0.369& 0.276& 0.344& 0.162& 0.018& 0.329& 0.306& 0.207& 0.204& 0.216 \\
      & 1.820& 5.471& -3.440& -0.289& -3.618& -1.018& 3.346& 2.985& 1.382& 0.862& 0.986& -1.205 \\[5pt]
      \hline
      \multirow{3}{*}{\begin{minipage}{\linewidth}RET12 L\end{minipage}} & 1.211& 1.223& 1.212& 1.240& 1.215& 1.320& 1.261& 1.166& 1.239& 1.322& 1.144& 1.232 \\
      & 1.217& 1.241& 1.208& 1.257& 1.176& 1.312& 1.293& 1.151& 1.229& 1.318& 1.212& 1.208 \\
      & -1.006& -2.006& 1.176& -2.261& 5.777& 1.258& -2.815& 6.934& 1.854& 0.631& -23.983& 6.033 \\[5pt]
      \hline\hline
      \end{tabular}
      \end{small}
      \end{table}
      \end{landscape}
      \end{document}

Leave a Reply