我有下表tabularx
,并且我希望最后一个单元格是多行的,因为多行 1和多行 2标记的细胞。
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\linespread{1.5} % Set the line-spacing
\begin{table}[H]
\centering
\def\arraystretch{1}
\begin{tabularx}{\linewidth}{| m{0.025\linewidth} | m{0.74\linewidth} | Y |}
\hline
\rowcolor[HTML]{4473c5} \multicolumn{2}{|c|}{{\color{white} \textbf{Foo}}} & {\color{white} \textbf{Foo BarBaz}} \\ \hline
\rowcolor[HTML]{b3c6e7} \multicolumn{3}{|l|}{\textbf{Lorem ipsum}} \\ \hline
1 & \textbf{Dolor sit} & 0.5 \\ \hline
2 & \textbf{Multi-line 1:} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin feugiat eros et mauris dictum, tempus finibus mauris iaculis. Sed suscipit finibus sem. & 2.5 \\ \hline
\rowcolor[HTML]{b3c6e7}
\multicolumn{3}{|l|}{\textbf{Consecteur adipiscing}} \\ \hline
3 & \textbf{Multi-line 2:} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent ac metus nec risus euismod varius nec nec turpis. Curabitur efficitur. & 1 \\ \hline
\rowcolor[HTML]{b3c6e7}
\multicolumn{3}{|l|}{\textbf{Present ac metus}} \\ \hline
\multicolumn{3}{|l|}{This is the cell I want to be also multi-line. } \\ \hline
\end{tabularx}
\caption{Foo}
\label{tab:my-table2}
\end{table}
据我目前所知,最后一个单元格不能正确支持多行。
我怎样才能让最后一个单元格表现为多行 1和多行 2标记的细胞。
提前非常感谢您。
答案1
现在看一下——我已经为所有正在使用的各种多列使用了一些快捷方式
最后一行感谢—— https://tex.stackexchange.com/a/377722/197451
\documentclass[10pt,a4paper]{article}
\usepackage[table]{xcolor}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcommand{\mc}[1]{\multicolumn{3}{|l|}{\textbf {#1}}}
\newcommand{\md}[1]{\multicolumn{2}{|c|}{\textbf {#1}}}
\newcommand{\me}[1]{\multicolumn{3}{|p{\dimexpr\linewidth-2\tabcolsep-
2\arrayrulewidth}|}{#1}}
\linespread{1.5} % Set the line-spacing
\begin{document}
\begin{table}
\centering
\def\arraystretch{1}
\begin{tabularx}{\linewidth}{| m{0.025\linewidth} | m{0.74\linewidth} | Y |}
\hline
\rowcolor[HTML]{4473c5} \md{Foo}
& {\textbf{Foo BarBaz}} \\ \hline
\rowcolor[HTML]{b3c6e7}\mc{Lorem ipsum} \\ \hline
1
& \textbf{Dolor sit}
& 0.5 \\ \hline
2
& \textbf{Multi-line 1:} Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Proin feugiat eros et mauris dictum, tempus finibus
mauris iaculis. Sed suscipit finibus sem.
& 2.5 \\ \hline
\rowcolor[HTML]{b3c6e7}
\mc{Present ac metus} \\ \hline
3
& \textbf{Multi-line 2:} Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Praesent ac metus nec risus euismod varius nec nec turpis.
Curabitur efficitur.
& 1 \\ \hline
\rowcolor[HTML]{b3c6e7}
\mc{Present ac metus} \\ \hline
\me{I want a new line I want a new line I want a new line I want a new
line I want a new line I want a new line} \\ \hline
\end{tabularx}
\caption{Foo}
\label{tab:my-table2}
\end{table}
\end{document}