
我正在嘗試繪製一個尺寸與頁面大小相關的盒子。我可以用\length
術語(包括長度單位,例如 55.5pt)計算盒子的高度和寬度。然而,當嘗試在環境中繪製方框時,picture
尺寸項只是數字(例如,55.5)。如何將帶單位的長度轉換為普通數字?下面是我正在嘗試執行的操作的範例,但\textwidth
在參數\framebox
中的巨集中失敗了\put
。
% borderprob.tex SE 559677
\documentclass{memoir}
\usepackage{lipsum}
\newlength{\bmargin}
\setlength{\bmargin}{2cm}
\newlength{\bwidth} \setlength{\bwidth}{\paperwidth}
\addtolength{\bwidth}{-\bmargin}
\newlength{\bheight} \setlength{\bheight}{\paperheight}
\addtolength{\bheight}{-\bmargin}
\newcommand{\borderbox}{\put(0,0){\framebox(\textwidth,-\textheight)}{}}
%\renewcommand{\borderbox}{\put(0,0){BORDERBOX}}
%\renewcommand{\borderbox}{\put(0,0){\framebox(20,30)}{}}
%\renewcommand{\borderbox}{\put(0,0){\framebox({\bwidth},{\bheight})}{}}
%\renewcommand{\borderbox}{\put(0,0){\framebox(20,\bheight)}{}}
%\renewcommand{\borderbox}{\put(0,0){\framebox(\bwidth,30)}{}}
%\renewcommand{\borderbox}{\put(0,0){\framebox(20,30)}{}}
\begin{document}
% length values
\verb!\bmargin = ! \the\bmargin
\verb!\paperwidth = ! \the\paperwidth{}
\verb!\bwidth = ! \the\bwidth
\verb!\paperheight = ! \the\paperheight{}
\verb!\bheight = ! \the\bheight
% draw a box
\begin{picture}(0,0) \borderbox \end{picture}
\lipsum
\lipsum
\end{document}
答案1
在下一個 (LaTeX2e 2020-10-01) 版本中,您將能夠在圖片環境中使用長度,但現在添加\usepackage{picture}
,您可以使用\put(\bmargin,10cm)
或任何您需要的長度。