我想创建一个新的列类型,用于多列内部。我尝试使用以下解决方案来实现一种新的列类型Tabularx 和多列。
我添加了这个 MWE 以便更好地理解
\documentclass{scrbook}
\usepackage{array}
\usepackage{multirow}
\usepackage{tabularx}
\begin{document}
%\newcolumntype{MultiX}[1]{>{\hsize=\dimexpr#1\hsize+((2*#1)-2)\tabcolsep+(#1+1-2)\arrayrulewidth\relax}X}
%\newcolumntype{TwoX}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}X}
\begin{table}
\centering
\caption{Example}
\begin{tabularx}{\textwidth}{lXX}
Name & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}X}{Test} \\
Target & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax}X}{ I am a very interesting sentence, and I am long I am a very interesting sentence, and I am long } \\
\multirow{3}{*}{ Essential Steps } & Step & System response \\
& 1. I am a very interesting sentence & I am a very interesting sentence \\
& 2. I am a very interesting sentence & I am a very interesting sentence \\
\end{tabularx}
\end{table}
\end{document}
我想要多列的结果,但要使用新的列类型。我将在多个 tabularx 中使用此列类型。我尝试为n
列创建一个动态列类型,但 2 列的列类型(正如我尝试过的列类型)TowX
就足够了。
答案1
您无法通过以下方式定义多列规范,\newcolumntype
但是您可以定义一个命令来执行此操作
\documentclass{scrbook}
\usepackage{array}
\usepackage{multirow}
\usepackage{tabularx}
\begin{document}
\newcommand\zz[1]{\multicolumn{#1}{>{\hsize=%
\dimexpr\numexpr#1\relax\hsize+
\numexpr#1*2-2\relax\tabcolsep+
\numexpr#1-1\relax\arrayrulewidth
\relax}X}}
\begin{table}
\centering
\caption{Example}
\begin{tabularx}{\textwidth}{lXX}
Name & \zz{2}{Test} \\
Target & \zz{2}{ I am a very interesting sentence, and I am long I am a very interesting sentence, and I am long } \\
\multirow{3}{*}{ Essential Steps } & Step & System response \\
& 1. I am a very interesting sentence & I am a very interesting sentence \\
& 2. I am a very interesting sentence & I am a very interesting sentence \\
\end{tabularx}
\end{table}
\end{document}
答案2
表格行之间可能有分页符:
\documentclass[captions=tableabove]{scrbook}
\usepackage{array}
\usepackage{multirow}
\usepackage{xltabular}
\newcolumntype{Y}{>{\hsize=\dimexpr2\hsize+2\tabcolsep}X}
\begin{document}
\begin{xltabular}{\textwidth}{lXX | }
\caption{Example}\\
Name & \multicolumn{2}{Y|}{Test} \\
Target & \multicolumn{2}{Y|}{ I am a very
interesting sentence, and I
am
long I am a
very
interesting sentence, and I am long } \\
\multirow{3}{*}{ Essential Steps } & Step & System response \\
& 1. I am a very interesting sentence & I am a very interesting sentence \\
& 2. I am a very interesting sentence & I am a very interesting sentence \\
\end{xltabular}
\end{document}