无法在两列(或更多列)翻译表格内居中或“进入”(在右列)

无法在两列(或更多列)翻译表格内居中或“进入”(在右列)

这篇文章是我旧文的后续:在表格或并行包内绘制垂直线(以及如何扩展并行以拥有超过 2 列

尽管如此,

  • 右列居中文本
  • 右列中同一“条目”内的多行文本

问题体现在以下代码中:

\documentclass{article}

\newlength\svparskip
\newlength\delfix
\delfix1.3pt
\newlength\colwidth
\setlength\colwidth{\dimexpr.5\textwidth-2\tabcolsep}
\newlength\splitcolwidth
\setlength\splitcolwidth{\dimexpr.25\textwidth-2\tabcolsep}
\newenvironment{partabular}
  {\par\svparskip=\parskip\relax\vspace{\delfix}}
  {\vspace{\delfix}\parskip=\svparskip\relax}
\newenvironment{nextentry}
  {\parskip-\delfix\par\noindent\begin{tabular*}{\textwidth}[t]
  {|p{\colwidth}|p{\colwidth}|}\hline}{\hline\end{tabular*}\par}
\def\filllines#1{\vspace{\dimexpr#1\ht\strutbox+#1\dp\strutbox}}

\begin{document}

\begin{partabular}
\begin{nextentry}
\centering{\textbf{$(A)$ some text i can center}} & {\centering{\textbf{$(B)$ some text i can't center}}} \\\hline
$(C)$ some text here and then enter \\ and have some more text below \\ which is possible & $(D)$ \textbf{some text here but then enter} \\ \textbf{and have some more text below} \\ \textbf{isn't possible + the vertical lines on the right get distorted ...} \\
\end{nextentry}
\begin{nextentry}
$(E)$ & $(F)$ \\\hline
\begin{tabular}[t]{@{}p{\splitcolwidth}|p{\splitcolwidth}@{}}
$(H)_1$ \filllines{6}& $(H)_2$
  \end{tabular} 
& \vspace{1cm} Thanks for any help in advance! :) \\
\end{nextentry}
\end{partabular}

\end{document}

答案1

由于您手动扩展一列中的垂直行,因此我不确定如何在另一列中自动执行该过程。但如果您可以接受手动干预,您应该能够实现所需的垂直布局,使用\filllines{}手动插入空白行。

已编辑,以实现单元格 B、D、F 和右下单元格的水平居中。为了\centering使 生效,\par必须 生效。{\centering...\par}在最后两种情况下可以使用 来完成,但由于单元格“B”和“F”是一行,因此我不得不使用 来实现\hfil...\hfill,以免\par产生不需要的空白行。

为了回答 OP 关于我如何垂直居中单元格“D”的评论,关键是将单元格“C”设为单个单元格,而 OP 的 MWE 将单元格“C”组合为两个唯一的单元格。

\documentclass{article}
\newlength\svparskip
\newlength\delfix
\delfix1.3pt
\newlength\colwidth
\setlength\colwidth{\dimexpr.5\textwidth-2\tabcolsep}
\newlength\splitcolwidth
\setlength\splitcolwidth{\dimexpr.25\textwidth-2\tabcolsep}
\newenvironment{partabular}
  {\par\svparskip=\parskip\relax\vspace{\delfix}}
  {\vspace{\delfix}\parskip=\svparskip\relax}
\newenvironment{nextentry}
  {\parskip-\delfix\par\noindent\begin{tabular*}{\textwidth}[t]
  {|p{\colwidth}|p{\colwidth}|}\hline}{\hline\end{tabular*}\par}
\def\filllines#1{\vspace{\dimexpr#1\ht\strutbox+#1\dp\strutbox}}

\begin{document}

\begin{partabular}
\begin{nextentry}
\centering{\textbf{$(A)$ some text i can center}} 
  & \hfil\bfseries$(B)$ some text i can't center\hfill\\ \hline
$(C)$ some text here and then enter and have some more text below  which is possible\bfseries\par\bigskip
and have some more text below
isn't possible + the vertical lines on the right get distorted ...
&  \filllines{2.5}{\centering$(D)$ \bfseries text here but then enter\par}
\filllines{2} \\ 
\end{nextentry}
\begin{nextentry}
$(E)$ & \hfil$(F)$\hfill \\\hline
\begin{tabular}[t]{@{}p{\splitcolwidth}|p{\splitcolwidth}@{}}
$(H)_1$ \filllines{6}& $(H)_2$
  \end{tabular} 
& \filllines{2.5} {\centering Thanks for any help in advance! :)\par} \\
\end{nextentry}
\end{partabular}
\end{document}

在此处输入图片描述

相关内容