5

I wonder why \parskip is zero inside the tabular environment.

How can i make the paragraphs to be equally vertically spaced inside the tabular environment, just like outside the tabular?

I know about \@parboxrestore and \@minipagerestore, but could not find a reference to fix this inside \begin{tabular}.

\documentclass{article}

\usepackage{array}
\setlength{\parindent}{0mm}
\setlength{\parskip}{8pt}

\begin{document}

\textbf{par inside tabular}

\begin{tabular}{|>{\raggedright}p{8cm}|} \hline Lorem ipsum dolor sit amet. \par{} Lorem ipsum dolor sit amet. \par{} Lorem ipsum dolor sit amet. \tabularnewline \hline \end{tabular}

\textbf{par outside tabular}

Lorem ipsum dolor sit amet. \par{} Lorem ipsum dolor sit amet. \par{} Lorem ipsum dolor sit amet.

\end{document}

Leads to the following result:

Example

Kaii
  • 406

2 Answers2

4

Actually, minipage and \parbox reset \parskip to 0pt, so you will have to reset it inside. While in this case we know \parskip=8pt, in general that will not be true.

\documentclass{article}

\usepackage{array}
\setlength{\parindent}{0mm}
\setlength{\parskip}{8pt}
\newlength{\oldparskip}

\begin{document}

\textbf{par inside tabular}

\oldparskip=\parskip
\begin{tabular}{|>{\raggedright\parskip=\oldparskip}p{8cm}|}
\hline 
Lorem ipsum dolor sit amet.
\par
Lorem ipsum dolor sit amet.
\par
Lorem ipsum dolor sit amet.
\tabularnewline
\hline 
\end{tabular}

\end{document}

reset parskip

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • \let\myparskip\parskip will not save the value of \parskip. One can definitely have more than one paragraph in a \parbox, why not? – egreg Nov 20 '15 at 17:17
  • @egreg - Thanks, learn something every day. When I used \parbox in the revised solution, \par did nothing, although it works fine outside tabular. – John Kormylo Nov 20 '15 at 17:38
  • Thanks but it seems that this solution causes some new problems - in your screenshot you see the first and last line are offset and collide with the table border. Is there some way to achieve without using parbox or minipage? – Kaii Nov 20 '15 at 22:02
  • why use a minipage here rather than just a normal p column? – David Carlisle Nov 21 '15 at 00:41
  • 2
    >{\begin{minipage}{8cm}\raggedright\parskip=8pt}{c}<{\end{minipage}} could more simply (and better vertical spacing) be >{\raggedright\parskip=8pt}p{8cm} – David Carlisle Nov 21 '15 at 00:48
  • @David Carlisle - If I had known it would be that simple,I wouldn't have bothered. – John Kormylo Nov 21 '15 at 01:03
4

A p column is essentially identical to a \parbox. In both cases they use \@arrayparboxrestore to normalise several things. If you don't want parskip and parindent normalized but left as in the main document just redefine the command not to reset them:

enter image description here

\documentclass{article}

\usepackage{array}
\setlength{\parindent}{0mm}
\setlength{\parskip}{8pt}

\makeatletter
\def\@arrayparboxrestore{%
  \let\if@nobreak\iffalse
  \let\if@noskipsec\iffalse
  \let\par\@@par
  \let\-\@dischyph
  \let\'\@acci\let\`\@accii\let\=\@acciii
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  \parindent\z@ \parskip\z@skip
  \everypar{}%
  \linewidth\hsize
  \@totalleftmargin\z@
  \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip
  \parfillskip\@flushglue \lineskip\normallineskip
  \baselineskip\normalbaselineskip
  \sloppy}
\makeatother
\begin{document}

\textbf{par inside tabular}

\begin{tabular}{|>{\raggedright}p{8cm}|}
\hline 
Lorem ipsum dolor sit amet.
\par
Lorem ipsum dolor sit amet.
\par
Lorem ipsum dolor sit amet.
\tabularnewline
\hline 
\end{tabular}

\textbf{par outside tabular}

Lorem ipsum dolor sit amet.
\par{}
Lorem ipsum dolor sit amet.
\par{}
Lorem ipsum dolor sit amet.

\end{document}
David Carlisle
  • 757,742
  • While this is the technically most correct and most generic answer, i prefer the other solution. I wonder if overwriting \@arrayparboxrestore may cause new problems, i.e. with packages that depend on their own version of \@arrayparboxrestore. – Kaii Nov 24 '15 at 18:17
  • @Kali I would be inclined to do something like \NewCommandCopy{\old@arrayparboxrestore}{\@arrayparboxrestore} followed by \RenewDocumentCommand{\@arrayparboxrestore}{}{\old@arrayparboxrestore\parskip 8pt} which would alleviate your concerns. – Don Hosek Jul 29 '21 at 00:34