我有以下代码:
\documentclass{article}
\usepackage{amssymb}
\usepackage{caption,sansmath}
\usepackage{array}
\DeclareCaptionFont{sansmath}{\sansmath}
\captionsetup{textfont={sf,sansmath}}
\newlength\Origarrayrulewidth
% horizontal rule equivalent to \cline but with 2pt width
\newcommand{\Cline}[1]{%
\noalign{\global\setlength\Origarrayrulewidth{\arrayrulewidth}}%
\noalign{\global\setlength\arrayrulewidth{2pt}}\cline{#1}%
\noalign{\global\setlength\arrayrulewidth{\Origarrayrulewidth}}%
}
% draw a vertical rule of width 2pt on both sides of a cell
\newcommand\Thickvrule[1]{%
\multicolumn{1}{!{\vrule width 2pt}c!{\vrule width 2pt}}{#1}%
}
% draw a vertical rule of width 2pt on the left side of a cell
\newcommand\Thickvrulel[1]{%
\multicolumn{1}{!{\vrule width 2pt}c|}{#1}%
}
% draw a vertical rule of width 2pt on the right side of a cell
\newcommand\Thickvruler[1]{%
\multicolumn{1}{|c!{\vrule width 2pt}}{#1}%
}
% Square cells in the matrix, so we just increase the space between rows
\renewcommand{\arraystretch}{1.5}
\begin{document}
\begin{table}
\parbox{.45\linewidth}{
\centering
\begin{tabular}{ c |c|c|c|c|c|}
\multicolumn{1}{c}{~} & \multicolumn{1}{c}{$c_{1}$} & \multicolumn{1}{c}{$c_{2}$} & \multicolumn{1}{c}{$c_{3}$} & \multicolumn{1}{c}{$c_{4}$} & \multicolumn{1}{c}{$c_{5}$} \\ \cline{2-6}
$r_{1}$ & 2 & 8 & 4 & 5 & 3 \\ \cline{2-6}
$r_{2}$ & 4 & 9 & 6 & 7 & 1 \\ \cline{2-6}
$r_{3}$ & 3 & 4 & 2 & 0 & 9 \\ \cline{2-6}
$r_{4}$ & 1 & 0 & 9 & 8 & 4 \\ \cline{2-6}
$r_{5}$ & 8 & 3 & 7 & 6 & 5 \\ \cline{2-6}
\end{tabular}
\caption{}
}
\hfill
\parbox{.45\linewidth}{
\centering
\begin{tabular}{ c |c|c|c|c|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-2}\cline{2-6}
1 & \Thickvrule{\hspace{0.8em}} & \hspace{0.8em} & \hspace{0.8em} & \hspace{0.8em} & \hspace{0.8em} \\ \Cline{2-3}\cline{3-6}
2 & \hspace{0.8em} & \Thickvrule{~} & \hspace{0.8em} & \hspace{0.8em} &\hspace{0.8em} \\ \cline{2-3}\Cline{3-4}\cline{4-6}
3 & \hspace{0.8em} & \hspace{0.8em} & \Thickvrule{\hspace{0.8em}} & \hspace{0.8em} & \hspace{0.8em} \\ \cline{2-4}\Cline{4-5}\cline{6-6}
4 & \hspace{0.8em} & \hspace{0.8em} & \hspace{0.8em} & \Thickvrule{\hspace{0.8em}} & \hspace{0.8em} \\ \cline{2-5}\Cline{5-6}
5 & \hspace{0.8em} & \hspace{0.8em} & \hspace{0.8em} & \hspace{0.8em} & \Thickvrule{\hspace{0.8em}} \\ \cline{2-6}\Cline{6-6}
\end{tabular}
\caption{}
}
\end{table}
\end{document}
该代码是从这里复制的:
代码是正确的。当我尝试使用该pdfpages
包时,没有显示粗水平线。请问原因是什么?当我删除此包时,该线成功显示。我的文章中有很多矩阵,我无法删除它们或重写它们,但我还必须在文档末尾添加附录。
重新定义 \setlength 后出现错误:
! Missing number, treated as zero.
<to be read again>
(
l.1584 \includepdf[pages=-]{nosingl1.pdf}
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
! Illegal unit of measure (pt inserted).
<to be read again>
(
l.1584 \includepdf[pages=-]{nosingl1.pdf}
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type `2' to delete
two letters. (See Chapter 27 of The TeXbook.)
如果我不重新定义它,代码编译成功,即当我包含pdf文件时发生编译错误:
\includepdf[pages=-]{nosingl1.pdf}
\includepdf[angle=90]{nosingl2.pdf}
\includepdf[angle=90]{nosingl3.pdf}
答案1
使用 TeX 样式的长度设置似乎可以解决这个问题,否则长度设置仍然是本地的:
% horizontal rule equivalent to \cline but with 2pt width
\newcommand{\Cline}[1]{%
\noalign{\global\Origarrayrulewidth\arrayrulewidth%
\global\arrayrulewidth2pt}\cline{#1}%
\noalign{\global\arrayrulewidth\Origarrayrulewidth}%
}
正如 PolGab 在评论中提到的那样,这种互动源于calc
(加载者pdfpages
)重新定义\setlength
。恢复原始\setlength
命令(后加载pdfpages
或calc
)至
\def\setlength#1#2{#1#2\relax}%
也解决了这个问题。不过不确定是否有其他副作用。
答案2
问题主要在于
\global\setlength
是不是由 LaTeX 正式支持,事实上,它以一种完全无效的方式calc
重新定义,因为它适用于临时变量(正是如此,其中是的参数)。setlength
\global\setlength
\global
\global\let\calc@A #1
#1
\setlength
简单写
\newcommand{\Cline}[1]{%
\noalign{\xdef\Origarrayrulewidth{\the\arrayrulewidth}}%
\noalign{\global\arrayrulewidth=2pt}\cline{#1}%
\noalign{\global\arrayrulewidth=\Origarrayrulewidth}%
}
这也避免了分配\Origarrayrulewidth
维度。
\setlength
加载后重新定义pdfpages
当然是不是值得推荐,因为这个包做依赖\setlength
于 的定义calc
。