# singlespacing in table with no indent

I'm trying to make a table that is as wide as the textwidth singlespaced with etoolbox's \AtBeginEnvironment but that somehow gets rid of the \noindent that I issued before.

\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}


Any idea how to fix that?

• Your issuing of \singlespacing the \arraystretch redefinition comes too late anyway. – Werner Dec 4 '16 at 19:27
• @Werner Hmm, it does do it though, I mean the spacing. Only the indent. When I don't use etoolbox it's fine but where would I issue the singlespacing then? – jan Dec 4 '16 at 19:32
• Is the rest of your document not \singlespacing? – Werner Dec 4 '16 at 19:41
• @Werner Yeah, the rest is doublespaced, sorry, I didn't put that in the MWE (it's in the class) – jan Dec 4 '16 at 19:42
• Even if you use \noindent\singlespacing the indent appears. You can put \singlespacing\noindent to again force a \noindent. – Werner Dec 4 '16 at 19:44

\singlespacing ignores the use of \noindent. If you want to insert content as part of tabularx, redefine it as part of a new environment:

\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}
`