我有以下代码:
\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}
它基本上将页面分成两半,并使用可选参数(xparse)和adjustbox来使两个小页面的内容垂直对齐。
当我使用文本、方程式、图表(TikZ)等时,它运行得很好,并且它也可以很好地处理表格,但它只是吐出大量的溢出警告,即使它看起来不错:
\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}
以下是一些定义:
\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}}
我已经尝试过这里的许多解决方案:
-在表格设置中使用@{} -在调整框等中设置宽度 -在表格周围使用调整框(甚至是微型表格)将它们缩小到几乎不可见,但它仍然会生成相同的警告
但看起来表格周围有一堆浮动空间,我看不出哪些超出了小页面内的边距或宽度。
如果除了以某种方式摆脱过多的问题之外,还有更好的解决方案来解决上述黑客编辑问题,我们将非常感激您的建议。
下面是我解构了 \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}
第一个没问题,第二个是产生警告的原因,\adjustbox 用于右对齐表格。它适用于图像、方程式等,但不适合表格。
答案1
我设法找到了一个解决方案真的hacky,这不可能是你应该做的方式:
\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}
和 :
\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}
因此解决方案是:
- 从 0.99 调整为 1 以避免与调整框发生内部冲突(?)
- 提供另一个参数来调整第二个调整框的宽度
- 如果需要,使用adjustwidth将第二个小页面向右移动
这似乎是一个非常笨拙的方式:
- 在某些环境中,可能位于非完整文本宽度内
- 创建两个小页面
- 垂直对齐
- 使一个左对齐,另一个右对齐
- 为其中一个指定固定宽度,并计算另一个宽度
由于我这样做,所以部分内容变得混乱:
\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}
删除第二个小页面,这几乎适用于所有情况,但当我尝试在右侧使用对齐方程时,它就坏了,不知道为什么它们需要小页面。我还尝试了表格、多列等,但无法让它们整齐地工作。无论如何,必须有更好的解决方案来做到这一点,因为上面的解决方案虽然有效,但很丑陋,有时您必须在调整框中进行硬编码,以及您必须调整的数量。必须有一种方法让 Tex 基本上做这样的事情:
- 计算当前环境的剩余宽度
- 根据第一个小页面计算第二个小页面的宽度
- 左对齐第一个(这是默认行为)
- 垂直对齐
- 将第二个小页面向右对齐
我不知道如何做 #1,我可以做 #2 (fp),#3 自然而然地就完成了,而使用调整框的 #4 似乎很简单,对 #5 一无所知。调整框中有一个正确的选项,但它所做的只是将整个框推向右侧,而不是内容。
这是一个稍微好一点但仍然不太好的解决方案:
\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}
flushright 似乎消除了表格上的黑客攻击,并且 flalign* 允许方程式刷新 l 或 r,具体取决于您如何输入 & 。
\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}
我仍然认为这太复杂了。