![为什么在行尾添加 \\[...] 会搞乱对齐?](https://linux22.com/image/353160/%E4%B8%BA%E4%BB%80%E4%B9%88%E5%9C%A8%E8%A1%8C%E5%B0%BE%E6%B7%BB%E5%8A%A0%20%5C%5C%5B...%5D%20%E4%BC%9A%E6%90%9E%E4%B9%B1%E5%AF%B9%E9%BD%90%EF%BC%9F.png)
我试图回复原帖的评论我的这个答案但我发现当我把它放在[...]
一行末尾时它会弄乱水平对齐。
\documentclass{book}
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\usepackage{arydshln}
\begin{document}
\renewcommand{\arraystretch}{2.2}
Without space added:
\begin{tabular}{|M{.7cm}|}
\hline
$y$ \\
\hdashline
$a$ \\
\hdashline
$b$ \\
\hline
\end{tabular}
\vspace{10pt} with space added:
\begin{tabular}{|M{.7cm}|}
\hline
$y$ \\[2ex]
\hdashline
$a$ \\
\hdashline
$b$ \\
\hline
\end{tabular}
\end{document}
查看的位置y
:
我究竟做错了什么?
答案1
问题在于数学后面的空格。arydshln
重新定义内部命令(在本例中\@xargarraycr
)并忘记了\unskip
原始定义:
\documentclass{book}
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{arydshln}
\usepackage{etoolbox}
\begin{document}
\renewcommand{\arraystretch}{2.2}
\begin{tabular}{|M{.7cm}|}
\hline
$y$ \\[2ex]
\hdashline
$a$ \\
\hline
\end{tabular}
\begin{tabular}{|M{.7cm}|}
\hline
$y$\\[2ex] %no problem without the space
\hdashline
$a$ \\
\hline
\end{tabular}
\makeatletter
\pretocmd\@xargarraycr{\unskip}{}{\fail} %patch to add \unskip
\begin{tabular}{|M{.7cm}|}
\hline
$y$ \\[2ex]
\hdashline
$a$ \\
\hline
\end{tabular}
\end{document}