75

I want to create a table like this using Latex

      ---------------------------------
      |               sets            |
      ---------------------------------
      | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---------------------------------------
| I1  | * |   | * | * |   | * |   | * |
---------------------------------------

Here is what I wrote

\begin{table}
\caption{Multiprogram sets}
\label{multiprogram}
 \begin{tabular}{| c | c | c | c | c | c | c | c | c |}
  \cline{3-9}
  \multicolumn{8}{}{}    &   Sets  \\
  \hline
  \multicolumn{1}{}{}   & 1 & 2 &  3 & 4 & 5 &  6 & 7  & 8 \\
  \hline
   astar         &  & * &  & * &  &  & * &   \\
  \hline
 \end{tabular}
\end{table}

But it doesn't work! The output look like

          -----------------------------
                                 sets |
---------------------------------------
        1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---------------------------------------
| I1  | * |   | * | * |   | * |   | * |
---------------------------------------

Any way to fix that?

  • 11
    It should be \multicolumn{1}{c|}{} & \multicolumn{8}{c|}{Sets} \\ – egreg Sep 6 '13 at 11:13
103

Code:

\documentclass{article}
\begin{document}
    \begin{table}
        \centering
        \caption{Multiprogram sets}
        \label{multiprogram}
        \begin{tabular}{c|c|c|c|c|c|c|c|c|}
            \cline{2-9}
             & \multicolumn{8}{|c|}{Sets}\\
            \cline{2-9}
             & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
            \hline
            \multicolumn{1}{|c|}{astar} & & * &  & * &  &  & * &\\
            \hline
        \end{tabular}
    \end{table}
\end{document}

And the result:

enter image description here

| improve this answer | |
1

With {NiceTabular} of nicematrix, you only have to use the key hvlines-except-corners and all the expected rules will be drawn.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{table}
\centering
\caption{Multiprogram sets}
\label{multiprogram}
\begin{NiceTabular}{*{9}{C}}[hvlines-except-corners]
      & \Block{1-8}{Sets}\\
      & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8\\
astar & & * &  & * &  &  & * & ~ \\
\end{NiceTabular}
\end{table}
\end{document}

Ouput of the above code

| improve this answer | |
  • In this answer, since version 5.0 of nicematrix one must write *{9}{c} instead of *{9}{C} in the preamble of {NiceTabular} (but there is an option for backward compatibility). – F. Pantigny Jul 18 at 20:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.