这个问题与顶部和底部为半圆形的盒子。
在这里,我尝试将顶部排版为使用环境中的\savebox
半圆形,并产生以下效果:\parshape
MyRoundedBox*
而未使用的环境 MyRoundedBox
(即非星号变体)\savebox
会产生:
似乎在\parshape
a 内部使用 a 存在一些问题\savebox
。
这里的目标是使用 来\savebox
测量结果框的高度(按照@marmot 在链接问题的评论中的建议)。但由于遇到的问题,我进一步简化了测试用例。
代码:
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{environ}
\usepackage[protrusion=false]{microtype}
%\usepackage{showframe}
\usepackage[mathlines]{lineno}
\linenumbers
\AtEndDocument{\typeout{Total number of lines: \thelinenumber}}
\newcommand*{\Radius}{1.75in}
\newcommand*{\Margins}{2pt}
\newcommand*{\ExtraLeftMargin}{0cm}% Set to 0.5cm if want to see line numbers
\newcommand*{\PaperHeight}{12.5cm}%<----- This is tweaked for this example
\newlength{\TextWidth}
\newlength{\PaperWidth}
\pgfmathsetlength{\TextWidth}{2*\Radius}
\pgfmathsetlength{\PaperWidth}{\TextWidth+2*\Margins}
\usepackage[
paperwidth=\dimexpr\PaperWidth+\ExtraLeftMargin\relax,
paperheight=\PaperHeight,
left=\dimexpr\Margins+\ExtraLeftMargin\relax,
right=\Margins,
top=\Margins,
bottom=\Margins,
]{geometry}
\newcommand*{\TitleAndExternalBorder}[1]{%
\noindent
\TitleShape\begingroup\centering\textbf{#1}\par\endgroup%
\TopSemiCircleParshape%
}
\newcommand*{\TitleShape}{%
\parshape 2
0.40\hsize 0.20\hsize
0.26\hsize 0.48\hsize
}
\newcommand*{\TopSemiCircleParshape}{%
\parshape 9
%% First two lines used by title
%0.40\hsize 0.20\hsize
%0.26\hsize 0.48\hsize
0.20\hsize 0.60\hsize
0.14\hsize 0.72\hsize
0.10\hsize 0.80\hsize
0.07\hsize 0.86\hsize
0.05\hsize 0.90\hsize
0.03\hsize 0.94\hsize
0.025\hsize 0.95\hsize
0.01\hsize 0.99\hsize
0.00\hsize 1.00\hsize
}
\newcommand{\TextA}{%
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sem ante, efficitur eget diam quis, lacinia sollicitudin elit. Donec tempor sodales finibus. Fusce accumsan laoreet lorem, eget lacinia urna. Phasellus ornare nibh quis metus dignissim aliquam. Vestibulum hendrerit augue at libero dignissim cursus. Vestibulum tristique metus vitae sem sagittis gravida. Aliquam commodo arcu quam, at congue ex commodo quis. Ut dapibus, quam id suscipit vulputate, orci dolor lobortis lectus, in pellentesque ante est sit amet odio. Integer pretium iaculis sapien sit amet sagittis. Sed sagittis libero libero, eu tempus neque malesuada quis. Aliquam id mauris ac enim tincidunt aliquet nec sit amet odio. In ultricies in nulla id dictum. Nulla facilisi. Proin aliquet semper odio, sit amet eleifend ante.}
\NewEnviron{MyRoundedBox}[1]{%
%% #1 = Title
\sloppy\TitleAndExternalBorder{#1}%
\BODY%
}%
\makeatletter
\newsavebox{\@MyRoundedBoxSavebox}
\NewEnviron{MyRoundedBox*}[1]{% Same as {MyRoundedBox} but uses a \savebox
%% #1 = Title
\savebox{\@MyRoundedBoxSavebox}{%
\sloppy\TitleAndExternalBorder{#1}%
\BODY%
}%
\usebox{\@MyRoundedBoxSavebox}%
}%
\makeatother
\begin{document}%
%% --------------------------------------- This works
%\begin{MyRoundedBox}{My Lipsum Title}
% \noindent\TextA\par
%\end{MyRoundedBox}%
%% --------------------------------------- This savebox version does NOT
\begin{MyRoundedBox*}{My Lipsum Title}
\noindent\TextA\par
\end{MyRoundedBox*}%
\end{document}
答案1
请注意\savebox{\name}{...}
相当于\setbox\name=\hbox{...}
。
顺便说一句,你也可以使用\unvbox
来\usebox
让胶水膨胀。这也会清空盒子。
\documentclass{article}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{environ}
\usepackage[protrusion=false]{microtype}
%\usepackage{showframe}
\usepackage[mathlines]{lineno}
\linenumbers
\AtEndDocument{\typeout{Total number of lines: \thelinenumber}}
\newcommand*{\Radius}{1.75in}
\newcommand*{\Margins}{2pt}
\newcommand*{\ExtraLeftMargin}{0cm}% Set to 0.5cm if want to see line numbers
\newcommand*{\PaperHeight}{12.5cm}%<----- This is tweaked for this example
\newlength{\TextWidth}
\newlength{\PaperWidth}
\pgfmathsetlength{\TextWidth}{2*\Radius}
\pgfmathsetlength{\PaperWidth}{\TextWidth+2*\Margins}
\usepackage[
paperwidth=\dimexpr\PaperWidth+\ExtraLeftMargin\relax,
paperheight=\PaperHeight,
left=\dimexpr\Margins+\ExtraLeftMargin\relax,
right=\Margins,
top=\Margins,
bottom=\Margins,
]{geometry}
\newcommand*{\TitleAndExternalBorder}[1]{%
\noindent
\TitleShape\begingroup\centering\textbf{#1}\par\endgroup%
\TopSemiCircleParshape%
}
\newcommand*{\TitleShape}{%
\parshape 2
0.40\hsize 0.20\hsize
0.26\hsize 0.48\hsize
}
\newcommand*{\TopSemiCircleParshape}{%
\parshape 9
%% First two lines used by title
%0.40\hsize 0.20\hsize
%0.26\hsize 0.48\hsize
0.20\hsize 0.60\hsize
0.14\hsize 0.72\hsize
0.10\hsize 0.80\hsize
0.07\hsize 0.86\hsize
0.05\hsize 0.90\hsize
0.03\hsize 0.94\hsize
0.025\hsize 0.95\hsize
0.01\hsize 0.99\hsize
0.00\hsize 1.00\hsize
}
\newcommand{\TextA}{%
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sem ante, efficitur eget diam quis, lacinia sollicitudin elit. Donec tempor sodales finibus. Fusce accumsan laoreet lorem, eget lacinia urna. Phasellus ornare nibh quis metus dignissim aliquam. Vestibulum hendrerit augue at libero dignissim cursus. Vestibulum tristique metus vitae sem sagittis gravida. Aliquam commodo arcu quam, at congue ex commodo quis. Ut dapibus, quam id suscipit vulputate, orci dolor lobortis lectus, in pellentesque ante est sit amet odio. Integer pretium iaculis sapien sit amet sagittis. Sed sagittis libero libero, eu tempus neque malesuada quis. Aliquam id mauris ac enim tincidunt aliquet nec sit amet odio. In ultricies in nulla id dictum. Nulla facilisi. Proin aliquet semper odio, sit amet eleifend ante.}
\NewEnviron{MyRoundedBox}[1]{%
%% #1 = Title
\sloppy\TitleAndExternalBorder{#1}%
\BODY%
}%
\makeatletter
\newsavebox{\@MyRoundedBoxSavebox}
\NewEnviron{MyRoundedBox*}[1]{% Same as {MyRoundedBox} but uses a \savebox
%% #1 = Title
\setbox\@MyRoundedBoxSavebox=\vbox{%
\sloppy\TitleAndExternalBorder{#1}%
\BODY%
}%
\noindent\usebox{\@MyRoundedBoxSavebox}%
}%
\makeatother
\begin{document}%
%% --------------------------------------- This works
%\begin{MyRoundedBox}{My Lipsum Title}
% \noindent\TextA\par
%\end{MyRoundedBox}%
%% --------------------------------------- This savebox version does NOT
\begin{MyRoundedBox*}{My Lipsum Title}
\noindent\TextA\par
\end{MyRoundedBox*}%
\end{document}