多列和多行中的垂直和水平对齐

多列和多行中的垂直和水平对齐

我对多列和多行的对齐有很大的问题。我需要垂直对齐multicolumn内容“a”和“b”。我还需要水平和垂直对齐multirow。有办法吗?如果有人能帮助我将不胜感激。

\documentclass{article}
\usepackage{geometry}                 % customize page layout
\usepackage{array}
\usepackage{multirow}                 % multirow for table (rowspan)

\geometry{paper=a4paper, landscape,hmargin=28.5mm,vmargin=20mm}

\setlength\parindent{0cm}   % no indent for whole document
\setlength{\tabcolsep}{0cm}   % padding either side of each column (only horizontal)

% document start
\begin{document}

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{\dimexpr#1-\arrayrulewidth\relax}}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{\dimexpr#1-\arrayrulewidth\relax}}

  \begin{tabular}{
  | P{1.4cm}
  | M{1.4cm}
  | M{1.4cm}
  | P{7.6cm}
  | P{6.4cm}
  | P{1.2cm}
  | P{1.2cm}
  | P{1.2cm}
  | P{2.2cm}
  |
}

\hline
\multicolumn{4}{|c|}{\rule[-0.8cm]{0cm}{1cm} a} & \multicolumn{5}{c|}{b} \\

\hline
0 & 1 \par \footnotesize{(1)} & 2 & 3 & 4 & 5 & 6 & 7 &  \\\cline{1-8}

\rule[-0.8cm]{0cm}{1cm} & & &
\multirow{3}{7.6cm}{%
Question \hfill $\bigcirc$ \strut  Yes  $\bigcirc$ No \newline
Question \hfill $\bigcirc$ \strut  Yes  $\bigcirc$ No \newline
Question \hfill $\bigcirc$ \strut  Yes  $\bigcirc$ No \newline
Question \hfill $\bigcirc$ \strut  Yes  $\bigcirc$ No \newline
Question \hfill $\bigcirc$ \strut  Yes  $\bigcirc$ No \newline
Question \hfill $\bigcirc$ \strut  Yes  $\bigcirc$ No%  <--- % needed
}
  & & & & & \\
\cline{1-3}\cline{5-8}
\rule[-0.8cm]{0cm}{1cm} & s & & & & & & & \\\cline{1-3}\cline{5-8}
\multicolumn{2}{|P{2.8cm}}{\rule{0cm}{1cm}}  & & & & \multicolumn{3}{P{2.8cm}}{\rule{0cm}{1cm}}  &\\
\hline

\end{tabular}

% document end
\end{document}

在此处输入图片描述

答案1

\multirowcell以下是稍微简单的代码,以及来自包的使用makecell。所有内容都已垂直居中:

\documentclass{article}
\usepackage{geometry} % customize page layout
\usepackage{array}
\usepackage{multirow} % multirow for table (rowspan)
\geometry{paper=a4paper, landscape,hmargin=28.5mm,vmargin=20mm}

\usepackage{etoolbox}
\usepackage{makecell}
\renewcommand\cellalign{{p{\dimexpr7.6cm-10pt\relax}}c}
\patchcmd\cellset{\def\arraystretch{1}}{\def\arraystretch{1.12}}{}{}

\setlength\parindent{0cm} % no indent for whole document
\setlength{\tabcolsep}{0cm} % padding either side of each column (only horizontal)

\newcolumntype{M}[1]{>{\centering\arraybackslash}m{\dimexpr#1-\arrayrulewidth\relax}}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{\dimexpr#1-\arrayrulewidth\relax}}

\newcommand\YesNo{\hfill$\bigcirc$ \strut Yes\hskip0.5em$\bigcirc$ No }

% document start
\begin{document}

\begin{tabular}{%
    | P{1.4cm}
    | M{1.4cm}
    | M{1.4cm}
    | P{7.6cm}
    | P{6.4cm}
    | P{1.2cm}
    | P{1.2cm}
    | P{1.2cm}
    | P{2.2cm}
    |
    }%

    \hline
    \multicolumn{4}{|c|}{\rule[-0.45cm]{0pt}{1cm} a} & \multicolumn{5}{c|}{b} \\

    \hline
    0 & \thead{1 & & & & & & & \\ \footnotesize(1)}& 2 & 3 & 4 & 5 & 6 & 7 & \\
    \cline{1-8}
    \rule[-0.45cm]{0pt}{1cm} & & &
    \multirowcell{3}[4pt]{%
    Question \YesNo\\
    Question \YesNo\\%
    Question \YesNo\\%
    Question \YesNo\\%
    Question \YesNo\\%
    Question \YesNo% <--- % needed
    }%
    & & & & & \\
    \cline{1-3}\cline{5-8}
    \rule[-0.45cm]{0pt}{1cm} & s & & & & & & & \\
    \cline{1-3}\cline{5-8}
    \multicolumn{2}{|P{2.8cm}}{\rule[-0.45cm]{0pt}{1cm}} & & & & \multicolumn{3}{P{2.8cm}}{} &\\
    \hline

  \end{tabular}

  % document end
\end{document} 

在此处输入图片描述

相关内容