![在具有可变宽度的表格环境中,如何将文本垂直居中放置在多行“makecell”单元格旁边的单个单元格中?](https://linux22.com/image/452193/%E5%9C%A8%E5%85%B7%E6%9C%89%E5%8F%AF%E5%8F%98%E5%AE%BD%E5%BA%A6%E7%9A%84%E8%A1%A8%E6%A0%BC%E7%8E%AF%E5%A2%83%E4%B8%AD%EF%BC%8C%E5%A6%82%E4%BD%95%E5%B0%86%E6%96%87%E6%9C%AC%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD%E6%94%BE%E7%BD%AE%E5%9C%A8%E5%A4%9A%E8%A1%8C%E2%80%9Cmakecell%E2%80%9D%E5%8D%95%E5%85%83%E6%A0%BC%E6%97%81%E8%BE%B9%E7%9A%84%E5%8D%95%E4%B8%AA%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%EF%BC%9F.png)
下面是我的一个简化的示例表:
代码如下:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{makecell}
\begin{document}
\begin{table}[h]
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
\textbf{CENTER THIS} & \textbf{\makecell[t]{Words \\ are here}} & \textbf{\makecell[t]{Blank \\ \#1}} & \textbf{\makecell[t]{Blank \\ \#2}} & \textbf{\makecell[t]{Blank \\ \#3}} & \textbf{\makecell[t]{Blank \\ \#4}} & \textbf{\makecell[t]{Blank \\ \#5}} & \textbf{\makecell[t]{Blank \\ \#6}} \\
\hline
Words & \makecell[t]{Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\hline
Words & \makecell[t]{Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\hline
\end{tabular}
\end{table}
\end{document}
如何使标有“CENTER THIS”的单元格垂直居中?
答案1
托盘\makecell[cc]{Words \\ are here}
:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{makecell}
\begin{document}
\begin{table}[h]
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
\textbf{CENTER THIS}
& \textbf{\makecell[t]{Words \\ are here}}
& \textbf{\makecell[t]{Blank \\ \#1}}
& \textbf{\makecell[t]{Blank \\ \#2}}
& \textbf{\makecell[t]{Blank \\ \#3}}
& \textbf{\makecell[t]{Blank \\ \#4}}
& \textbf{\makecell[t]{Blank \\ \#5}}
& \textbf{\makecell[t]{Blank \\ \#6}} \\
\hline
Words & \makecell[cc]{Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\hline
Words & \makecell[cc]{Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\hline
\end{tabular}
\end{table}
\end{document}
编辑: 从你的评论可以看出,你遵循的是这样的:
\documentclass{article}
\usepackage{makecell}
\begin{document}
\begin{table}[h]
\renewcommand\cellalign{cc}
\begin{tabular}{|*{8}{c|}}
\hline
\textbf{CENTER THIS}
& \textbf{\makecell{Words \\ are here}}
& \textbf{\makecell{Blank \\ \#1}}
& \textbf{\makecell{Blank \\ \#2}}
& \textbf{\makecell{Blank \\ \#3}}
& \textbf{\makecell{Blank \\ \#4}}
& \textbf{\makecell{Blank \\ \#5}}
& \textbf{\makecell{Blank \\ \#6}} \\
\hline
Words & \makecell{Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\hline
Words & \makecell{Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\hline
\end{tabular}
\end{table}
\end{document}
但你可以尝试用tabularray
包来制作这个表。使用它你会得到更简单但更短的代码:
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}[h]
\begin{tblr}{hlines, vlines,
colspec={ *{8}{Q[c, m]} },
row{1} = {font=\bfseries}
}
CENTER THIS
& {Words \\ are here} & {Blank \\ \#1}
& {Blank \\ \#2}
& {Blank \\ \#3}
& {Blank \\ \#4}
& {Blank \\ \#5}
& {Blank \\ \#6} \\
Words & {Words \\ are here} & {} & {} & {} & {} & {} & {} \\
Words & {Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\end{tblr}
\end{table}
\end{document}
答案2
\makecell[c]
在该行的其他单元格中使用。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{makecell}
\begin{document}
\begin{table}[h]
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
\textbf{CENTER THIS} & \textbf{\makecell[c]{Words \\ are here}} & \textbf{\makecell[c]{Blank \\ \#1}} & \textbf{\makecell[c]{Blank \\ \#2}} & \textbf{\makecell[c]{Blank \\ \#3}} & \textbf{\makecell[c]{Blank \\ \#4}} & \textbf{\makecell[c]{Blank \\ \#5}} & \textbf{\makecell[c]{Blank \\ \#6}} \\
\hline
Words & \makecell[t]{Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\hline
Words & \makecell[t]{Words \\ are here} & {} & {} & {} & {} & {} & {} \\
\hline
\end{tabular}
\end{table}
\end{document}