有没有办法绘制一个具有宽度\textwidth
和高度的简单框,以便它从放置位置填充到页面底部边缘?
答案1
也许我仍然需要微调一些参数,但这里有一个\leaders
似乎可行的垂直想法:
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{lipsum}
\makeatletter
\newcommand*\@helper@hboxto@hsize[2]{%
\hb@xt@ \hsize {%
\vrule \@width .4\p@ \@height #1\ht\strutbox \@depth #2\dp\strutbox
\hfil
\vrule \@width .4\p@ % automatic height and depth
}
}
\newcommand*\@helper@hrule{%
\kern -.2\p@
\hrule \@height .2\p@ \@depth .2\p@
\kern -.2\p@
}
\newcommand*\boxcolumnfill{%
\par
\vskip \dimexpr \dp\strutbox-\prevdepth
\@helper@hrule
\@helper@hboxto@hsize{.25}{.25}%
\nobreak
\xleaders \vbox {
\kern -.25\ht\strutbox
\@helper@hboxto@hsize{.5}{.5}%
\kern -.25\dp\strutbox
}\vfill
\kern -.25\dp\strutbox
\nointerlineskip
\@helper@hboxto@hsize{.25}{0}%
\@helper@hrule
\break
}
\makeatother
\begin{document}
With some text before.
\lipsum*[1]
Is the positioning affected by the presence of descenders?
% Uncomment this line to find it out: Qfgjpqy.
\boxcolumnfill
\lipsum[2]
Whole pages of boxes follow.
\newpage
\boxcolumnfill
\boxcolumnfill
Some more text.
\end{document}
添加
下面是该代码的另一个版本,它\boxcolumnfill
为命令赋予一个可选参数,您可以在其中指定要在顶部水平规则上方插入的额外空格量:
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{lipsum}
\makeatletter
\newcommand*\@helper@hboxto@hsize[2]{%
\hb@xt@ \hsize {%
\vrule \@width .4\p@ \@height #1\ht\strutbox \@depth #2\dp\strutbox
\hfil
\vrule \@width .4\p@ % automatic height and depth
}
}
\newcommand*\@helper@hrule{%
\kern -.2\p@
\hrule \@height .2\p@ \@depth .2\p@
\kern -.2\p@
}
% The user-level command; in the optional argument you can specify additional
% whitespace to be inserted above the horizontal rule.
\newcommand*\boxcolumnfill[1][\z@]{%
\par
% Not yet sure: provide a legal breakpoint here, just in case the user
% passes an argument that is too tall?
% \penalty \@highpenalty
\kern \dimexpr \dp\strutbox-\prevdepth
% The additional "\dimexpr" around "#1" is actually redundant
% here, but you know, Murphy's law...
+\dimexpr #1\relax
\relax
\@helper@hrule
\@helper@hboxto@hsize{.25}{.25}%
\nobreak
\xleaders \vbox {
\kern -.25\ht\strutbox
\@helper@hboxto@hsize{.5}{.5}%
\kern -.25\dp\strutbox
}\vfill
\kern -.25\dp\strutbox
\nointerlineskip
\@helper@hboxto@hsize{.25}{0}%
\@helper@hrule
\break
}
\makeatother
\flushbottom % please note
\begin{document}
With some text before.
\lipsum*[1]
Is the positioning affected by the presence of descenders?
% Uncomment this line to find it out: Qfgjpqy.
\boxcolumnfill
\lipsum[2]
Some additional space above the rule,\\
without descenders.
% Now with descenders: Qfgjpqy.
\boxcolumnfill[\bigskipamount]
If used at the top of a new page, \verb|\boxcolumnfill| prints a box extending
to the full page height, but any additional space is ignored, even if specified.
\newpage
\boxcolumnfill
\boxcolumnfill[10cm]
This text should be on a new page. Let's try it again:
\boxcolumnfill[10cm]
\lipsum[3-4]
Now, with an argument that is too tall for the available space:
\boxcolumnfill[15cm]
\textbf{Beware:} a negative argument \emph{is} honored!\\
without descenders.
% Now with descenders: Qfgjpqy.
\boxcolumnfill[-2\baselineskip]
Some more text.
\end{document}
答案2
使用包很容易实现tcolorbox
。height fill
选项会创建高度等于到页面末尾可用空间的框:
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lipsum}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\begin{document}
With some text before.
\lipsum*[1]
\begin{tcolorbox}[height fill]
\end{tcolorbox}
\lipsum[2]
\begin{tcolorbox}[height fill]
\end{tcolorbox}
\begin{tcolorbox}[height fill]
\end{tcolorbox}
\lipsum[1-2]
\begin{tcolorbox}[height fill]
\end{tcolorbox}
\end{document}