5

Following up this question:

How to keep a constant baselineskip when using minipages (or \parboxes)?

The answers to the question suggest that \strut is not perfect to space minipages well with regard to the following line. They suggest a combination of the commands \par\xdef\tpd{\the\prevdepth} (within the minipage) and \prevdepth\tpd (outside the minipage).

However, the suggested solution is not working in tables, because \prevdepth\tpd needs to be written in a separate spaced-out line to work:

...
\par\xdef\tpd{\the\prevdepth}   
\end{minipage}

\prevdepth\tpd
...

The command would not allow me to use \\ instead of an empty line. However, the tabular-environment needs the \\ to separate the lines.

I tried

\begin{tabular}[t]{p{0.2 \linewidth}p{0.2 \linewidth}}
    lipsum & %
    \begin{minipage}[t]{\linewidth}
        lipsum\\lipsum
        \par\xdef\tpd{\the\prevdepth} 
    \end{minipage}\par
    \prevdepth\tpd 
    lipsum & lipsum
\end{tabular}

and similar things. I either get a compilation error from \prevdepth\tpd or from the tabular's missing \\. If I use an empty line and \\, I get an extra unwanted line break.

Is there a way to get this solution to work?

Edit: As requested, a full example

\documentclass[fontsize=11pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}
\setlength{\tabcolsep}{0pt}
\setlength{\parskip}{0pt}
\setlength{\parindent}{0pt}

\begin{tabular}[t]{p{0.2 \linewidth}p{0.2 \linewidth}}
lipsum & %
 \begin{minipage}[t]{\linewidth}lipsum\\libsum
 \end{minipage}\\ 
lipsum & lipsum
\end{tabular}
lipsum
\end{document}

Output without fix

Using the spacing command as suggested above I get this: Output with fix

This close to the desired output, but comes at the cost of a compilation error (because of the missing line separator \\ in the table).

  • Can you add a full example (without the settings related to \prevdepth), just to see what's the alignment you want to fix? – egreg May 4 '15 at 15:31
  • It's not clear the reason for wanting a minipage, as already a p column makes it. – egreg May 4 '15 at 17:39
  • The reason for the minipage is the need for an itemize inside the table, for which you need the minipage. The itemize is not needed to show the problem, so I did not include it in the example. – Coolkau May 4 '15 at 17:57
3

You don't need a minipage in order to have an itemize or enumerate in a p column: just issue \@minipagetrue inside it.

\documentclass[fontsize=11pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{enumitem}
\makeatletter
\newcolumntype{P}[1]{>{\@minipagetrue}p{#1}}
\makeatother

\begin{document}

\begin{tabular}{|P{0.2 \linewidth}|P{0.2 \linewidth}|}
\hline
lipsum & 
\begin{itemize}
\item A
\item B
\end{itemize}
lipsum \\
\hline
lipsum & lipsum\\
\hline
\end{tabular}

\bigskip

\begin{tabular}{|P{0.2 \linewidth}|P{0.2 \linewidth}|}
\hline
lipsum & 
\begin{itemize}[nosep]
\item A
\item B
\end{itemize}
lipsum \\
\hline
lipsum & lipsum\\
\hline
\end{tabular}

\end{document}

I added the rules just for better showing the various cells, not because I endorse their usage.

enter image description here

  • This is pretty nice, I did not know that. I only found the version including a minipage on the internet. However, if I want to start a new line after the itemize I also have and extra line between the itemize and the next line and I also have to shift it up by one line using the \\[-bst] trick from above. Never the less it saves my quite a few lines of code. – Coolkau May 4 '15 at 18:38
0

I found a rather sloggish answer to my question. I hope there will be a better one, but it works.

\documentclass[fontsize=11pt]{scrartcl}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\newlength{\bls}

\begin{document}
\setlength{\bls}{\baselineskip}
\begin{tabular}[t]{p{0.2 \linewidth}p{0.2 \linewidth}}
    lipsum & %
    \begin{minipage}[t]{\linewidth}
        lipsum\\lipsum
        \par\xdef\tpd{\the\prevdepth} 
    \end{minipage}

    \prevdepth\tpd\\[\-bls]
    lipsum & lipsum
\end{tabular}

\end{document}

As mentioned above I can get the code to work on the cost of gaining an extra line. I can then shift the text upwards one line by using \\[-\bsl]. For some reason it would not let me use \\[-\baselineskip] directly to shift the text upwards while I can use \\[\baselineskip]to shift the text one line downwards. Instead I need to define a new length outside the tabular. Only then both up and down shifting work as they should. (My latex skills are not good enough to know why this is the case.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.