如何使用宏指定 \parshape 中的行数

如何使用宏指定 \parshape 中的行数

我希望能够使用宏来指定给定的行数\parshape。因此,

\parshape 8 ...

例如,我希望能够使用

\newcommand*{\NumberOfLines}{8}
\parshape \NumberOfLines ...

但是,这会产生问题,因为后面的空格\NumberOfLines会被宏吞噬。我尝试了我所知道的常用技巧,例如\relax{}\,但这些技巧不起作用,因为它们被视为尺寸规范,这当然是无效的。

下面的 MWE 工作正常,并产生

在此处输入图片描述

但是,这有硬编码的行数:

\newcommand*{\MyParShape}{%
    \parshape 8
    \BodyParShape
}%

我希望这是

\newcommand*{\MyParShape}{%
    \parshape \NumberOfLines
    \BodyParShape
}%

代码:

\documentclass{article}

\newcommand*{\Text}{%
\sloppy\noindent
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. 
Curabitur dictum
gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. 
Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. 
Nulla et lectus vestibulum urna fringilla ultrices.%
}%


\newcommand*{\TitleParShape}{%
    0.40\hsize 0.20\hsize
}%
\newcommand*{\BodyParShape}{%
    0.35\hsize 0.30\hsize
    0.30\hsize 0.40\hsize
    0.25\hsize 0.50\hsize
    0.20\hsize 0.60\hsize
    0.15\hsize 0.70\hsize
    0.10\hsize 0.80\hsize
    0.05\hsize 0.90\hsize
    0.00\hsize 1.00\hsize
}%

\newcommand*{\NumberOfLines}{8   }
\newcommand*{\MyParShape}{%
    \parshape 8
    %% ^^^^ The above works, but need to use a macro that contains number of lines.
    %\parshape \NumberOfLines
    \BodyParShape
}%

\begin{document}
\parshape 1
\TitleParShape
{\bfseries\centering My Title\par\smallskip}%
\MyParShape
\Text
\end{document}

答案1

\newcommand*{\NumberOfLines}{8 }

或者

\newcommand*{\NumberOfLines}{\numexpr8\relax}

或者

 \parshape\NumberOfLines\space

或者

...

相关内容