# Hanging text in longtable

I used the solution offered in this post to have hanging indents within tables. This works fine with tabular. However, I now have to use a longtable. Here the first paragraph in each cell is not hanging anymore. I am not sure why.

Does anyone have a solution for this problem?

\documentclass[a4paper,
11pt,
BCOR=8.25mm,
DIV=11]{scrbook}

\usepackage{array}
\newcommand{\dohang}{\hangindent1em\hangafter1 }

\usepackage{booktabs}
\usepackage{longtable}

\begin{document}

\begin{longtable}[c]{
>{\everypar\expandafter{\the\everypar\dohang\everypar{\dohang}\raggedright\arraybackslash}\arraybackslash}p{.15\textwidth}
>{\everypar\expandafter{\the\everypar\dohang\everypar{\dohang}\raggedright\arraybackslash}\arraybackslash}p{.75\textwidth}}
\caption{Long table. } \\
\toprule

\multicolumn{2}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\toprule
\bottomrule
\multicolumn{2}{r}{\textit{Continued on next page}} \\
\endfoot
\bottomrule
\endlastfoot
\emph{Lorem ipsum dolor} &
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \par
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \par
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor  \\
&  \\
\emph{Lorem ipsum dolor} &
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \par
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \par
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
\end{longtable}

\begin{table}
\caption{Tabular. }
\begin{tabular}{
>{\everypar\expandafter{\the\everypar\dohang\everypar{\dohang}\raggedright\arraybackslash}\arraybackslash}p{.15\textwidth}
>{\everypar\expandafter{\the\everypar\dohang\everypar{\dohang}\raggedright\arraybackslash}\arraybackslash}p{.75\textwidth}}
\toprule
\emph{Lorem ipsum dolor} &
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \par
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \par
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor  \\
&  \\
\emph{Lorem ipsum dolor} &
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \par
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor \par
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
\end{tabular}
\end{table}

\end{document}


From what I think to see in the longtable source, at the start of the p{} entry a strut is inserted before the >{} code is executed. This happens in the macro \LT@startpbox. That means the paragraph has already started before the >{} code is done. Hence, the \everypar comes too late for the first paragraph. It can be compensated by adding a \dohang in the >{}.

In a normal tabular, at least in the array package, the strut is inserted through an \everypar. That's the reason for the \expandafter construction in \everypar, because that specific \everypar value has to be preserved. In a longtable this would not be necessary:

>{\everypar{\dohang}\dohang\raggedright\arraybackslash}


would do the job, as long as longtable isn't updated to conform to the array.sty way of doing it.

It seems to me that this is a kind of bug. What do you think, @DavidCarlisle?

• Many thanks. You are right. However, you have to add \dohang \raggedright to get the desired effect. Otherwise the text gets justified.
– phx
Oct 29 '16 at 16:10