当没有第一行时,前面的答案中使用两个表的以下代码非常容易理解。
\documentclass{article}
\begin{document}
\begin{tabular}{|@{} l @{}|@{} c @{}|}\hline
\begin{tabular}{ l }
some text in the left\\\cline{1-1}
some more text in the left column\\
\end{tabular}
&
\begin{tabular}{ l }
some text in the left\\\hline
some text in the left\\\hline
some more text in the left column
\end{tabular}\\\hline
\end{tabular}
\end{document}
但在我的实际情况中,每个表的顶部都有一个额外的行,它们的高度应该相等。
这是我的真实代码:
\begin{tabular}{@{} l @{}|@{} l @{}}
\toprule
\begin{tabular}{ l|l }
\multirow{2}{*}{Ticker} & \multirow{2}{*}{Types}\\
&
\end{tabular}
&
\begin{tabular}{l|l|l|l|l}
\multirow{2}{*}{Strikes} & Up & Down & Up/Down & \multirow{2}{*}{BarrierTypes}\\
& Barriers & Barriers & LevelInit &
\end{tabular}\\
\hline\hline
\begin{tabular}{ l|l }
Trade A & Vanilla\\\hline
Trade A & Vanilla\\\hline
Trade A & Vanilla\\\hline
Trade A & Vanilla\\\hline
Trade A & Vanilla\\\hline
Trade A & Vanilla
\end{tabular}
&
\begin{tabular}{ l|l|l|l|l }
max(1.05*S+4, 1.10*S) & \multirow{4}{*}{1.1*S} & \multirow{4}{*}{0.9*S} & \multirow{8}{*}{\shortstack{1.2*TS/\\0.8*TS}} & \multirow{8}{*}{\shortstack{Continuous/\\Out}}\\
min(1.05*S+4, 1.10*S) & & & & \\
min(1.05*S+8, 1.10*S) & & & & \\
min(1.05*S+8, 1.10*S+4) & & & & \\ \cline{1-3}
S & x*S, & \multirow{4}{*}{0} & & \\
1.05*S & Multiplier x & & & \\
min(1.05*S+4, 1.10*S) & moving as & & & \\
max(1.05*S+4, 1.10*S) & x-variable & & & \\
\end{tabular}\\
\bottomrule
\end{tabular}
不知道为什么左下角会是这样的图形,而且第一行的列线好像是错的。
答案1
使用一些\multirow
、\multicolumn
和\makecell
一些获得更好间距的小技巧(\renewcommand{\arraystretch}{1.4}
和\rule{0pt}{...}
),您可以创建不嵌套 的表格tabular
,但其宽度大于普通文章类的页面宽度。也许您必须将其侧放。
\documentclass{article}
\usepackage{array}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}
{\renewcommand{\arraystretch}{1.4}\noindent\small%
\begin{tabular}{|*9{c|}}
\hline
\rule{0pt}{4ex}Ticker & Types & Strikes & \makecell{Up\\Barries} & \makecell{Down\\Barriers} & \makecell{Up/Down\\LevelInit} & \multicolumn{3}{c|}{BarrierTypes} \\
\hline
Trade A & Vanilla & \multicolumn{3}{c|}{\multirow{3}{*}{\makecell{\rule{0pt}{2.5ex}max(1.05*S+4, 1.10*S)\\min(1.05*S+4, 1.10*S)\\min(1.05*S+8, 1.10*S)\\min(1.05*S+8, 1.10*S+4)}}} & \multirow{3}{*}{\makecell{\rule{0pt}{2.5ex}1.1*S}}& \multirow{3}{*}{0.9*S}&\multirow{6}{*}{\makecell{1.2*TS/\\0.8*TS}}&\multirow{6}{*}{\makecell{Continuous/\\Out}}\\
\cline{1-2}
Trade A & Vanilla & \multicolumn{3}{c|}{}&&&&\\
\cline{1-2}
Trade A & Vanilla & \multicolumn{3}{c|}{}&&&&\\
\cline{1-7}
Trade A & Vanilla & \multicolumn{3}{c|}{\multirow{3}{*}{\makecell{\rule{0pt}{2.5ex}S\\
1.05*S \\
min(1.05*S+4, 1.10*S) \\
max(1.05*S+4, 1.10*S)}}}&
\multirow{3}{*}{\makecell{\rule{0pt}{2.5ex}x*S\\
Multiplier x \\
moving as \\
x-variable}}
&\multirow{3}{*}{0}&&\\
\cline{1-2}
Trade A & Vanilla & \multicolumn{3}{c|}{}&&&&\\
\cline{1-2}
Trade A & Vanilla & \multicolumn{3}{c|}{}&&&&\\
\hline
\end{tabular}%
}
\end{document}
编辑:如果这是你想要的(但我更喜欢另一种方式或leandriis 的解决方案,因为这样会有很多未使用的空间并且桌子已经很宽了)。
重新编辑:为了避免\makecell
,\shortstack
似乎有效。
\documentclass{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}
{\renewcommand{\arraystretch}{1.6}\noindent\footnotesize%
\begin{tabular}{|*9{c|}}
\hline
Ticker & Types & Strikes & UpBarries & DownBarriers & Up/DownLevelInit & \multicolumn{3}{c|}{BarrierTypes} \\
\hline
Trade A & Vanilla & \multicolumn{3}{c|}{\multirow{3}{*}{\shortstack{\rule{0pt}{2.5ex}max(1.05*S+4, 1.10*S)\\min(1.05*S+4, 1.10*S)\\min(1.05*S+8, 1.10*S)\\min(1.05*S+8, 1.10*S+4)}}} & \multirow{3}{*}{\shortstack{\rule{0pt}{2.5ex}1.1*S}}& \multirow{3}{*}{0.9*S}&\multirow{6}{*}{\shortstack{1.2*TS/\\0.8*TS}}&\multirow{6}{*}{\shortstack{Continuous/\\Out}}\\
\cline{1-2}
Trade A & Vanilla & \multicolumn{3}{c|}{}&&&&\\
\cline{1-2}
Trade A & Vanilla & \multicolumn{3}{c|}{}&&&&\\
\cline{1-7}
Trade A & Vanilla & \multicolumn{3}{c|}{\multirow{3}{*}{\shortstack{\rule{0pt}{2.5ex}S\\
1.05*S \\
min(1.05*S+4, 1.10*S) \\
max(1.05*S+4, 1.10*S)}}}&
\multirow{3}{*}{\shortstack{\rule{0pt}{2.5ex}x*S\\
Multiplier x \\
moving as \\
x-variable}}
&\multirow{3}{*}{0}&&\\
\cline{1-2}
Trade A & Vanilla & \multicolumn{3}{c|}{}&&&&\\
\cline{1-2}
Trade A & Vanilla & \multicolumn{3}{c|}{}&&&&\\
\hline
\end{tabular}%
}
\end{document}
答案2
以下内容可能适合您的需求:
\documentclass{article}
\usepackage{geometry}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{bigstrut}
\usepackage{array}
\usepackage{ragged2e}
\newcolumntype{C}[1]{>{\Centering\arraybackslash}p{#1}}
\begin{document}
\begin{table}
\setlength{\tabcolsep}{3.4pt}
\newcommand{\mystrut}{\rule[-4pt]{0pt}{10pt}}
\begin{tabular}{@{}ccC{4cm}C{1.9cm}C{1.25cm}C{1.6cm}C{2cm}@{}}
\toprule
Ticker & Types & Strikes & Up \newline Barriers & Down \newline Barriers & Up/Down \newline LevelInit & Barrier \newline Types\\
\midrule
Trade A & Vanilla \mystrut
& \multirow{3}{\hsize}{\Centering max(1.05*S+4, 1.10*S) min(1.05*S+8, 1.10*S+4) min(1.05*S+4, 1.10*S) max(1.05*S+4, 1.10*S)} &
\multirow{4}{*}{1.1*S} &
\multirow{4}{*}{0.9*S} &
\multirow{8}{\hsize}{\Centering 1.2*TS/ 0.8*TS} &
\multirow{8}{\hsize}{\Centering Continuous/ Out}\\
\cmidrule(r){1-2}
Trade B & Digital \mystrut & \\
\cmidrule(r){1-2}
Trade C & Vanilla \mystrut & \\
\cmidrule(r){1-5}
Trade D & Vanilla \mystrut
& \multirow{3}{\hsize}{\Centering S \newline 1.05*S \newline min(1.05*S+4, 1.10*S) max(1.05*S+4, 1.10*S)} &
\multirow{4}{\hsize}{\Centering x*S Multiplier x moving as x-variable} &
\multirow{4}{*}{0.8*S} \\
\cmidrule(r){1-2}
Trade E & Digital \mystrut & \\
\cmidrule(r){1-2}
Trade F & Quadratic \mystrut & \\
\bottomrule
\end{tabular}
\end{table}
% & x*S, & \multirow{4}{*}{0} & & \\
% 1.05*S & & & & \\
% min(1.05*S+4, 1.10*S) & & & & \\
% max(1.05*S+4, 1.10*S) & & & & \\
\end{document}
我已删除嵌套表格。为了在第一列中增加间距,我使用了支柱,如multirow
手册中所建议的那样。