0

I've written the below code with the quote from this post.

\documentclass[border=0.1cm]{article}

\usepackage{diagbox} \usepackage{makecell}

\begin{document}

  \begin{table}\centering\setlength\tabcolsep{3.5pt}\renewcommand\arraystretch{1.25}
      \noindent\makebox[\textwidth]{%
        \begin{tabular}{|l|*{3}{c|}}
          \hline
          \diagbox[width=\dimexpr \textwidth/8+2\tabcolsep\relax, height=1cm,width=3cm]{ row  }{column }
         & smth1 & smth2 \\
          \hline
          smth3   & 1 & 2  \\  
          \hline
          smth4& 3 & 4 \\
          \hline
        \end{tabular}
      }
    \end{table}        

\end{document}

Got the below image from the above code.

enter image description here

As I done line break at the cell of smth3, the blank lines have appeared as shown in the below image.

How can I resolve this problem?

\documentclass[border=0.1cm]{article}

\usepackage{diagbox} \usepackage{makecell}

\begin{document}

  \begin{table}\centering\setlength\tabcolsep{3.5pt}\renewcommand\arraystretch{1.25}
      \noindent\makebox[\textwidth]{%
        \begin{tabular}{|l|*{3}{c|}}
          \hline
          \diagbox[width=\dimexpr \textwidth/8+2\tabcolsep\relax, height=1cm,width=3cm]{ row  }{column }
         & smth1 & smth2 \\
          \hline
          smth3 \\ text at 2nd row of smth3  & 1 & 2  \\ % Added "\\ text at 2nd row of smth3" 
          \hline
          smth4& 3 & 4 \\
          \hline
        \end{tabular}
      }
    \end{table}        

\end{document}

enter image description here

2 Answers2

1

Use multirow given in How to use \multirow

Here is the complete code

\documentclass[border=0.1cm]{article}
\usepackage{diagbox}
\usepackage{makecell}
\usepackage{multirow}
\begin{document}
        \begin{table}\centering \setlength\tabcolsep{3.5pt}\renewcommand\arraystretch{1.25}
          \noindent\makebox[\textwidth]{%
            \begin{tabular}{|l|*{3}{c|}}
              \hline
              \diagbox[width=\dimexpr \textwidth/8+2\tabcolsep\relax, height=1cm,width=3cm]{ row  }{column }
             & smth1 & smth2 \\
              \hline
              smith3 & \multirow{ 2}{*}{1}  & \multirow{ 2}{*}{2}   \\ % Added "\\ text at 2nd row of smth3" 
              text at 2nd row of smth3 &&\\
              \hline
              smth4& 3 & 4 \\
              \hline
            \end{tabular}
          }
        \end{table}        
\end{document}

enter image description here

0

enter image description here

\documentclass[border=0.1cm]{article}

\usepackage{diagbox} \usepackage{makecell}

\begin{document}

\begin{table}\centering\setlength\tabcolsep{3.5pt}\renewcommand\arraystretch{1.25}
    \noindent\makebox[\textwidth]{%
        \begin{tabular}{|l|*{3}{c|}}
            \hline
            \diagbox[width=\dimexpr \textwidth/8+2\tabcolsep\relax, height=1cm,width=4.2cm]{ row  }{column }
            & smth1 & smth2 \\
            \hline
            \makecell[l]{smth3 \\ text at 2nd row of smth3}  & 1 & 2  \\ % Added "\\ text at 2nd row of smth3" 
            \hline
            smth4& 3 & 4 \\
            \hline
        \end{tabular}
    }
\end{table}        

\end{document}

js bibra
  • 21,280