1

I would like to create my table as shown in the picture.

I have attached the LaTeX code I have written. How to modify it, to get the same as that in the picture?

enter image description here

\begin{table}[h]
     \begin{center}
        \setlength{\tabcolsep}{0.4cm}
       \renewcommand{\arraystretch}{1}
       \begin{tabular}{|c|ccccccccccc|}\hline
        &-50& -40 &-30&-20&-10&0&10&20&30&40&50 \\ \hline
        50 &0& 0 &0&0&0&0&0&0&0&0&0 \\ 
        40 & 0 & 0 & 0& 0&0 & 0 & 0 & 0 & 0 &0 &0 \\ 
        30 & 0 & 0 & 0& 10 & 13 & 18 & 14 & 7 & 0 &0 &0\\ 
        20 &    0&  0&  14& 19 & 22 &   24  &22&    18& 12& 0  &0\\ 
        10& 0&  8&  20& 24& 27& 27& 24& 21& 12&0&0\\ 
        0&  3 & 12& 22  &25&    27& 30& 27& 24& 18 &4&0\\ 
        -10&    6&  16  &24&    27  &27&    30& 27& 24& 17& 8 &0\\ 
        -20 &0& 10& 18& 22& 27& 27& 23& 21& 12&0 &0\\ 
        -30&    0&  4&  14& 18& 22& 24& 18& 15& 13&0&0\\ 
        -40 &0& 0&  0&  0&  0&  0&  0&  0&  0 &0&0\\ 
         -50 &0& 0 &0&0&0&0&0&0&0&0&0 \\ \hline
    \end{tabular}
\end{center}
\end{table}
CarLaTeX
  • 62,716

1 Answers1

2

With some \multicolumn and \multirow commands as well as using arrows of specific size from here, you can achieve the desired result. For the bold column, I hvave used >{\bfseries}c instead of c and for the bold row, I have repeatedly sed \textbf{}. For a more automated version of bold rows in tables, see for example here . Lastly, please note that I have also replaced the center environment by the \centering command as the former adds unwanted vertical white space arount the tabular.

enter image description here

\documentclass{article}
\usepackage{geometry}

\usepackage{array}
\usepackage{multirow}
\usepackage{mathtools}

\begin{document}

\begin{table}[h]
    \centering
    \setlength{\tabcolsep}{0.4cm}
    \renewcommand{\arraystretch}{1}
    \begin{tabular}{c|>{\bfseries}c|ccccccccccc|}
      \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{5}{c}{$\xleftarrow{\makebox[5.25cm]{}}$} & x & \multicolumn{5}{c}{$\xrightarrow{\makebox[4.75cm]{}}$}\\ \cline{2-13}
        & & \textbf{-50} &  \textbf{-40} &  \textbf{-30} & \textbf{-20} & \textbf{-10} &  \textbf{0} &  \textbf{10} &  \textbf{20} &  \textbf{30} &  \textbf{40} &  \textbf{50} \\ \cline{2-13}
        \multirow{5}{*}{\rotatebox{90}{$\xrightarrow{\makebox[1.25cm]{}}$}} & 50 &0& 0 &0&0&0&0&0&0&0&0&0 \\ 
       & 40 & 0 & 0 & 0& 0&0 & 0 & 0 & 0 & 0 &0 &0 \\ 
       & 30 & 0 & 0 & 0& 10 & 13 & 18 & 14 & 7 & 0 &0 &0\\ 
       & 20 &    0&  0&  14& 19 & 22 &   24  &22&    18& 12& 0  &0\\ 
       & 10& 0&  8&  20& 24& 27& 27& 24& 21& 12&0&0\\ 
      y & 0&  3 & 12& 22  &25&    27& 30& 27& 24& 18 &4&0\\ 
      \multirow{5}{*}{\rotatebox{-90}{$\xrightarrow{\makebox[1.25cm]{}}$}}  & -10&    6&  16  &24&    27  &27&    30& 27& 24& 17& 8 &0\\ 
       & -20 &0& 10& 18& 22& 27& 27& 23& 21& 12&0 &0\\ 
       & -30&    0&  4&  14& 18& 22& 24& 18& 15& 13&0&0\\ 
       & -40 &0& 0&  0&  0&  0&  0&  0&  0&  0 &0&0\\ 
       & -50 &0& 0 &0&0&0&0&0&0&0&0&0 \\ \cline{2-13}
    \end{tabular}
