![為什麼在行末尾添加 \\[...] 會擾亂對齊?](https://rvso.com/image/353160/%E7%82%BA%E4%BB%80%E9%BA%BC%E5%9C%A8%E8%A1%8C%E6%9C%AB%E5%B0%BE%E6%B7%BB%E5%8A%A0%20%5C%5C%5B...%5D%20%E6%9C%83%E6%93%BE%E4%BA%82%E5%B0%8D%E9%BD%8A%EF%BC%9F.png)
我試圖回覆OP的評論我的這個答案但我發現當我放在[...]
一行的末尾時,它會擾亂水平對齊。
\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}