![为什么使用 \everypar 的悬挂缩进会弄乱表格间距?](https://linux22.com/image/304373/%E4%B8%BA%E4%BB%80%E4%B9%88%E4%BD%BF%E7%94%A8%20%5Ceverypar%20%E7%9A%84%E6%82%AC%E6%8C%82%E7%BC%A9%E8%BF%9B%E4%BC%9A%E5%BC%84%E4%B9%B1%E8%A1%A8%E6%A0%BC%E9%97%B4%E8%B7%9D%EF%BC%9F.png)
我正在尝试为表格特定列的每个段落添加悬挂缩进:
\documentclass{article}
\usepackage{array}
\newcolumntype{R}{>{\everypar{\hangindent1em\hangafter1}\arraybackslash}m{3in}}
\usepackage[a4paper, total={7in, 9in}]{geometry}
\begin{document}
\begin{tabular}{|p{1.5in}|p{1.5in}|R|}\hline
first column & second column & first line of third column \newline This line is indented. \par This one is not, but if it goes on and on and eventually wraps, the next line is indented. \\\hline
etc. & etc. & etc. \\\hline
\end{tabular}
\end{document}
问题是,通过使用\everypar
,单元格顶部和文本之间的空间减少了,仅在具有悬挂缩进的单元格中:甚至第二行的第三个单元格看起来也很好。我该如何避免这种情况?
答案1
当一个p
(或m
)单元格启动时,\everypar
它不是空的,但它包含
\vrule\@height\ht\@arstrutbox\@width\z@\everypar{}
这是在段落开头插入支柱的代码。使用你的代码,你将删除它。
\documentclass{article}
\usepackage{array}
\newcommand{\dohang}{\hangindent1em\hangafter1 }
\newcolumntype{R}{%
>{\everypar\expandafter{\the\everypar\dohang\everypar{\dohang}}\arraybackslash}%
m{3in}%
}
\usepackage[a4paper, total={7in, 9in}]{geometry}
\begin{document}
\begin{tabular}{|p{1.5in}|p{1.5in}|R|}\hline
first column & second column &
first line of third column \newline
This line is indented. \par
This one is not, but if it goes on and on and eventually wraps,
the next line is indented. \\\hline
etc. & etc. & etc. \\\hline
\end{tabular}
\end{document}
另一种解决方案是使用 LaTeX 列表避免弄乱\hangindent
、\hangafter
和\everypar
。输出是相同的。
\documentclass{article}
\usepackage{array}
\newcommand{\dohang}{\hangindent1em\hangafter1 }
\newcolumntype{R}{%
>{\tablist}%
m{3in}%
<{\endtablist}%
}
\newenvironment{tablist}
{\list{}{%
\leftmargin=1em
\itemindent=-1em
\listparindent=-1em
\topsep=0pt
\parsep=0pt
\partopsep=0pt}\item[\strut]}
{\endlist\vspace{-\baselineskip}}
\usepackage[a4paper, total={7in, 9in}]{geometry}
\begin{document}
\begin{tabular}{|p{1.5in}|p{1.5in}|R|}\hline
first column & second column &
first line of third column \newline
This line is indented. \par
This one is not, but if it goes on and on and eventually wraps,
the next line is indented. \\\hline
etc. & etc. & etc. \\\hline
\end{tabular}
\end{document}