0

I'm trying to include equations in a table, I know I need to use minipage to do so. But for some reason it is creating a gap between where the row would usually start and where it does when I include the minipage/math combination.

I have tried using abovedisplayskip to no avail. As well as trimbox and raisebox, both of which succeeded in shifting the equations higher but the text in the first two columns was still offset.

I have the same issue occur with subequations, but the gap is even larger.

Does anyone know why this is happening and/or how to fix it?

\documentclass{article}

\usepackage{xcolor, colortbl}
\usepackage{array,booktabs,tabularx,rotating,amsmath}

\begin{document}
    \begin{sidewaystable}          
        \begin{tabularx}{\textwidth}{X>{$}>{\raggedright\arraybackslash}p{3cm}<{$}l}
        \toprule
        \textbf{Section}  & \textbf{Variables}  & \multicolumn{1}{c}{\textbf{Constraints}}  \\
        \midrule        
        Section 1  & (0 \le a \le 100)\newline
                     (0 \le b \le 100)  &   \begin{minipage}{13cm}
                                                \begin{gather} 
                                                    a+b \ge 42 \\
                                                    a \ge 11
                                                \end{gather}
                                          \end{minipage}\\
        \rowcolor{gray!50}
        Section 2 & (0 \le c \le 100) \newline
                    (0 \le d \le 100) &\begin{minipage}{13cm}
                                            \begin{subequations}                                                    
                                                \begin{gather} 
                                                    \text{Given a bunch of stuff define:} \notag \\                                                        
                                                    \sum_{\mathclap{\substack{a bunch of really\\long stuff}}} (a*d)\\
                                                    c=d                                                          
                                                \end{gather}                                                
                                        \end{subequations}
                                    \end{minipage}\\
             Usually & there & is no vertical space\\
            \bottomrule
        \end{tabularx}     
    \end{sidewaystable}
\end{document}

enter image description here

This is how I would like the table to be aligned. (This was done by putting the the minipage on a separate row and then using raisebox to lift it into place. But this feels very hacky, there must be an actual way to specify the alignment.) enter image description here

Adriala
  • 145
  • 1
  • 8
  • Putting an \fbox{} around the minipage shows that the extra line is inside. I can't figure out where it comes from, though. – John Kormylo Aug 24 '16 at 03:57
  • I believe the gather is what is causing the line. Ah, I only added abovedisplayskip not the short version too. though that still isn't helping. Regardless of where the minipage/gather appears (I can adjust them using boxes) the first two columns are no longer aligned at the top of their cells, like they usually would be, even given a multiline cell. – Adriala Aug 24 '16 at 04:17
  • Why can't you use \mathclap with inline maths? – Bernard Aug 24 '16 at 09:19
  • 1
    this answer is relevant to all multi-line display environments defined by amsmath. – barbara beeton Aug 24 '16 at 13:04
  • @Bernard huh, mathclap was giving me an error before. Strange. The subequation thing still stand though. – Adriala Aug 24 '16 at 14:00
  • @barbarabeeton that does fix the position of the minipage, but the text in the first two columns still has the gap. – Adriala Aug 24 '16 at 14:01
  • 1
    what if you use the position option: \begin{minipage}[t]{...} ? my guess is that the extra "height" on the other columns may be caused by the vertical centering of the minipage. – barbara beeton Aug 24 '16 at 14:40
  • @barbarabeeton Hmm that combination is closer. The equations are still slightly lower (by about half a line), do you know if i can modify what was at the link to lift it a bit more? (I understand the theory of it but no clue about how/why it actually works or how I'd modify it) – Adriala Aug 24 '16 at 14:46
  • \fbox now shows the absolute top of the minipage to be even with the baseline. Putting the minipage inside\raisebox{.4\normalbaselineskip}{...} appears about right. – John Kormylo Aug 24 '16 at 15:04
  • @JohnKormylo Awesome! Thankyou. Would either you or Barbara like to post an answer so I can accept it? (If not I'll do one myself in the morning) – Adriala Aug 24 '16 at 15:11
  • Instead of the \raisebox, you can add another \kern-0.4\normalbaselineskip to the \start@gather fix. – John Kormylo Aug 24 '16 at 15:14
  • @JohnKormylo POkay so it worked.... But when I tried to turn them into environments the subequation one broke, IF it has a label. If I don't give the subequation a label it aligns perfectly, as soon as I do it moves down again. This ONLY happens in the new environment WITH a label though. – Adriala Aug 24 '16 at 16:18
  • Try \label{name}% to prevent adding extra spaces or lines. – John Kormylo Aug 24 '16 at 21:06

1 Answers1

0

@barbarabeeton @JohnKormylo Thank-you for the assistance to answering this question.

The answer to this post explained why the minipage/math environment combination caused a gap (the etoolbox \kern part). Specifying the minipage placement [t] the corrected the alignment of the first two columns. an additional .4/normalbaselineskip was also added to the \kern adjustment to remove the remaining space above the equation.

\documentclass{article}

\usepackage{xcolor, colortbl}
\usepackage{array,booktabs,tabularx,rotating,amsmath}
\usepackage{adjustbox}
\usepackage{amsthm}
\usepackage{mathtools}

\usepackage{etoolbox}
\makeatletter
\pretocmd\start@gather{%
    \if@minipage\kern-\topskip\kern-\abovedisplayskip\kern-.4\normalbaselineskip\fi
}{}{}
\makeatother

\begin{document}
    \begin{sidewaystable}          
        \begin{tabularx}{\textwidth}{X>{$}>{\raggedright\arraybackslash}p{3cm}<{$}l}
            \toprule
            \textbf{Section}  & \textbf{Variables}  & \multicolumn{1}{c}{\textbf{Constraints}}  \\
            \midrule        
            Section 1  & (0 \le a \le 100)\newline
                         (0 \le b \le 100)  &   \begin{minipage}[t]{13cm}
                                                    \begin{gather} 
                                                        a+b \ge 42 \\
                                                        a \ge 11
                                                    \end{gather}
                                              \end{minipage}\\
            \rowcolor{gray!50}
            Section 2 & (0 \le c \le 100) \newline
                        (0 \le d \le 100) & \begin{minipage}[t]{13cm}
                                                \begin{subequations}   \label{broke}                                                 
                                                    \begin{gather} 
                                                        \text{Given a bunch of stuff define:} \notag \\                                                        
                                                        \sum_{\mathclap{\substack{a bunch of really\\long stuff}}} (a*d)\\
                                                        c=d                                                          
                                                    \end{gather}                                                
                                            \end{subequations}
                                        \end{minipage}\\            
            Usually & there \newline is \newline no & space\\
                \bottomrule
            \end{tabularx}     
        \end{sidewaystable}
\end{document}
Adriala
  • 145
  • 1
  • 8