是否可以创建像这样的表格?

是否可以创建像这样的表格?

桌子 我希望单元格垂直居中对齐。

答案1

在 OpTeX 中,我们可以使用\vspan宏,如文档,第 16 页。

\fontfam[lm]
\sans\rm

\table{4{c|}}{\crl
   \vspan2{x=1} & abc & xyz & asd, \crlp{2-3}
                & bcd & qwe & pqr  \crl
   \vspan2{x=2} & abc & xyz & asd, \crlp{2-3}
                & bcd & qwe & pqr  \crl
   \vspan2{x=3} & abc & xyz & asd, \crlp{2-3}
                & bcd & qwe & pqr  \crl
   \vspan2{x=4} & abc & xyz & asd, \crlp{2-3}
                & bcd & qwe & pqr  \crl
}
\bye

答案2

这是一个采用单一tabular环境的解决方案。

在此处输入图片描述

\documentclass{article}
\usepackage{array}    % for '\extrarowheight' parameter and 'w' column type
\usepackage{multirow} % for '\multirow' macro
\usepackage{arev}     % optional: sans-serif text and math fonts

\begin{document}

\begin{center}
\setlength\extrarowheight{2pt} % default: 0pt

\begin{tabular}{ wc{1.5cm} | wl{1.5cm} | wl{1.5cm} | wc{1.5cm} | }
\hline
\multirow{2.2}{*}{x=1} & abc & xyz & asd, \\
\cline{2-3}
                       & bcd & qwe & pqr  \\
\hline
\multirow{2.2}{*}{x=2} & abc & xyz & asd, \\
\cline{2-3}
                       & bcd & qwe & pqr  \\
\hline
\end{tabular}

\end{center}

\end{document}

答案3

使用tabularray包的解决方案:

\documentclass[margin=3mm]{standalone}
\usepackage{tabularray} 
\usepackage{arev}     % optional: sans-serif text and math fonts

\begin{document}
\begin{tblr}{hline{odd} = solid, hline{even} = {2-3}{solid}, 
             vline{2-Z} = solid, 
             colspec = {Q[c, wd=15mm, mode=math] *{3}{Q[c, wd=15mm]}}, 
             cell{odd}{1} = {r=2}{} % multi row cells
             }
x=1 & abc & xyz & asd, \\
    & bcd & qwe & pqr  \\
x=2 & abc & xyz & asd, \\
    & bcd & qwe & pqr  \\
x=3 & abc & xyz & asd, \\
    & bcd & qwe & pqr  \\
x=4 & abc & xyz & asd, \\
    & bcd & qwe & pqr  \\
\end{tblr}
\end{document}

在此处输入图片描述

附录: 或者通过对上述 MWE 进行细微的改动,在最后一列也使用多行单元格:

\documentclass[margin=3mm]{standalone}
\usepackage{tabularray}
\usepackage{arev}     

\begin{document}
\begin{tblr}{hlines, vline{2-Z} = solid, 
             colspec = {Q[c, wd=15mm, mode=math] *{3}{Q[c, wd=15mm]}}, 
             cell{odd}{1,Z} = {r=2}{} % multi row cells
             }
y=1 & abc & xyz & {asd,\\ pqr}  \\
    & bcd & qwe &               \\
y=2 & abc & xyz & {asd,\\ pqr}  \\
    & bcd & qwe &               \\
y=3 & abc & xyz & {asd,\\ pqr}  \\
    & bcd & qwe &               \\
y=4 & abc & xyz & {asd,\\ pqr}  \\
    & bcd & qwe &               \\
\end{tblr}

\end{document}

生成的表格与以前类似:

在此处输入图片描述

答案4

您可以通过嵌套表格环境来实现这一点 - 每个单元格本身可以是一个独立的表格环境,最左边一列的表格环境垂直[t]对齐,其他列的表格环境垂直[c]对齐:

\documentclass{article}
\usepackage{array}
\begin{document}

\sffamily\selectfont

\begin{tabular}{|@{}c@{}|@{}c@{}|@{}c@{}|@{}c@{}|}%
\hline \begin{tabular}[t]{c}$\mathsf{x=1}$\end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{abc}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \\\hline 
       \rlap{bcd}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{xyz}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \\\hline
       \rlap{qwe}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \end{tabular}%
&      \begin{tabular}[c]{r}asd,\\[\arrayrulewidth] pqr\end{tabular}%
\\
\hline \begin{tabular}[t]{c}$\mathsf{x=2}$\end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{a1b1c1}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \\\hline
       \rlap{b1c1d1}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{x1y1z1}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \\\hline
       \rlap{q1w1e1}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \end{tabular}%
&      \begin{tabular}[c]{r}asd,\\[\arrayrulewidth] pqr\end{tabular}%
\\\hline \begin{tabular}[t]{c}$\mathsf{x=3}$\end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{a11b11c11}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \\\hline
       \rlap{b11c11d11}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{x11y11z11}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \\\hline
       \rlap{q11w11e11}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \end{tabular}%
&      \begin{tabular}[c]{r}asd,\\[\arrayrulewidth] pqr\end{tabular}%
\\\hline \begin{tabular}[t]{c}$\mathsf{x=4}$\end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{a111b111c111}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \\\hline
       \rlap{b111c111d111}\hphantom{\vbox{\hbox{abc}\hbox{bcd}\hbox{a1b1c1}\hbox{b1c1d1}\hbox{a11b11c11}\hbox{b11c11d11}\hbox{a111b111c111}\hbox{b111c111d111}}}
       \end{tabular}%
&      \begin{tabular}[c]{l@{\hskip4\tabcolsep}}
       \rlap{x111y111z111}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \\\hline
       \rlap{q111w111e111}\hphantom{\vbox{\hbox{xyz}\hbox{qwe}\hbox{x1y1z1}\hbox{q1w1e1}\hbox{x11y11z11}\hbox{q11w11e11}\hbox{x111y111z111}\hbox{q111w111e111}}}
       \end{tabular}%
&      \begin{tabular}[c]{r}asd,\\[\arrayrulewidth] pqr\end{tabular}%
\\
\hline
\end{tabular}
\end{document}

在此处输入图片描述

如果您决定为表格列指定宽度,则不需要组合\rlap\hphantom来确保同一列中所有表格的宽度相等。

相关内容