4

How do I make a table using \begin{table*} in LaTeX?

The table I am trying to create is slightly complicated, and it should look like this:

Enter image description here

Sorry for the crooked lines of the image.

So far, I have been only able to make something simple:

\begin{table*}[t]
    \centering

\begin{tabular}{ *1c | *3c | *3c | *2c | }

        & & & & & & & & & & & & \\

% Keep adding as many numbers of rows, etc.

\end{tabular}
\end{table}

With this code, I have the following columns - Name, Text 1, Text 2, Text 3, Text 4, Text 5, Text 6, Text 7, and Text 8. And I can add as many rows as I want across the table.

I do not have the Category 1, Category 2 and Category 3 pat on the left and top side of the image.

1
4

Here is a starting point. The spacing can and should be adjusted, but this makes only sense once you have filled the table.

enter image description here

\documentclass{article}
\usepackage{rotating}
\newcommand\sw[1]{\begin{sideways}#1\end{sideways}}
\usepackage{multirow}
\begin{document}
\begin{tabular}{r|l|*8{c|}}
  \multicolumn{2}{c|}{}
    & \multicolumn{3}{c|}{Category 1}
          & \multicolumn{3}{c|}{Category 2}
                & \multicolumn{2}{c|}{Category 3}
\\\cline{3-10}
  & Name
    & \sw{Text1}
      & \sw{Text2}
        & \sw{Text3}
          & \sw{Text4}
            & \sw{Text5}
              & \sw{Text6}
                & \sw{Text7}
                  & \sw{Text8}
\\\hline
  \multirow{4}{*}{\sw{\small Category 1}}
  & & & & & & & & &
\\\cline{2-10}
  & & & & & & & & &
\\\cline{2-10}
  & & & & & & & & &
\\\cline{2-10}
  & & & & & & & & &
\\\hline
  \multirow{4}{*}{\sw{\small Category 2}}
  & & & & & & & & &
\\\cline{2-10}
  & & & & & & & & &
\\\cline{2-10}
  & & & & & & & & &
\\\cline{2-10}
  & & & & & & & & &
\\\hline
\end{tabular}

\end{document}

Edit: How to increase the number of columns in Category 3 from 2 to 6, as asked in the comments:

  • Change the line starting the table to

    \begin{tabular}{r|l|*{12}{c|}}
    
  • Change the \multicolumn for the headline to

    \multicolumn{6}{c|}{Category 3}
    
  • Change the \cline commands to \cline{3-14} and \cline{2-14}, respectively.

  • You need to add columns in all rows, even if they remain empty, to have vertical lines. This means adding

                & \sw{Text9}
                  & \sw{Text10}
                    & \sw{Text11}
                      & \sw{Text12}
    

for the column headings and extending the other lines to

  & & & & & & & & & & & & &
5
  • I am still trying to understand this. Could you please give a tip on how to increase the number of columns from 2 to 6 in category 3 ( i.e. I have - Text 7,8,9,10,11,12) Also how do I adjust the spacing ?/ – user128406 Mar 23 '17 at 10:34
  • 2
    See the edit to my answer. You should definitely read some tutorial on how tables work in LaTeX, otherwise you have to ask with every change you want to make. Regarding spacing, postpone it until you are finished with the table; then ask again if you don't like something in particular. – gernot Mar 23 '17 at 10:51
  • So I only have one spacing problem. How do I make this fine? It looks like this - drive.google.com/open?id=0B6unL1yNveR6eGlNUXZjaUdNVzA Yes, I went through the documentation and will work on tables. – user128406 Mar 23 '17 at 19:46
  • Basically, the text of category 1 and category 2 are colliding on the left side of the table and the sixth column is a bit wider by default. – user128406 Mar 23 '17 at 19:48
  • I figured it out. I was not using the correct number on the multirow option, but the sixth column is still wider. – user128406 Mar 23 '17 at 20:10
6

You might prefer to use booktabs.

The output of the following code

\documentclass{standalone}
\usepackage{booktabs}
\usepackage{rotating}
\newcommand\sw[1]{\small\begin{sideways}#1 \end{sideways}}
\usepackage{multirow}
\begin{document}
\def\arraystretch{1.25}
\begin{tabular}{rl*8{c}}
\toprule
  \multicolumn{2}{c}{}
    & \multicolumn{3}{c}{Category 1}
          & \multicolumn{3}{c}{Category 2}
                & \multicolumn{2}{c}{Category 3}
\\ 
  & Name
    & \sw{Text1}
      & \sw{Text2}
       & \sw{Text3}
          & \sw{Text4}
            & \sw{Text5}
              & \sw{Text6}
                & \sw{Text7}
                  & \sw{Text8}
\\ \midrule
  \multirow{4}{*}{\sw{Category 1}}
  & a & A & & & & & & &
\\
  & b & B & & & & & & &
\\
  & c & C & & & & & & &
\\
  & d & D & & & & & & &
\\ 
  \multirow{4}{*}{\sw{Category 2}}
  & a & A & & & & & & &
\\
  & b & B & & & & & & &
\\
  & c & C & & & & & & &
\\
  & d & D & & & & & & &
\\ \bottomrule
\end{tabular}
\end{document}
3

You can use \rotatebox{angle}{text} to rotate text (requires the rotating package).

You can use \multicolumn{num_cols}{alignment}{contents} to create cells spanning over several columns.

You can use \cline{from-to} for horizontal rules which do not span all columns.

You can use \multirow{num_rows}{width}{contents} to create cells spanning over several rows (requires the multirow package).

The argument of the tabular *{11}{c|} is a shortcut for eleven times the c|, allowed by the array package.

\documentclass{article}
\usepackage{array}
\usepackage{rotating}% https://en.wikibooks.org/wiki/LaTeX/Rotations
\usepackage{multirow}% https://tex.stackexchange.com/a/73285/120953

\newcommand{\cat}[1]{#1}
\newcommand{\thead}[1]{#1}
\newcommand{\catver}[1]{\rotatebox{90}{\cat{#1}}}
\newcommand{\theadver}[1]{\rotatebox{90}{\thead{#1}\hspace{.7em}}}
\begin{document}
\begin{tabular}{*{11}{c|}}
\multicolumn{2}{l|}{}
& \multicolumn{3}{l|}{\cat{Category~1}}
& \multicolumn{3}{l|}{\cat{Category~2}}
& \multicolumn{3}{l|}{\cat{Category~3}}
% https://tex.stackexchange.com/a/8555/120953
\\\cline{3-11}
& \thead{Name}
& \theadver{Text~1}
& \theadver{Text~2}
& \theadver{Text~3}
& \theadver{Text~4}
& \theadver{Text~5}
& \theadver{Text~6}
& \theadver{Text~7}
& \theadver{Text~8}
& \theadver{Text~9}
\\\hline
\multirow{5}{*}{\catver{Category~1}} &&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\hline
\multirow{5}{*}{\catver{Category~2}} &&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\hline
\multirow{5}{*}{\catver{Category~3}} &&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\cline{2-11}
&&&&&&&&&&\\\hline
\end{tabular}
\end{document}

Furthermore you might be interested in this question regarding vertically centering the contents of a multirow cell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy