自动调整表格大小以避免其被推到下一页

自动调整表格大小以避免其被推到下一页

语境

我的文档有一个标题短语和一个包含文本的表格。我想将它们放在同一页上。

  • 表格的内容可能会发生变化(有时会多出或少出 2 行或 3 行文本单元格),但始终有 2 列和 20 行。为了便于阅读,我将最小行高设置为 0.5 厘米。

  • 我愿意不是想要将表格拆分到下一页

  • 但我希望文本尽可能大。

尝试

如果我使用较小的尺寸(例如\normalsize而不是\large),那么它可以适合,但字体要小得多,实际上有点太小,而在页面底部留下很大的空白。

因此,当我想自动调整其大小(或缩放?)时,我认为答案是这里并想使用该adjustbox软件包,但我似乎无法让它按我想要的方式工作。我对所有键和值的含义有点困惑。无论如何, 和 都无法\adjustbox{max width=\columnwidth}提供\adjustbox{max width=\textwidth}解决方案。我找不到使用max height或 的任何解决方案max totalheight

另外,我想知道我的问题是否与浮动环境位置的更一般问题。不确定,因为如果表格太大,我知道 LaTeX 会将其“推”到下一页。但如果是的话,在这种情况下该如何处理?

最后,我想知道是否有可能实现我想要的(而且,使用tabular)。

产生问题的代码

\documentclass[a4paper,fleqn,12pt]{article}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage[british]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{geometry}
\usepackage{array}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{adjustbox}

% Page layout 
\geometry{hmargin=1.5cm, vmargin=1.5cm}
\setlength{\parindent}{0cm}
\pagestyle{empty}


\begin{document}
\LARGE
\textbf{Mental calculation: mini-problems}
\newline \newline \large
\adjustbox{max width=\textwidth}{
\begin{tabular}{|>{\centering}m{14 cm}|>{\centering}m{4 cm}@{}m{0pt}@{}|}
\hline 
My golden goose laid 4 eggs each day during 9 days. How many eggs has she laid?&
 & \tabularnewline
 [0.5cm] \hline 
Mya has 40 marbles. She gives them out to 5 friends. How many marbles will get each friend?&
 & \tabularnewline
 [0.5cm] \hline 
We have 4 sheep. Our neighbours have 7 times more sheep than us. How many sheep do they have?&
 & \tabularnewline
 [0.5cm] \hline 
I will give out 72 candies to the 8 friends that I invited at my birthday's party. How many candies will receive each of my friends?&
 & \tabularnewline
 [0.5cm] \hline 
I had to fill this can with 18$~\text{L}$ of water. There was 7$~\text{L}$ left in it. How much does it contain?&
...............$~\text{L}$ & \tabularnewline
 [0.5cm] \hline 
We have loaded 64$~\text{kg}$ of flour, shared in 8 packets. How heavy is one packet?&
...............$~\text{kg}$ & \tabularnewline
 [0.5cm] \hline 
A market gardener had 72 cabbages in his vegetable garden, and harvested 54 of them last week. How many cabbages are still in the garden?&
 & \tabularnewline
 [0.5cm] \hline 
9$~\text{m}^{2}$ of this wall are already painted. 7$~\text{m}^{2}$ are still missing to have the wall completely painted. What is its area?&
...............$~\text{m}^{2}$ & \tabularnewline
 [0.5cm] \hline 
I already rode 84$~\text{km}$ out of 98$~\text{km}$. How long do I still have to go cycling?&
...............$~\text{km}$ & \tabularnewline
 [0.5cm] \hline 
Lily gets 6 £ pocket money every month. If she doesn't spend it during 7 months, how much will she spare?&
...............~£ & \tabularnewline
 [0.5cm] \hline 
Yesterday, my golden goose laid 8 eggs. That's 11 less than today. How many eggs has she laid today?&
 & \tabularnewline
 [0.5cm] \hline 
Janet bought 8 boxes of 7 pencils. How many pens did she buy?&
 & \tabularnewline
 [0.5cm] \hline 
A market gardener had 78 cabbages in his vegetable garden, and harvested 56 of them last week. How many cabbages are still in the garden?&
 & \tabularnewline
 [0.5cm] \hline 
I will give out 49 candies to the 7 friends that I invited at my birthday's party. How many candies will receive each of my friends?&
 & \tabularnewline
 [0.5cm] \hline 
Jerry has 17 marbles. Elijah has 17 marbles more than Jerry. How many marbles has Elijah?&
 & \tabularnewline
 [0.5cm] \hline 
Isabel has prepared 30 truffles splitted in 5 packets. How many truffles is there in one packet?&
 & \tabularnewline
 [0.5cm] \hline 
The gardener has planted 16 cabbages last week, and 5 cabbages more this week. How many cabbages did he plant altogether?&
 & \tabularnewline
 [0.5cm] \hline 
Our neighbours have 98 sheep. That's 70 more than us. How many sheep do we have?&
 & \tabularnewline
 [0.5cm] \hline 
Layla bought 9 pens at 7 £. How much did she pay?&
...............~£ & \tabularnewline
 [0.5cm] \hline 
My bike ride is 73$~\text{km}$ long and I already rode 36$~\text{km}$. How long do I still have to go cycling?&
...............$~\text{km}$ & \tabularnewline
 [0.5cm] \hline 
\end{tabular}
}

