etoolbox
我正在尝试制作一个与带有's 的单倍行距文本宽度一样宽的表格\AtBeginEnvironment
,但这会以某种方式摆脱\noindent
我之前发布的。
\documentclass{report}
\usepackage{array,setspace,booktabs,tabularx,etoolbox}
\AtBeginEnvironment{tabularx}{\singlespacing\renewcommand{\arraystretch}{1.3}}
\usepackage{lipsum}
\begin{document}
\lipsum[1-2]
\noindent
\begin{tabularx}{\linewidth}{ @{} p{3em} X @{} }
\toprule
Table & Example \\
Table & Example \\
\bottomrule
\end{tabularx}
有什么办法可以修复它吗?
答案1
\singlespacing
忽略使用\noindent
。如果您想将内容插入为`tabularx,将其重新定义为新环境的一部分:
\documentclass{article}
\usepackage{setspace,tabularx,lipsum}
\let\oldtabularx\tabularx
\let\endoldtabularx\endtabularx
\renewenvironment{tabularx}[2]
{\singlespacing
\noindent
\oldtabularx{#1}{#2}}% https://tex.stackexchange.com/a/42331/5764
{\endoldtabularx}
\begin{document}
\doublespacing
\lipsum[1]
\begin{tabularx}{\linewidth}{ @{} p{3em} X @{} }
\hline
Table & Example \\
Table & Example \\
\hline
\end{tabularx}
\end{document}