0

I have the following code :

\NewDocumentCommand\splitpage{O{0.5} m m O{0.05}}
{ \FPeval\otherlen{1-#1} \FPeval\adjustedlen{\otherlen+#4} 
\adjustbox{valign=t} 
    {\begin{minipage}{#1\textwidth} #2 \end{minipage}\hfill } 
\adjustbox{valign=t,right=\adjustedlen\textwidth}
    {\begin{minipage}{\otherlen\textwidth}#3\end{minipage}} \bigskip}

Which basically splits a page in half, and uses optional parameters (xparse) and adjustbox to get what is in the two minipages to vertically align.

It works very well when I use text, equations, plots (TikZ), etc., and it also works fine with tabular, but it just spits out reams of overflow warnings, even when it looks fine visually :

\begin{example}{
        \splitpage[0.35]{
            Given the information on the right. Is there a correlation between
            preferences for vegetables between the husband and wife? That is to say do
            they like or dislike similar vegetables?
        }
        {
            \begin{tabular}{@{}c|cccc@{}}
                & Husband & Wife & D & $D^2$ \\
                Brocolli & 4 & 3 & 1 & 1 \\
                Cauliflower & 3 & 1 & 2 & 4 \\
                Brussel Sprouts & 6 & 7 & -1 & 1 \\
                Okra & 1 & 2 & -1 & 1 \\
                Cabbage & 5 & 5 & 0 & 0 \\
                Spinach & 2 & 4 & -2 & 4 \\
                Turnips & 7 & 6 & 1 & 1 \\
            \end{tabular}
        }[0.1]
    }
        \vspace{-0.5cm}
        \begin{mstep}{Calculate $r_s$}
        r_s &=&1-\dfrac{6\sum D^2}{N(N^2-1)} \\
                &=&1-\dfrac{6 * 12}{7(48-1)} \\
                &=&0.79
        \end{mstep}
    \begin{istep}{Compare to critical values}
        As 0.79 is equal to the critical value (0.786, Appendix C) 
        the null hypothesis $H_0$ that $\rho=0$ is rejected and there is
        a strong positive correlation between the husband and wife's preferences.
    \end{istep}

\end{example}

With some definitions :


\newcounter{stepnumber}

\NewDocumentEnvironment{example}{m} { \begin{tcolorbox} \setcounter{stepnumber}{1} \textbf{Example} : #1\\smallskip } {\end{tcolorbox}}

\NewDocumentEnvironment{mstep}{m} {\noindent Step # \thestepnumber : #1\begin{eqnarray}} {\end{eqnarray}\stepcounter{stepnumber}\vspace{-0.5cm}}

\NewDocumentEnvironment{istep}{m} {\noindent Step # \thestepnumber : #1\begin{adjustwidth}{1cm}{1cm}} {\end{adjustwidth} \stepcounter{stepnumber}}

I have tried a number of the solutions here :

Overfull \hbox warning when using tabular

-use the @{} in the tabular setup -setting the width in adjustbox, etc. -using resizebox around the tabular (and even miniage) to shrink them to barely visible and it still generates the same warnings

But it looks like tabular has a bunch of floating space around it I can't see which is going outside the margins or width inside the mini-page.

If there are better solutions to to the hacky editing above, aside from somehow getting rid of the overfull issues, suggestions are appreciated.

tabular gone wild

Here is a stripped down example where I deconstructed the \splitpage :

\documentclass{report}
\usepackage[left=2cm,right=1cm,top=1cm,bottom=2cm]{geometry} 
\usepackage{adjustbox,xparse}
\setlength{\parindent}{0mm}

\begin{document}

\begin{minipage}{0.5\textwidth} Given the following data listing 183 children with ODD and ADHD, is there a correlation? \end{minipage}\hfill \begin{minipage}{0.5\textwidth} {\begin{tabular}{@{}ccc@{}} & \multicolumn{2}{c}{ODD}\ & No & Yes \ \hline
ADHD & $110^a$ & $19^b$\ & $22^c$ & $32^d$\ \end{tabular}} \end{minipage}

\vspace{3.0cm}

\adjustbox{valign=t}{ \begin{minipage}{0.5\textwidth} Given the following data listing 183 children with ODD and ADHD, is there a correlation? \end{minipage}\hfill } \adjustbox{valign=t,width=0.5\textwidth, right=0.8\textwidth}{ \begin{minipage}{0.5\textwidth} \begin{tabular}{@{}ccc@{}} & \multicolumn{2}{c}{ODD}\ & No & Yes \ \hline
ADHD & $110^a$ & $19^b$\ & $22^c$ & $32^d$\ \end{tabular} \end{minipage} }

\end{document}

The first one is fine, the second is what is generating the warnings, the \adjustbox which is used to right align the tabular. This works fine with images, equations, etc. but not with tabular.

stripped

  • 1
    you make it very hard for anyone to test your code as you have posted disconnected fragments rather than a test file. But you are adding a lot of white space in addition to the table. – David Carlisle Aug 17 '20 at 19:11
  • 1
    you could measure the width of the tabular by putting it into a savebox. – John Kormylo Aug 17 '20 at 19:54
  • It doesn't even seem to be the tabular itself, I used a resize box around the tabular and shrunk it even to extremes with 0.1\textwidth and you could barely see the table, it was no where near anything and had the exact same overfull warnings. – Cliff Stamp Aug 17 '20 at 22:12
  • Use \setlength\overfullrule{2pt} so overfull boxes will be visibly flagged in the output. Use \showboxdepth=3 \showboxbreadth=30 to identify which boxes are overfull from the log file. – Donald Arseneau Aug 18 '20 at 00:08
  • Thanks, I did that, but it only make it clear it was in that section which I knew. What I don't know is why tabular is generating those warnings. I added a MWE, but all the ones I have with tabular inside the \adjustbox all do the same. – Cliff Stamp Aug 18 '20 at 13:57

1 Answers1

0

I managed to find a solution which is really hacky, this can't be the way you are supposed to do it :

\begin{example}{
        \splitpage[0.4]{
            Police officers who have been exposed to stressful situations were
            encouraged to enter into psychotherapy and
            assessed for their stress levels before and after three 
            sessions to determine whether a new type of
            brief psychotherapy was successful. The employees
            stress was measured by standardized $T$ stress scores where
            higher values indicate higher stress.  } {
            \begin{adjustwidth}{1cm}{1cm}
                \begin{tabular}{@{}c|ccr@{}}
                    Employee & Before & After & D \\
                    \hline
                    \#1 & 68 & 63 & 5 \\
                    \#2 & 58 & 60 & -2 \\
                    \#3 & 74 & 65 & 9 \\
                    \#4 & 55 & 62 & -7 \\
                    \#5 & 81 & 54 & 27 \\
                    \#6 & 59 & 73 & -14 \\
                    \#7 & 47 & 45 & 2 \\
                    \#8 & 75 & 73 & 3 
                \end{tabular}
        \end{adjustwidth}
        }[0.15]
    }
    \splitpage[0.5]{
    \begin{mstep}{Calculate $t$}
        t&=&\dfrac{\overline{x}_1-\overline{x}_2}
        {\sqrt{\dfrac{\sum D^2-\dfrac{(\sum D)^2}{N}}{N(N-1)}}} \\
        &=&\dfrac{62.625-61.875}
        {\sqrt{\dfrac{1092-\dfrac{22^2}{8}}{8(8-1)}}} \\
        &=& 0.641
    \end{mstep}
    }{
    \begin{mstep}{Calculate $r$}
        r=&=& \dfrac{t^2}{t^2+df} \\
        &=& \dfrac{0.641^2}{0.641^2+7} \\
         &=& 0.235
    \end{mstep}
}[0.05]
\begin{istep}{Interpret Results}
    \begin{itemize}
        \item The null hypothesis that $\mu_1 = \mu_2$ is rejected on the critical
            $t$ value of $\pm 2.365$, with $p=0.05$ and $df=7$, therefore there was
            no significant reduction in stress by the therapy as the $t$ value here
            (0.641) is far less than that value.

        \item However, examining the effect size $r$ it is found that is it just
            under a medium effect (the tolerance for medium is $r \le 0.243$). 

        \item If the therapy is inexpensive the police department may choose to do
            it because of the effect size (and the fact there is no obvious
            harm/risk) however replication is surely needed.
    \end{itemize}
\end{istep}

\end{example}

with :

\NewDocumentCommand\splitpage{O{0.5} m m O{0.00}} {
    \FPeval\otherlen{0.99-#1-#4} 
\adjustbox{valign=t,frame,width=#1\textwidth} 
    {\begin{minipage}{#1\textwidth} #2 \end{minipage}} 
    \adjustbox{valign=t,frame,width=\otherlen\textwidth,center=\otherlen\textwidth} 
    {\begin{minipage}{\otherlen\textwidth} #3 \end{minipage}} \bigskip}

So the solution was :

  • adjust from 0.99 vs 1 to avoid an inner clash with the adjustbox (?)
  • provide another parameter to adjust the width of the second adjust box
  • use adjustwidth to move the second minipage to the right if necessary

This seems a really clumsy way to basically :

  • in some environment, which may be inside of a not-full textwidth
  • create two minipages
  • align them vertically
  • make one left aligned and the other right aligned
  • give a fixed width for one, and have the other width calculated

It got tangly at parts because I was doing this :

\NewDocumentCommand\splitpage{O{0.5} m m O{0.00}} {
    \FPeval\otherlen{0.99-#1-#4} 
\adjustbox{valign=t,frame,width=#1\textwidth} 
    {\begin{minipage}{#1\textwidth} #2 \end{minipage}} 
    \adjustbox{valign=t,frame,width=\otherlen\textwidth,center=\otherlen\textwidth} 
    {#3} \bigskip}

Removing the second minipage, and that worked for almost everything, but it broke when I tried to use aligned equations on the right hand side, no idea why they need a minipage. I also tried tabular, multicols, etc. but could not get them to work out neatly. Anyway, there has to be better solutions to do that, as the above solution while works is UGLY and you have to hard code in adjustboxes sometimes, and the amount you have to adjust. There has to be a way to have Tex basically do something like :

  1. calculate the width remaining of the current environment
  2. calculate the width of the second minipage based on the first one
  3. left align the first one (that's the default behavior)
  4. align both vertically
  5. flush the second minipage to the right

I have no idea how to do #1, I can do #2 (fp) and #3 happens naturally, and #4 using adjustbox seems simple, no idea on #5. There is a right option in adjustbox but all that does it ram the entire box to the right, not the contents.

And here is a little better but still hacky solution :

\NewEnviron{astep}[1] {
    Step \# \thestepnumber : #1
    \begin{flalign*}
        \BODY
    \end{flalign*}
    \stepcounter{stepnumber}
    \vspace{-0.5cm}
}

\NewDocumentCommand\splitpage{O{0.5} m m O{0.00}} { \FPeval\otherlen{0.99-#1-#4} \adjustbox{valign=t,width=#1\textwidth} {\begin{minipage}{#1\textwidth} #2 \end{minipage}} \adjustbox{valign=t,width=\otherlen\textwidth,center=\otherlen\textwidth} {\begin{minipage}{\otherlen\textwidth} \begin{flushright} #3\end{flushright} \end{minipage}} \bigskip}

The flushright seems to eliminate the hacks on the tabular, and the flalign* allows equations to flush l or r depending on how you put in the & .


\begin{example}{
    \newsplit[0.4]{Given the results of the following on a total of 20 participants
    use an ANOVA and $\omega^2$ to analysis and interpret the data and reach a
    conclusion.
    }
    {
        \begin{tabular}{rrrr}
            Placebo & 100 mg & 250 mg & 500 mg\\
            \hline
                            8& 7&   7&  4\\
                            9& 9&   6&  5\\
                            6& 8&   8&  6\\
                            9& 10&  7&  5\\
                            9& 8&   9&  7\\
        \end{tabular}
    }[0.15]
}
    \vspace{-0.25cm}
\splitpage[0.5]{
    \begin{step}{Calculate $F$}
        \begin{flalign*}
            F&= \dfrac{\text{SSB}/(k-1)}{\text{SSW}/(N-k)} &\\
             &= \dfrac{28.150/(4-1)}{22.4/(20-4)} &\\
             &= 6.70&  
        \end{flalign*}
    \end{step}
}
{
    \begin{step}{calculate $\omega^2$}
        \begin{flalign*}
            &&\omega^2&=\dfrac{\text{SSB}-(k-1)\text{MSW}}{\text{SST}+\text{MSW}} \\
            &&              &=\dfrac{28.15-(4-1)1.40}{50.55+1.40}\\
            &&              &=0.46 
    \end{flalign*}
    \end{step}
}
\begin{sstep}{Interpret Results}
        \item As the calculated $F = 6.70$ exceeds the critical value of $F =
            3.24$ at $p = 0.05$ with $df_1 = 3$ and $df_2 = 16$ the $H_0$ is
            rejected. 
    \item As the $\omega^2 \ge 0.15$ this also has a large effect size. 
    \item The next step in the analysis would be to use one of the multiple
    comparison tests to determine which of the means are significantly different
    from each other.
\end{sstep}

\end{example}

I still think this is way too complicated.