下面是我的代码,它给了我一个错误消息:
\documentclass[11pt,oneside,openany]{book}
\usepackage[a4paper, left=1.5cm, right=1.5cm, top=3cm, bottom=3cm]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{longtable}
\usepackage[table, dvipsnames]{xcolor}
\usepackage{array,booktabs}
\usepackage{makecell}
\definecolor{mintbg}{rgb}{.63,.79,.95}
\begin{document}
\begin{longtable}{|p{1.7cm}|p{3.6cm}|p{2.8cm}|p{4cm}|}
\hline
\rowcolor{gray} \bfseries $ t $&\bfseries $ D_{t} $&\bfseries $ ABCD $&\bfseries $ sdf$ \\ \hline \hline
\endfirsthead
\hline
\rowcolor{gray} \bfseries $ t $&\bfseries $ D_{t} $&\bfseries $ TV=P_{n_{1}+n_{2}} $&\bfseries $ PV $ \\ \hline \hline
\endhead
\hline \multicolumn{4}{r}{\emph{Continued on next page}}
\endfoot
\hline
\endlastfoot
\rowcolor{mintbg}1& & &\Gape[6pt]{dgdgd\\ fgwwwu\\dvdgdgg
dgfgfgf}\\
\hline
\rowcolor{mintbg} $x $&& &\Gape[6pt]{fgfgf\\ghhriri\\rrhrhrhfbf}
\end{longtable}
\end{document}
答案1
添加\makecell
命令:
\documentclass[11pt,oneside,openany]{book}
\usepackage[a4paper, left=1.5cm, right=1.5cm, top=3cm, bottom=3cm]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{longtable}
\usepackage[table, dvipsnames]{xcolor}
\usepackage{array,booktabs}
\usepackage{makecell}
\definecolor{mintbg}{rgb}{.63,.79,.95}
\begin{document}
\begin{longtable}{|p{1.7cm}|p{3.6cm}|p{2.8cm}|p{4cm}|}
\hline
\rowcolor{gray} \bfseries $ t $&\bfseries $ D_{t} $&\bfseries $ ABCD $&\bfseries $ sdf$ \\ \hline \hline
\endfirsthead
\hline
\rowcolor{gray} \bfseries $ t $&\bfseries $ D_{t} $&\bfseries $ TV=P_{n_{1}+n_{2}} $&\bfseries $ PV $ \\ \hline \hline
\endhead
\hline \multicolumn{4}{r}{\emph{Continued on next page}}
\endfoot
\hline
\endlastfoot
\rowcolor{mintbg}1& & &\Gape[6pt]{\makecell{dgdgd\\ fgwwwu\\ dvdgdgg
dgfgfgf}}\\
\hline
\rowcolor{mintbg} $x $&& &\Gape[6pt]{\makecell[l]{fgfgf\\\ ghhriri\\ rrhrhrhfbf}}
\end{longtable}
\end{document}
答案2
尝试使用tabularray
包:
\documentclass[11pt,oneside,openany]{book}
\usepackage[a4paper,
hmargin=1.5cm, vmargin=3cm]{geometry}
\usepackage[table, dvipsnames]{xcolor}
\definecolor{mintbg}{rgb}{.63,.79,.95}
\usepackage{tabularray}
\begin{document}
\begingroup
\SetTblrStyle{caption-tag}{font=\bfseries}
\DefTblrTemplate{contfoot-text}{normal}{\small\textit{Continued on the next page}}
\SetTblrTemplate{contfoot-text}{normal}
\begin{longtblr}[
caption={My long table},
label={tab:valhelmet},
]{hlines, vlines,
colspec={>{$}X[1.7,c]<{$} X[3.6,l] X[2.8,l,m] X[4,l,m]},
rowsep={5pt},
rows={mintbg},
row{1}={gray, font=\bfseries\itshape},
}
t
& \SetCell{c} $D_{t}$
& \SetCell{c} ABCD
& \SetCell{c} sdf \\
%
1 & & & dgdgd\newline fgwwwu\newline dvdgdgg dvdgdgg \\
x & & & fgfgf\newline ghhriri\newline rrhrhrhfbf \\
\end{longtblr}
\endgroup
\end{document}