在具有可变宽度的表格环境中,如何将文本垂直居中放置在多行“makecell”单元格旁边的单个单元格中?

在具有可变宽度的表格环境中,如何将文本垂直居中放置在多行“makecell”单元格旁边的单个单元格中?

下面是我的一个简化的示例表:

文本

代码如下:

\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}

在此处输入图片描述

相关内容