问题
我想创建一个页面,其大小会裁剪为页面内容的大小。我还想能够缩进段落并设置文本和背景的颜色。有办法吗?
第一次尝试
我第一次尝试使用独立包来实现这一点。以下是示例代码:
\documentclass[varwidth]{standalone}
\usepackage[usenames,dvipsnames]{xcolor}
\pagecolor{Apricot}
\color{Sepia}
\begin{document}
This is my first paragraph.
It is long enough to go on to the second line because I added a bunch of words to it.
This is my second paragraph.
Notice the lack of indentation.
\end{document}
这是它给我的输出:
请注意,颜色符合我的预期,但没有缩进。
第二次尝试
研究这个问题,我发现这个问题,但当我尝试实现他们的解决方案如下:
\documentclass[preview]{standalone}
\usepackage[usenames,dvipsnames]{xcolor}
\pagecolor{Apricot}
\color{Sepia}
\usepackage{etoolbox}
\edef\keptparindent{\the\parindent}
\patchcmd{\preview}
{\ignorespaces} %%% \preview ends with \ignorespaces
{\parindent\keptparindent\ignorespaces}
{}{}
\begin{document}
This is my first paragraph.
It is long enough to go on to the second line because I added a bunch of words to it.
This is my second paragraph.
Notice the colors are not right.
\end{document}
我得到以下输出:
如您所见,颜色不正确。
答案1
内容被放入varwidth
使用 的环境minipage
中。minipage
段落内的缩进为零 ( \@parboxrestore
/ \@arrayparboxrestore
)。解决方法:
\documentclass[varwidth]{standalone}
\usepackage[usenames,dvipsnames]{xcolor}
\pagecolor{Apricot}
\color{Sepia}
\newlength\keptparindent
\keptparindent=\parindent
\begin{document}
\parindent=\keptparindent
This is my first paragraph.
It is long enough to go on to the second line because I added a bunch of
words to it.
This is my second paragraph.
Notice the lack of indentation.
\end{document}