我想做一张长桌 我想将文本对齐到矩形中心第一列和第三列的每个单元格。例如,如图所示,第一列和第二列,但我无法对齐。我的代码是
\documentclass[a4paper, 12pt]{article}
\usepackage{fouriernc}
\usepackage[utf8]{inputenc}\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{xcolor}
\usepackage{tabvar}
\usepackage{lipsum}
\linespread{1.5}
\setlength{\arrayrulewidth}{0.2 mm}
\usepackage{longtable}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{document}
\lipsum[1-2]
\begin{longtable}{
|>{\centering\arraybackslash}m{0.06\dimexpr \textwidth-4\arrayrulewidth-6.5\tabcolsep\relax}|
p{0.84\dimexpr \textwidth-4\arrayrulewidth-6.5\tabcolsep\relax}|
>{\centering\arraybackslash} m{0.1\dimexpr \textwidth-4\arrayrulewidth-6.5\tabcolsep\relax}|
}
\hline
\multicolumn{1}{|c|}{\textbf{\textit{1st}}}&\multicolumn{1}{|c|}{\textbf{\textit{2nd }}}
& \multicolumn{1}{|c|}{\textbf{\textit{3rd }}}\\
\hline
\endhead
\hline
\endfoot
\hline
\textbf{First}& \cellcolor[gray]{.9} Solve the equation $y=x^3 - 3x^2 -9x$ & \cellcolor[gray]{.9}
\textbf{1.0}
\\
\cline{2-3}
& Long text long text long text long text Long text long text long text long text Long text long text long text long text\[\begin{tabvar}{|C|CCCCCCC|}
\hline
\,\,x\,\, &-\infty & &-1& &3 & &+\infty\\
\hline
f'(x) & &+ &0 &- &0 &+ & \\
\hline
\niveau{1}{2}\raisebox{0.5em}{$f$}&\niveau{1}{2}-\infty&\croit&5 &\decroit&-27&\croit&+\infty\\
\hline
\end{tabvar}\] & 2 points \\
\end{longtable}
\end{document}
我该如何对齐?
答案1
这是一个使用 的解决方案,它将的\tablex
功能引入,并在必要时为行提供一些垂直填充。因此,表格的代码更简单。我还冒昧地稍微简化了序言。longtable
tabularx
makecell
\documentclass[a4paper, 12pt]{article}
\usepackage{fouriernc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[margin=2cm]{geometry}
\usepackage{xcolor}
\usepackage{tabvar}
\usepackage{lipsum}
\linespread{1.5}
\setlength{\arrayrulewidth}{0.2 mm}
\usepackage{ltablex, makecell}
\begin{document}
\lipsum[1-2]
\begin{tabularx}{\linewidth}{|c|X|c|}
\hline
\textbf{\itshape1\textsuperscript{st}}&\multicolumn{1}{c}{\textbf{\itshape 2{\textsuperscript{nd}}}}
& \textbf{\itshape 3\textsuperscript{rd}}\\
\hline
\endhead
\hline
\endfoot
& \cellcolor[gray]{.9} Solve the equation $y=x³ - 3x² -9x$ & \cellcolor[gray]{.9}
\textbf{1.0}
\\
\cline{2-3}
& Long text long text long text long text Long text long text long text long text Long text long text long text long text & \\
\textbf{First} & \centering \Gape[2ex]{$ \begin{tabvar}{|C|CCCCCCC|}
\hline
\,\,x\,\, & -∞ & & -1 & & 3 & & +∞ \\
\hline
f'(x) & & + & 0 & - & 0 & + & \\
\hline
\niveau{1}{2}\raisebox{0.5em}{$f$} & \niveau{1}{2}-∞ & \croit & \TVstretch[3pt]{5} & \decroit & -27 & \croit & +∞ \\
\hline
\end{tabvar} $} & 2 points \\
\end{tabularx}
\end{document}
答案2
我只是说我真的不推荐这种表格。我鼓励你至少阅读并考虑手册中的建议booktabs
。它可能有点极端,但像这样的表格让我非常清楚地了解了该软件包的激进主义 ;)。
如果你必须:
\documentclass[a4paper, 12pt]{article}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\usepackage{fouriernc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{xcolor}
\usepackage{tabvar}
\usepackage{lipsum}
\linespread{1.5}
\setlength{\arrayrulewidth}{0.2 mm}
\usepackage{longtable,calc,makecell}
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{document}
\lipsum[1-2]
\newlength\mywidth
\setlength\mywidth{\textwidth-4\arrayrulewidth-6.5\tabcolsep}
\renewcommand\theadfont{\bfseries\itshape}
\renewcommand\theadalign{c}
\begin{longtable}{%
|>{\centering\arraybackslash}m{0.06\mywidth}| m{0.84\mywidth}| >{\centering\arraybackslash} m{0.1\mywidth}|
}
\hline
\thead{1st} & \thead{2nd} & \thead{3rd} \\
\hline
\endhead
\hline
\endfoot
\hline
& \cellcolor[gray]{.9} Solve the equation $y=x^3 - 3x^2 -9x$ & \cellcolor[gray]{.9}
\textbf{1.0}
\\
\cline{2-3}
\textbf{First}& Long text long text long text long text Long text long text long text long text Long text long text long text long text
\[\begin{tabvar}{|C|CCCCCCC|}
\hline
\,\,x\,\, &-\infty & &-1& &3 & &+\infty\\
\hline
f'(x) & &+ &0 &- &0 &+ & \\
\hline
\niveau{1}{2}\raisebox{0.5em}{$f$}&\niveau{1}{2}-\infty&\croit&5 &\decroit&-27&\croit&+\infty\\
\hline
\end{tabvar}\] & 2 points \\
\end{longtable}
\end{document}