我根据以下引用编写了以下代码这个帖子。
\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}
从上面的代码中得到下面的图像。
当我在 smth3 单元格处完成换行时,出现了空白行,如下图所示。
我该如何解决这个问题?
\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}
答案1
\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}
答案2
使用给定的多行 如何使用 \multirow
以下是完整的代码
\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}