你好。我想定义一个环境,根据宽度改变文本高度
\documentclass[a4paper]{book}
\usepackage{lipsum}
\begin{document}
\the\textwidth---\the\textheight
\newenvironment{whtext}[1]{%
\newpage\begingroup
\hsize=#1
\vsize=\dimexpr\textheight*\numexpr\hsize/\textwidth\relax
\textwidth=\hsize
\textheight=\vsize}%
{\endgroup\newpage}
\lipsum[1-10]
\begin{whtext}{15cm}
\the\textwidth---\the\textheight
\lipsum[1-20]
\the\textwidth---\the\textheight
\end{whtext}
\end{document}
我该做什么?
答案1
直接操纵等不是一个好主意textheight
。该geometry
软件包提供了使用 执行此操作的方法\newgeometry
,但价格是\clearpage\newpage
\documentclass[a4paper]{book}
\usepackage{geometry}
\usepackage{lipsum}
\begin{document}
\the\textwidth---\the\textheight
\newenvironment{whtext}[1]{%
\newpage\begingroup
\hsize=#1
\vsize=\dimexpr\textheight*\numexpr\hsize/\textwidth\relax
\newgeometry{textheight=\vsize,textwidth=\hsize}
}%
{\endgroup\newpage}
\lipsum[1-10]
\begin{whtext}{15cm}
\the\textwidth---\the\textheight
\lipsum[1-20]
\the\textwidth---\the\textheight
\end{whtext}
\begin{whtext}{10cm}
\the\textwidth---\the\textheight
\lipsum[1-20]
\the\textwidth---\the\textheight
\end{whtext}
\end{document}
答案2
我认为我有答案
\documentclass[a4paper]{book}
\usepackage{lipsum}
\begin{document}
\the\textwidth---\the\textheight
\makeatletter
\newenvironment{whtext}[1]{%
\newpage\begingroup
\hsize=#1
\vsize=\dimexpr\textheight*\hsize/\textwidth\relax
\textwidth=\hsize
\textheight=\vsize}%
{\endgroup\newpage}
\makeatother
\lipsum[1-10]
\begin{whtext}{15cm}
\the\textwidth---\the\textheight
\lipsum[1-20]
\the\textwidth---\the\textheight
\end{whtext}
\end{document}