\end{document} 

答案1

我可以理解您不愿意将表格材料拆分到各个页面。但是,如果要在 (a) 允许在表格材料中间设置分页符和 (b) 缩小表格材料以使其适合页面的可用空间(并且冒着材料变得很小且几乎无法阅读的风险)之间做出选择,前者可能更可取。

longtable下面是使用环境而不是环境的解决方案tabular。如果\normalsize有效,则整个表格可以放在一页中;相反,如果\large\Large有效,则需要分页符。观察示例代码中的相对行宽划分,即 5:1;当然,您可以自由设置相对行宽以满足您的需要。

进一步观察,我还主张让表格材料看起来更加开放,主要是通过删除所有垂直线。单元格还可以包含通过\includegraphics语句插入的图像,而不是文本。并且,请考虑使用包的\SI和宏来强制单位和数字/单位对的外观一致。\sisiunitx

在此处输入图片描述

在此处输入图片描述

\documentclass[a4paper,fleqn,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[british]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{geometry}
\usepackage{array}
\usepackage{amssymb}
\usepackage{amsmath}

\usepackage{longtable,ragged2e,siunitx}
\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}p{#1}}
\setlength\extrarowheight{3pt} % provide some visual "breathing space"

% Page layout 
\geometry{margin=1.5cm}
\setlength{\parindent}{0cm}
\pagestyle{empty}

\begin{document}
\large % or: \Large, \huge, or whatever

\begingroup % localize the effect of the following \setlength instruction
\setlength\tabcolsep{0pt} 
\begin{longtable}{L{0.833\textwidth}R{0.167\textwidth}}

\caption{Mental calculation: Mini-problems} \label{tab:mini}\\
\multicolumn{2}{r}{Answer}\\
\hline
\endfirsthead

\caption*{Table \ref{tab:mini}, continued} \\
\multicolumn{2}{r}{Answer}\\
\hline
\endhead

\hline
\multicolumn{2}{r}{\small (Continued on the following page)}\\
\endfoot

\hline
\endlastfoot

My golden goose laid 4 eggs each day during 9 days. How many eggs has she laid?&\\
\hline
Mya has 40 marbles. She gives them out to 5 friends. How many marbles will each friend get?&\\
\hline
We have 4 sheep. Our neighbours have 7 times more sheep than us. How many sheep do they have?&\\
\hline
I will give out 72 candies to the 8 friends that I invited at my birthday party. How many candies will each of my friends receive?&\\
\hline
I had to fill this can with \SI{18}{\liter} of water. There was \SI{7}{\liter} left in it. How much does it contain?&
\si{\liter}\\
\hline
We have loaded \SI{64}{\kilogram} of flour, shared in 8 packets. How heavy is one packet?&
~\si{\kilogram}\\
\hline
A market gardener had 72 cabbages in his vegetable garden, and harvested 54 of them last week. How many cabbages are still in the garden?&\\
\hline
\SI{9}{\meter\squared} of this wall are already painted. \SI{7}{\meter\squared} are still missing to have the wall completely painted. What is its area?&
~\si{\meter\squared}\\
\hline
I already rode \SI{84}{\kilo\meter} out of \SI{98}{\kilo\meter}. How long do I still have to go cycling?&
~\si{\kilo\meter}\\
\hline
Lily gets 6\,£ pocket money every month. If she doesn't spend it during 7 months, how much will she spare?&
~£\\
\hline
Yesterday, my golden goose laid 8 eggs. That's 11 less than today. How many eggs has she laid today?&\\
\hline
Janet bought 8 boxes of 7 pencils. How many pens did she buy?&\\
\hline
A market gardener had 78 cabbages in his vegetable garden, and harvested 56 of them last week. How many cabbages are still in the garden?&\\
\hline
I will give out 49 candies to the 7 friends that I invited at my birthday's party. How many candies will receive each of my friends?&\\
\hline
Jerry has 17 marbles. Elijah has 17 marbles more than Jerry. How many marbles has Elijah?&\\
\hline
Isabel has prepared 30 truffles splitted in 5 packets. How many truffles are there in one packet?&\\
\hline
The gardener planted 16 cabbages last week and 5 cabbages more this week. How many cabbages did he plant altogether?&\\
\hline
Our neighbours have 98 sheep. That's 70 more than us. How many sheep do we have?&\\
\hline
Layla bought 9 pens at 7\,£. How much did she pay?&
~£\\
\hline
My bike ride is \SI{73}{\kilo\meter} long and I already rode \SI{36}{\kilo\meter}. How long do I still have to go cycling?&
~\si{\kilo\meter}\\
\end{longtable}
\endgroup
\end{document} 

答案2

如果您希望文本可读(在测试中,您做到了 111%),您真的不想缩小它。因此,您必须将其拆分为两页。结合对列表进行反制表,代码可能如下所示:

\documentclass[a4paper,12pt]{article}
\usepackage[british]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{geometry}
\usepackage{calc}
\usepackage{siunitx}


% Page layout 
\geometry{hmargin=1.5cm, vmargin=1.5cm}

\newenvironment{problems}{
    \newcommand\problem[2][]{
        \par
        \noindent\rule{\linewidth}{0.4pt}
        \\\nobreak\ignorespaces
        ##2
        % Borrowed from amsthm.sty
        \leavevmode\unskip\penalty9999\hbox{}\nobreak\hfill\quad
        % Lower the box so that the lines of the paragraph are not disturbed
        \raisebox{-\fboxsep-\fboxrule}{\fbox{\hbox to 2cm{\strut\hfil\si{##1}}}}
        \par
    }
}{}

\begin{document}

\subsection*{Mental calculation: mini-problems}

\begin{problems}
\problem{My golden goose laid 4~eggs each day during 9~days. How many eggs has she laid?}
\problem{Mya has 40~marbles. She gives them out to 5~friends. How many marbles will get each friend?}
\problem{We have 4~sheep. Our neighbours have 7~times more sheep than us. How many sheep do they have?}
\problem{I will give out 72~candies to the 8~friends that I invited at my birthday's party. How many candies will receive each of my friends?}
\problem[L]{I had to fill this can with \SI{18}{L} of water. There was \SI{7}{L} left in it. How much does it contain?}
\problem[kg]{We have loaded \SI{64}{kg} of flour, shared in 8~packets. How heavy is one packet?}
\problem{A market gardener had 72~cabbages in his vegetable garden, and harvested 54~of them last week. How many cabbages are still in the garden?}
\problem[m^2]{\SI{9}{m^2} of this wall are already painted. \SI{7}{m^2} are still missing to have the wall completely painted. What is its area?}
\problem[km]{I already rode \SI{84}{km} out of \SI{98}{km}. How long do I still have to go cycling?}
\problem[\textsterling]{Lily gets \SI{6}{\textsterling} pocket money every month. If she doesn't spend it during 7~months, how much will she spare?}
\problem{Yesterday, my golden goose laid 8~eggs. That's 11~less than today. How many eggs has she laid today?}
\problem{Janet bought 8~boxes of 7~pencils. How many pens did she buy?}
\problem{A market gardener had 78~cabbages in his vegetable garden, and harvested 56~of them last week. How many cabbages are still in the garden?}
\problem{I will give out 49~candies to the 7~friends that I invited at my birthday's party. How many candies will receive each of my friends?}
\problem{Jerry has 17~marbles. Elijah has 17~marbles more than Jerry. How many marbles has Elijah?}
\problem{Isabel has prepared 30~truffles splitted in 5~packets. How many truffles is there in one packet?}
\problem{The gardener has planted 16~cabbages last week, and 5~cabbages more this week. How many cabbages did he plant altogether?}
\problem{Our neighbours have 98~sheep. That's 70~more than us. How many sheep do we have?}
\problem[\textsterling]{Layla bought 9~pens at \SI{7}{\textsterling}. How much did she pay?}
\problem[km]{My bike ride is \SI{73}{km} long and I already rode \SI{36}{km}. How long do I still have to go cycling?}
\end{problems}

\end{document} 

请注意,我做了更多更改:

  • 用过的siunitx
  • 使用过的\subsection*而不是\textbf{\LARGE东西
  • 删除了不必要的包
  • 更改£\textsterling,因此utf8x也没有ucs必要(我强烈反对在 中使用 unicode 来表示非字母pdflatex
  • ~在所有金额之后添加

答案3

这是另一个答案,它与我之前的答案主要不同之处在于使用tabular环境。为了确保表格材料页眉材料适合在单个页面上使用\large相对字体大小,通常需要减少垂直边距的宽度(相对于您在发布中指定的宽度(1.5 厘米))。

在此处输入图片描述

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[british]{babel}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{geometry}
\usepackage{array}
\usepackage{amssymb}
\usepackage[fleqn]{amsmath}

\usepackage{ragged2e,siunitx}
\newcolumntype{L}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\RaggedLeft\arraybackslash}p{#1}}
\setlength\extrarowheight{3pt}

% Page layout 
\geometry{hmargin=1.5cm,vmargin=0.75cm}
\setlength{\parindent}{0cm}
\setlength\tabcolsep{0pt}
\pagestyle{empty}

\begin{document}
\large % or: \Large, \huge, or whatever

\textbf{Mental calculation: Mini-problems} 

\smallskip
\begin{tabular}{L{0.88\textwidth}R{0.12\textwidth}}
\multicolumn{2}{r}{Answer}\\
\hline
My golden goose laid 4 eggs each day during 9 days. How many eggs has she laid?&\\
\hline
Mya has 40 marbles. She gives them out to 5 friends. How many marbles will each friend get?&\\
\hline
We have 4 sheep. Our neighbours have 7 times more sheep than us. How many sheep do they have?&\\
\hline
I will give out 72 candies to the 8 friends that I invited at my birthday party. How many candies will each of my friends receive?&\\
\hline
I had to fill this can with \SI{18}{\liter} of water. There was \SI{7}{\liter} left in it. How much does it contain?&
\si{\liter}\\
\hline
We have loaded \SI{64}{\kilogram} of flour, shared in 8 packets. How heavy is one packet?&
~\si{\kilogram}\\
\hline
A market gardener had 72 cabbages in his vegetable garden, and harvested 54 of them last week. How many cabbages are still in the garden?&\\
\hline
\SI{9}{\meter\squared} of this wall are already painted. \SI{7}{\meter\squared} are still missing to have the wall completely painted. What is its area?&
~\si{\meter\squared}\\
\hline
I already rode \SI{84}{\kilo\meter} out of \SI{98}{\kilo\meter}. How long do I still have to go cycling?&
~\si{\kilo\meter}\\
\hline
Lily gets 6\,£ pocket money every month. If she doesn't spend it during 7 months, how much will she spare?&
~£\\
\hline
Yesterday, my golden goose laid 8 eggs. That's 11 less than today. How many eggs has she laid today?&\\
\hline
Janet bought 8 boxes of 7 pencils. How many pens did she buy?&\\
\hline
A market gardener had 78 cabbages in his vegetable garden, and harvested 56 of them last week. How many cabbages are still in the garden?&\\
\hline
I will give out 49 candies to the 7 friends that I invited to my birthday party. How many candies will receive each of my friends?&\\
\hline
Jerry has 17 marbles. Elijah has 17 marbles more than Jerry. How many marbles has Elijah?&\\
\hline
Isabel has prepared 30 truffles splitted in 5 packets. How many truffles are there in one packet?&\\
\hline
The gardener planted 16 cabbages last week and 5 cabbages more this week. How many cabbages did he plant altogether?&\\
\hline
Our neighbours have 98 sheep. That's 70 more than us. How many sheep do we have?&\\
\hline
Layla bought 9 pens at 7\,£. How much did she pay?&
~£\\
\hline
My bike ride is \SI{73}{\kilo\meter} long and I already rode \SI{36}{\kilo\meter}. How long do I still have to go cycling?&
~\si{\kilo\meter}\\
\hline
\end{tabular}
\end{document} 

相关内容