我正在尝试从 Excel 复制复杂的表格(方案):
带有数字(1、2、...)的单元格应该或多或少呈正方形。围绕中心表格形成直角的线条比普通边框更粗(此处未显示)。
我可以单独制作每个表格,但不知道如何将它们组合在一起(水平和垂直方向有一些小空间)。尝试使用 ctan 中的 excel2latex 宏,但没有成功。
先感谢您。
编辑
正如评论中所要求的,这里是单独的表格:
\documentclass{article}
\usepackage{multirow}
\usepackage{graphicx}
\begin{document}
\begin{tabular}{|r|r|r|r|r|}
\hline
1 & 2 & 3 & 4 & 5\\
\hline
1 & 2 & 3 & 4 & 5\\
\hline
1 & 2 & 3 & 4 & 5\\
\hline
1 & 2 & 3 & 4 & 5\\
\hline
1 & 2 & 3 & 4 & 5\\
\hline
\end{tabular}
\begin{tabular}{c|l|r|}
\cline{2-3}
\multirow{5}{*}{\rotatebox[origin=c]{90}{some long text here}} & qwerty 1 & 1 \\[1.5ex]
\cline {2-3}
& qwerty 2 & 2 \\[1.5ex]
\cline {2-3}
& qwerty 3 & 3 \\[1.5ex]
\cline {2-3}
& qwerty 4 & 4 \\[1.5ex]
\cline {2-3}
& qwerty 5 & 5 \\[1.5ex]
\cline{2-3}
\end{tabular}
\begin{tabular}{|r|l|}
\hline
4 & text \\
\hline
3 & text text \\
\hline
2 & text text text \\
\hline
1 & text \\
\hline
\end{tabular}
\begin{tabular}{|r|r|r|r|r|}
\hline
1 & 2 & 3 & 4 & 5 \\
\hline
\rotatebox[origin=c]{90}{abc} & \rotatebox[origin=c]{90}{abc abc} & \rotatebox[origin=c]{90}{abc} & \rotatebox[origin=c]{90}{abc abc} & \rotatebox[origin=c]{90}{abc abc abc} \\
\hline
\multicolumn{5}{c}{long text here 2} \\
\end{tabular}
\end{document}
编辑2
我提出这个问题是为了引起高级用户和软件包开发人员的注意,人们需要一种简单而强大的方法来制作这种复杂的“可视化”表格。创建表格的复杂性使人们不愿意使用 LaTeX。
答案1
{NiceTabular}
的一个解决方案nicematrix
。
每个子表的规则由插入该子表左上角单元格的命令\Block
(使用键)绘制。hvlines
形成直角的粗线是在\CodeAfter
构建表格后用 Tikz 绘制的(使用在nicematrix
数组的行、列和单元格下创建的 PGF/Tikz 节点)。
\documentclass[10pt]{article}
\usepackage{nicematrix,tikz}
\begin{document}
\sffamily
\small
\renewcommand{\arraystretch}{1.8}
\setlength{\tabcolsep}{2pt}
\newcolumntype{R}{w{r}{8mm}}
\begin{NiceTabular}{clRw{c}{4mm}RRRRRcRl}[cell-space-top-limit=2pt]
\Block{5-1}{\rotate some long text here}
& \Block[hvlines]{5-2}{}
qwerty 1 & 1 & & \Block[hvlines]{5-5}{}
1 & 2 & 3 & 4 & 5 & & \Block[hvlines]{4-2}{}
4 & text \\
& qwerty 2 & 2 & & 1 & 2 & 3 & 4 & 5 & & 3 & text text \\
& qwerty 3 & 3 & & 1 & 2 & 3 & 4 & 5 & & 2 & text text text \\
& qwerty 4 & 4 & & 1 & 2 & 3 & 4 & 5 & & 1 & text \\
& qwerty 5 & 5 & & 1 & 2 & 3 & 4 & 5 \\
\\
& & & & \Block[hvlines]{2-5}{}
1 & 2 & 3 & 4 & 5 & & \Block[C,draw]{2-2}{centered text }\\
\RowStyle{\rotate}
& & & & abc & abc abc & abc & abc abc & abc abc abc \\
\CodeAfter
\tikz \draw [thick] (1-|4.5) |- (6.5-|10) ;
\end{NiceTabular}
\end{document}
回答评论中的问题
我没有简单的解决方案。我已将列更改w{r}{8mm}
为列,p[r]{8mm}
因为在列中p
,可以使用更改水平对齐\RowStyle{\centering}
。但是,这会给旋转元素带来问题,这些元素现在包裹在 8 毫米处(也许我应该在中更改它nicematrix
)。这就是为什么我必须使用\makebox
...
\documentclass{article}
\usepackage{nicematrix,tikz}
\begin{document}
\sffamily
\small
\renewcommand{\arraystretch}{1.8}
\setlength{\tabcolsep}{2pt}
\newcolumntype{R}{p[r]{8mm}}
\begin{NiceTabular}{clRw{c}{4mm}RRRRRcRl}[cell-space-top-limit=2pt]
\Block{5-1}{\rotate some long text here}
& \Block[hvlines]{5-2}{}
qwerty 1 & 1 & & \Block[hvlines]{5-5}{}
1 & 2 & 3 & 4 & 5 & & \Block[hvlines]{4-2}{}
4 & text \\
& qwerty 2 & 2 & & 1 & 2 & 3 & 4 & 5 & & 3 & text text \\
& qwerty 3 & 3 & & 1 & 2 & 3 & 4 & 5 & & 2 & text text text \\
& qwerty 4 & 4 & & 1 & 2 & 3 & 4 & 5 & & 1 & text \\
& qwerty 5 & 5 & & 1 & 2 & 3 & 4 & 5 \\
\\
\RowStyle{\rotate\centering}
& & & & \Block[hvlines]{2-5}{}
1 & 2 & 3 & 4 & 5 & & \Block[C,draw]{2-2}{centered text }\\
\noalign{\vskip 11mm}
\RowStyle{\rotate\centering}
& & & & \makebox[18mm][r]{abc} & \makebox[18mm][r]{abc abc} & \makebox[18mm][r]{abc} & \makebox[18mm][r]{abc abc} & \makebox[18mm][r]{abc abc abc} \\
\CodeAfter
\tikz \draw [thick] (1-|4.5) |- (6.5-|10) ;
\end{NiceTabular}
\end{document}
答案2
建议只制作一张表:
\documentclass{article}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{threeparttable}
\renewcommand{\arraystretch}{1.2}
\usepackage{caption}
\captionsetup{font=small,labelfont=bf,justification = justified,
singlelinecheck = true}
\captionsetup[table]{singlelinecheck = false}
\usepackage{makecell} %<- EDIT
\begin{document}
\setlength\tabcolsep{4pt}
\begin{table}[]
\begin{threeparttable}
\caption{This is a Table}
\label{tab:my-table}
\begin{tabular}{ccccccccccccl}
\cline{2-3} \cline{6-10} \cline{12-13}
\multicolumn{1}{c|}{\multirow{5}{*}{\rotatebox[origin=c]{90}{some long text here}}} &
\multicolumn{1}{c|}{quwerty 1} &
\multicolumn{1}{r|}{1} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{1} &
\multicolumn{1}{c|}{2} &
\multicolumn{1}{c|}{3} &
\multicolumn{1}{c|}{4} &
\multicolumn{1}{c|}{5} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{4} &
\multicolumn{1}{l|}{text} \\ \cline{2-3} \cline{6-10} \cline{12-13}
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{quwerty 2} &
\multicolumn{1}{r|}{2} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{1} &
\multicolumn{1}{c|}{2} &
\multicolumn{1}{c|}{3} &
\multicolumn{1}{c|}{4} &
\multicolumn{1}{c|}{5} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{3} &
\multicolumn{1}{l|}{text text} \\ \cline{2-3} \cline{6-10} \cline{12-13}
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{quwerty 3} &
\multicolumn{1}{r|}{3} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{1} &
\multicolumn{1}{c|}{2} &
\multicolumn{1}{c|}{3} &
\multicolumn{1}{c|}{4} &
\multicolumn{1}{c|}{5} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{2} &
\multicolumn{1}{l|}{text text text} \\ \cline{2-3} \cline{6-10} \cline{12-13}
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{quwerty 4} &
\multicolumn{1}{r|}{4} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{1} &
\multicolumn{1}{c|}{2} &
\multicolumn{1}{c|}{3} &
\multicolumn{1}{c|}{4} &
\multicolumn{1}{c|}{5} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{1} &
\multicolumn{1}{l|}{text} \\ \cline{2-3} \cline{6-10} \cline{12-13}
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{quwerty 5} &
\multicolumn{1}{r|}{5} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{1} &
\multicolumn{1}{c|}{2} &
\multicolumn{1}{c|}{3} &
\multicolumn{1}{c|}{4} &
\multicolumn{1}{c|}{5} &
&
&
\\ \cline{2-3} \cline{6-10}
&
&
&
\multicolumn{1}{c|}{} &
&
&
&
&
&
&
&
&
\\ \cline{5-10}
&
&
&
&
&
&
&
&
&
&
&
&
\\ \cline{6-10} \cline{12-13}
&
&
&
&
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{1} &
\multicolumn{1}{c|}{2} &
\multicolumn{1}{c|}{3} &
\multicolumn{1}{c|}{4} &
\multicolumn{1}{c|}{5} &
\multicolumn{1}{c|}{} &
\multicolumn{2}{c|}{\multirow{3}{*}{centered cell}} \\ \cline{6-10}
&
&
&
&
\multicolumn{1}{c|}{} &
\multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
\multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
\multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
\multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
\multicolumn{1}{c|}{\rotatebox[origin=c]{90}{abc}} &
\multicolumn{1}{c|}{} &
\multicolumn{2}{c|}{} \\ \cline{6-10}
&
&
&
&
&
\multicolumn{5}{c}{\thead[l]{some long text \\ more text}} & <- EDIT
\multicolumn{1}{c|}{} &
\multicolumn{2}{c|}{} \\ \cline{12-13}
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}
答案3
另一个建议:
如果您希望将表格分开,就像在 MWE 中给出的那样。您也可以将它们插入到节点中,然后将它们排列在 TIKZ 图片中。
\documentclass{article}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{tikz}
\renewcommand{\arraystretch}{1.4}
\begin{document}
\begin{tikzpicture}
\node (table1) {%
\begin{tabular}{c|l|r|}
\cline{2-3}
\multirow{5}{*}{\rotatebox[origin=c]{90}{some long text here}} & qwerty 1 & 1 \\
\cline {2-3}
& qwerty 2 & 2 \\
\cline {2-3}
& qwerty 3 & 3 \\
\cline {2-3}
& qwerty 4 & 4 \\
\cline {2-3}
& qwerty 5 & 5 \\
\cline{2-3}
\end{tabular}};
\node[right of =table1, xshift=2.5cm,yshift=-1.2pt] (table2) {%
\begin{tabular}{|r|r|r|r|r|}
\hline
1 & 2 & 3 & 4 & 5\\
\hline
1 & 2 & 3 & 4 & 5\\
\hline
1 & 2 & 3 & 4 & 5\\
\hline
1 & 2 & 3 & 4 & 5\\
\hline
1 & 2 & 3 & 4 & 5\\
\hline
\end{tabular}};
\node[right of =table2, xshift=2.5cm,yshift=8.6pt] (table3) {%
\begin{tabular}{|r|l|}
\hline
4 & text \\
\hline
3 & text text \\
\hline
2 & text text text \\
\hline
1 & text \\
\hline
\end{tabular}};
\node[above of =table2, yshift=-4.5cm] (table4) {%
\begin{tabular}{|r|r|r|r|r|}
\hline
1 & 2 & 3 & 4 & 5 \\
\hline
\rotatebox[origin=c]{90}{abc} & \rotatebox[origin=c]{90}{abc abc} & \rotatebox[origin=c]{90}{abc} & \rotatebox[origin=c]{90}{abc abc} & \rotatebox[origin=c]{90}{abc abc abc} \\
\hline
\multicolumn{5}{c}{long text here 2} \\
\end{tabular}};
\draw[thick](1.75,1.5) -- (1.75,-1.8);
\draw[thick](1.75,-1.8) -- (5.25,-1.8);
\end{tikzpicture}
\end{document}