\end{table}

\end{document}

Regarding the request in the comments:

\documentclass{article}
\usepackage{geometry}
\usepackage{array}
\usepackage{multirow}
\usepackage{mathtools}

\begin{document}

\begin{table}[h]
    \centering
    \setlength{\tabcolsep}{0.4cm}
    \renewcommand{\arraystretch}{1}
    \begin{tabular}{c|>{\bfseries}c|ccccccccccc|}
      \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{5}{r}{\multirow{2}{*}{$\xleftarrow{\makebox[5.25cm]{}}$}} & x &  \multicolumn{5}{l}{\multirow{2}{*}{$\xrightarrow{\makebox[4.75cm]{}}$}}\\
      \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & & & & & \multicolumn{3}{c}{in mm}\\ \cline{2-13}
        & & \textbf{-50} &  \textbf{-40} &  \textbf{-30} & \textbf{-20} & \textbf{-10} &  \textbf{0} &  \textbf{10} &  \textbf{20} &  \textbf{30} &  \textbf{40} &  \textbf{50} \\ \cline{2-13}
        \multirow{4}{*}{\rotatebox{90}{$\xrightarrow{\makebox[1.25cm]{}}$}} & 50 &0& 0 &0&0&0&0&0&0&0&0&0 \\ 
       & 40 & 0 & 0 & 0& 0&0 & 0 & 0 & 0 & 0 &0 &0 \\ 
       & 30 & 0 & 0 & 0& 10 & 13 & 18 & 14 & 7 & 0 &0 &0\\ 
       & 20 &    0&  0&  14& 19 & 22 &   24  &22&    18& 12& 0  &0\\ 
      y & 10& 0&  8&  20& 24& 27& 27& 24& 21& 12&0&0\\ 
      in mm & 0&  3 & 12& 22  &25&    27& 30& 27& 24& 18 &4&0\\ 
      \multirow{5}{*}{\rotatebox{-90}{$\xrightarrow{\makebox[1.5cm]{}}$}}  & -10&    6&  16  &24&    27  &27&    30& 27& 24& 17& 8 &0\\ 
       & -20 &0& 10& 18& 22& 27& 27& 23& 21& 12&0 &0\\ 
       & -30&    0&  4&  14& 18& 22& 24& 18& 15& 13&0&0\\ 
       & -40 &0& 0&  0&  0&  0&  0&  0&  0&  0 &0&0\\ 
       & -50 &0& 0 &0&0&0&0&0&0&0&0&0 \\ \cline{2-13}
    \end{tabular}
\end{table}

\end{document}

enter image description here

leandriis
  • 62,593
  • Hello, I try to write X in mm and the distance between the 0th column increases. If i had to write "in mm" i=on the next line. How to do it – Parnal Patni Mar 03 '19 at 16:29
  • Like one of these? https://i.stack.imgur.com/yJGbI.png – leandriis Mar 03 '19 at 16:37
  • Yes for both, X and Y – Parnal Patni Mar 03 '19 at 17:01
  • Please see my updated answer for a suggestion on how to add in mm to both x and y. – leandriis Mar 03 '19 at 17:16
  • \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & & & & & \multicolumn{3}{c}{in mm}\ \cline{2-13} I get an error for this line – Parnal Patni Mar 03 '19 at 20:29
  • It would be interesting to know which error message you recieve. Also do you get the error with the MWE from my answer or if you use the code in your actual document? – leandriis Mar 03 '19 at 20:32
  • If I use the actual code in my answer, it shows an error at "\" this symbol of the line, which I mentioned above. – Parnal Patni Mar 03 '19 at 21:01
  • \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & & &&& \multicolumn{3}{c}{in mm}&&&&\ \cline{2-13} If i use this the error is gone but the in cm position is slightly changed.. I tried to adjust &&& to left and right side , but it doesnt line exactly next to X – Parnal Patni Mar 03 '19 at 21:02