1

I can not see what i wrong with my table code

\begin{tabular}{l*{11}{c}r}
  & A & B & C & D & E & F & G & H\\
\hline
A & 0_A & 4_A & \infty & 5_A & 6_A & \infty & \infty & \infty\\
B & & 4_A & 14_B & 5_A & 6_A & \infty & \infty & \infty\\
D & & & 10_D & 5_A & 6_A & 12_D & 9_D & \infty\\
E & & & 10_D & & 6_A & 8_E & 7_E & \infty\\
G & & & 10_D & & & 8_E & 7_E & 12_G\\
F & & & 9_F & & & 8_E & & 12_G\\
C & & & 9_F & & & & & 11_C\\
H & & & & & & & & 11_C
\end{tabular}
  • 5
    tabular entries are in text but you have math expressions, you want array not tabular. – David Carlisle Feb 27 '17 at 14:19
  • Thanks!, the table works fine in tabular with the first 3 rows, – asd123321dsa Feb 27 '17 at 14:22
  • 5
    Ehm, no, it doesn't. Exactly what error do you get? Replace tabular with array as @DavidCarlisle suggested, and place the whole thing in math mode (add \[ before \begin{array}, and \] after \end{array}) if you haven't already. – Torbjørn T. Feb 27 '17 at 14:33
2

Your given code results in several warnings that an $ is missing. So your given code can not work fine.

You have two possibilities to solve the issue:

  1. Add $ arround the mathematical parts in the table, like $\infty$ and $0_A$ etc.
  2. Use environment array, which has to be used in mathematical mode, started with \[, ended with \]. To keep the letters in the first row and column upright, I used command \mathrm{A} etc.

The following MWE shows both solutions:

\documentclass{article}


\begin{document}
First possibility:

\begin{tabular}{l*{7}{c}r}
  & A     & B     & C        & D     & E     & F        & G        & H\\
\hline
A & $0_A$ & $4_A$ & $\infty$ & $5_A$ & $6_A$ & $\infty$ & $\infty$ & $\infty$\\
B &       & $4_A$ & $14_B$   & $5_A$ & $6_A$ & $\infty$ & $\infty$ & $\infty$\\
D &       &       & $10_D$   & $5_A$ & $6_A$ & $12_D$   & $9_D$    & $\infty$\\
E &       &       & $10_D$   &       & $6_A$ & $8_E$    & $7_E$    & $\infty$\\
G &       &       & $10_D$   &       &       & $8_E$    & $7_E$    & $12_G$\\
F &       &       & $9_F$    &       &       & $8_E$    &          & $12_G$\\
C &       &       & $9_F$    &       &       &          &          & $11_C$\\
H &       &       &          &       &       &          &          & $11_C$
\end{tabular}

Second possibility:

\[
\begin{array}{l*{7}{c}r}
           & \mathrm{A} 
                 & \mathrm{B} 
                       & \mathrm{C} 
                                & \mathrm{D} 
                                      & \mathrm{E} 
                                            & \mathrm{F} 
                                                     & \mathrm{G} 
                                                              & \mathrm{H}\\
\hline
\mathrm{A} & 0_A & 4_A & \infty & 5_A & 6_A & \infty & \infty & \infty\\
\mathrm{B} &     & 4_A & 14_B   & 5_A & 6_A & \infty & \infty & \infty\\
\mathrm{D} &     &     & 10_D   & 5_A & 6_A & 12_D   & 9_D    & \infty\\
\mathrm{E} &     &     & 10_D   &     & 6_A & 8_E    & 7_E    & \infty\\
\mathrm{G} &     &     & 10_D   &     &     & 8_E    & 7_E    & 12_G\\
\mathrm{F} &     &     & 9_F    &     &     & 8_E    &        & 12_G\\
\mathrm{C} &     &     & 9_F    &     &     &        &        & 11_C\\
\mathrm{H} &     &     &        &     &     &        &        & 11_C
\end{array}
\]
\end{document}

resulting in the following pdf page:

first page

| improve this answer | |
  • This is a good answer, but since all columns which have mathematical parts to them have mathematical parts in every row, you could just go ahead and use the array package and >{$}c<{$} as the column specifier. That would save you have to add $ ... $ around every entry in a column – Au101 Feb 27 '17 at 21:34
  • If you want to keep the letters in the first row upright, you could of course go ahead and use \mathrm{A}, \mathrm{B} etc. or equivalent. I think it would be easier to correct the first row than all other rows – Au101 Feb 27 '17 at 21:35
  • 1
    You don't need the array package for the array environment, try e.g. \documentclass{article}\begin{document}$\begin{array}{c}a\end{array}$\end{document}. – Torbjørn T. Feb 27 '17 at 21:51

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.