![调整小页面以填充剩余的垂直空间](https://linux22.com/image/402810/%E8%B0%83%E6%95%B4%E5%B0%8F%E9%A1%B5%E9%9D%A2%E4%BB%A5%E5%A1%AB%E5%85%85%E5%89%A9%E4%BD%99%E7%9A%84%E5%9E%82%E7%9B%B4%E7%A9%BA%E9%97%B4.png)
我正在尝试使用 minipages 将文档分成三部分。首先,我创建了一个顶部条带,然后我想将文档分成两部分,并使这些部分完全填满页面剩余的垂直间距
我的问题是我必须手动计算第二和第三小页的高度,以便它们填满整个页面。是否可以自动执行此操作,这样如果我更改顶部条带的高度,它们会自动修改?
代码:
% Heavily commented to hopefully undestand what I am doing (Help!)
%
% Start a document with the here given default font size and paper size.
\documentclass[10pt,a4paper]{article}
% Call needed packages
\usepackage[a4paper,margin=0pt]{geometry} % Set the page margins.
\usepackage{lipsum} % To create random text
\usepackage{fontspec}
\usepackage{xcolor}
% Setup the language.
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\hyphenation{Some-long-word}
%Colors used
\definecolor{babyblueeyes}{rgb}{0.63, 0.79, 0.95}
\definecolor{blizzardblue}{rgb}{0.67, 0.9, 0.93}
% Command to check margins
\newcommand\redbox[1]{%
\setlength\fboxsep{0pt}\fcolorbox{red}{white}{#1}
}
\begin{document}
%--- TOP STRIP ---%
\noindent % Delete indentation white space
\colorbox{babyblueeyes}{% Background color
\begin{minipage}[c][0.65in]{\textwidth}% Height and width of minipage
\centering
\textcolor{black}{\fontsize{14pt}{0pt}%
\textbf{John Doe Peter}}
\\ \medskip
\textcolor{white}{\fontsize{14pt}{0pt}%
\textbf{Evolving Latex apprentice}}
\end{minipage}
}
%
%--- LEFT STRIP ---%
\noindent
\colorbox{blizzardblue}{% Background color
\begin{minipage}[t][10in]{0.2\textwidth}% Height and width of minipage
\vspace{0pt}
\textcolor{black}{\fontsize{14pt}{0pt}%
\textbf{Title side strip}}
\\ \medskip
\textcolor{white}{\fontsize{14pt}{0pt}%
\textbf{Text side strip}}
\end{minipage}%
}%
%
%--- RIGHT PART ---%
\begin{minipage}[t][8in]{0.75\textwidth}%
\vspace{0pt}
\lipsum[1-5]
\end{minipage}
\end{document}
答案1
我找到了解决方案。感谢用户@KOLEYGR。
所用代码如下。calculateBottomStripHeight 中的 -0.2in 是手动选择的,我猜它是来自 minipage 或 colorbox 中某种内部填充或边距的值,但我无法通过编程将其删除。
\newlength{\availafter}
\newlength{\topstripheight} % Top strip height
\setlength{\topstripheight}{0.65in}
\def\calculateBottomStripHeight{%
\setlength{\availafter}{%
\the\dimexpr\textheight-0.2in-\topstripheight-\pagetotal\relax}}
此后,我仅对顶部条带使用 \topstripheight,然后调用 \calculateBottomStripHeight 并使用 \avaliafter 作为其他两个小页面的高度。我已经测试过了,它似乎工作正常。
完整代码:
% Start a document with the here given default font size and paper size.
\documentclass[10pt,a4paper]{article}
% Call needed packages
\usepackage[a4paper,margin=0pt]{geometry} % Set the page margins.
\usepackage{lipsum} % To create random text
\usepackage{fontspec}
\usepackage{xcolor}
% Setup the language.
\usepackage[english]{babel}
\hyphenation{Some-long-word}
%Colors used
\definecolor{babyblueeyes}{rgb}{0.63, 0.79, 0.95}
\definecolor{blizzardblue}{rgb}{0.67, 0.9, 0.93}
% Command to check margins
\newcommand\redbox[1]{%
\setlength\fboxsep{0pt}\fcolorbox{red}{white}{#1}
}
% Set top strip height and remaining space
% Credits to KOLEYGR
\newlength{\availafter}
\newlength{\topstripheight} % Top strip height
\setlength{\topstripheight}{0.65in}
\def\calculateBottomStripHeight{%
\setlength{\availafter}{%
\the\dimexpr\textheight-0.2in-\topstripheight-\pagetotal\relax}}
\begin{document}
%--- TOP STRIP ---%
\noindent % Delete indentation white space
\colorbox{babyblueeyes}{% Background color
\begin{minipage}[c][\topstripheight]{\textwidth}% Height and width of minipage
\centering
\textcolor{black}{\fontsize{14pt}{0pt}%
\textbf{John Doe Peter}}
\\ \medskip
\textcolor{white}{\fontsize{14pt}{0pt}%
\textbf{Evolving \LaTeX{} apprentice}}
\end{minipage}
}
\calculateBottomStripHeight
%--- LEFT STRIP ---%
\noindent
\colorbox{blizzardblue}{% Background color
\begin{minipage}[t][\availafter]{0.2\textwidth}% Height and width of minipage
\vspace{0pt}
\textcolor{black}{\fontsize{14pt}{0pt}%
\textbf{Title side strip} Jesús María y José}
\\ \medskip
\textcolor{white}{\fontsize{14pt}{0pt}%
\textbf{Text side strip}}
\end{minipage}%
}%
%
%--- RIGHT PART ---%
\begin{minipage}[t][\availafter]{0.75\textwidth}%
\vspace{0pt}
\lipsum[1-5]
\end{minipage}
\end{document}