我们重点关注以下代码:
\documentclass{book}
\begin{document}
\begin{tabular}
{|l|
r@{}@{\hspace{0.3em}}
|l|r|}
%--------------------------------------------------------------------
\textbf{(2)}
&$x$
&$=a+b+c+d+e$
&Putting some reasons here\\
\hline
%--------------------------------------------------------------------
\textbf{(4)}
&\multicolumn{2}{p{5cm}}{Some multi lines sentences here.
Some multi lines sentences here.}\vline
& \multicolumn{1}{p{2.5cm}}{I love to move this parbox to very right of the table, that will
be great}\vline\\
\end{tabular}
\end{document}
它创建如下表:
我喜欢将 parbox 移到最右边以移除黄色空间,你知道怎么做吗?
答案1
我和 Zarko 理解的事情不一样(而且我的理解速度慢得多)。
\documentclass{book}
\usepackage{tabularray}
%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tblr}
{
hlines,vlines,
colspec = {
Q[c,m,wd=1.5em,font=\bfseries]
Q[l]
Q[l]
Q[r]},
cell{2}{2}={c=2}{l}
}
%\mycnt
(2)
&$x$
&$=a+b+c+d+e$
&Putting some reasons here\\
(4)
&{Some multi lines sentences here.\\
Some multi lines sentences here.}
&& \parbox[t]{2.5cm}{I love to move this parbox to very right of the table, that will
be great}
\end{tblr}
\end{document}
答案2
目前尚不清楚,表格最后一列的宽度是多少:
- 2.5 厘米,可以从
\multicolumn{1}{p{2.5cm}}{...}
您的 MWE 中得出,或者 - 最后两列可以有相等的宽度
因此,下面是两种情况的示例,使用了tabular˛,
tabularx and
tblr (defined in
tabularray` 包)表:
\documentclass{book}
%\usepackage{microtype}
\usepackage{tabularray,
tabularx}
\begin{document}
\begin{table}[ht]
\caption{The case when width of the last column is 2,5 cm}
\centering
\begin{tabular}{|l| p{5cm} | p{2.5cm}|}
\textbf{(2)} & $x=a+b+c+d+e$ & Putting some reasons here \\
\hline
\textbf{(4)} & Some multi lines sentences here.
Some multi lines sentences here.
& I love to move this parbox to very right of the table, that will be great
\end{tabular}
\medskip
\begin{tblr}{colspec={Q[l, font=\bfseries] Q[l, 5cm] Q[l, 2.5cm]},
vlines}
(2) & $x=a+b+c+d+e$ & Putting some reasons here \\
\hline
(4) & Some multi lines sentences here.
Some multi lines sentences here.
& I love to move this parbox to very right of the table, that will be great
\end{tblr}
\end{table}
\begin{table}[ht]
\caption{The case when the last two columns have equal width}
\begin{tabularx}{\linewidth}{|l| X | X |}
\textbf{(2)} & $x=a+b+c+d+e$ & Putting some reasons here \\
\hline
\textbf{(4)} & Some multi lines sentences here.
Some multi lines sentences here.
& I love to move this parbox to very right of the table, that will be great
\end{tabularx}
\medskip
\begin{tblr}{colspec={Q[l, font=\bfseries] X[l] X[l]},
vlines}
(2) & $x=a+b+c+d+e$ & Putting some reasons here \\
\hline
(4) & Some multi lines sentences here.
Some multi lines sentences here.
& I love to move this parbox to very right of the table, that will be great
\end{tblr}
\end{table}
\end{document}
答案3
不需要\multicolumn
。拆分单个单元格然后合并所有其他列更容易;解决方案使用内部。然后,定义自动添加换行符的段落array
列也更容易p{}
\documentclass{book}
\begin{document}
\bgroup
\centering
\begin{tabular}{| l | p{5cm} | p{4cm} |}
\textbf{(2)}
& \(\begin{array}{@{}r|l@{}}x & = a + b + c + d + e\end{array}\)
& Putting some reasons here \\
\hline
\textbf{(4)}
& Some multi lines sentences here. Some multi lines sentences here.
& I love to move this parbox to very right of the table, that will be great} \\
\end{tabular}
\par
\egroup
\end{document}