1

我正在使用Sphinx来记录项目。它从reStructuredText生成 LaTeX 文件。

我想给tipsnotes设置一个灰色的背景色,所以我在创建了一个graybox环境后自定义了notice环境:

\definecolor{MyGray}{rgb}{0.80,0.80,0.80}

\makeatletter\newenvironment{graybox}{%
   \begin{lrbox}{\@tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
   \colorbox{MyGray}{\usebox{\@tempboxa}}
}\makeatother

\makeatletter
\renewenvironment{notice}[2]{
  \begin{graybox}
  \bf\it
  \def\py@noticetype{#1}
  \par\strong{#2}
  \csname py@noticestart@#1\endcsname
}
{
  \csname py@noticeend@\py@noticetype\endcsname
  \end{graybox}
}
\makeatother

一切正常,除非我在通知环境中放置一个图形环境。在这种情况下,我收到此错误:

LaTeX 错误:不在外部标准模式下

有没有办法为那个通知环境设置灰色背景?

4

3 回答 3

3

这是一个常见问题解答。将图形(或任何其他可以在输出中移动到其他位置的“浮点数”)放入灰色框内是没有意义的;如果您希望您的图形包含一个灰色框,请将灰色框环境放在图形环境中。

于 2009-03-03T20:54:58.123 回答
2

谢谢GodbykJouni回答我的问题。

问题是我没有直接在LaTeX中编码。我用重组文本编写文档,Sphinx 输出LaTeX文件。

但我找到了一个解决方案:我重新定义了图形环境以使用flowfram包中的staticfigure

\usepackage{flowfram}

\definecolor{MyGray}{rgb}{0.80,0.80,0.80}

\makeatletter\newenvironment{graybox}{%
   \begin{lrbox}{\@tempboxa}\begin{minipage}{\columnwidth}}{\end{minipage}\end{lrbox}%
   \colorbox{MyGray}{\usebox{\@tempboxa}}
}\makeatother

\makeatletter
\renewenvironment{notice}[2]{
  \begin{graybox}
  \bf\it
  \def\py@noticetype{#1}
  \par\strong{#2}
  \csname py@noticestart@#1\endcsname
}
{
  \csname py@noticeend@\py@noticetype\endcsname
  \end{graybox}
}
\makeatother

\renewenvironment{figure}[6]{
  \begin{staticfigure}
}{
  \end{staticfigure}
}

PS:重新定义“数字”时,我必须将参数数量设为 6:如果我不这样做,它会在 pdf 文件中输出一些“htbp”(我不是LaTeX专家。这只是我找到的解决方案对于这个问题)

于 2009-03-04T10:36:19.070 回答
1

正如 Jouni 正确指出的那样,图形和表格(即浮动)可以移动,而您的灰色框不能包含它们。要达到预期的效果,您有两种选择:

  1. 将您的整个通知放入一个figure环境中(以便整个通知可以在页面上浮动,或者如果 LaTeX 选择,则可以浮动到新页面)。
  2. 不要使用浮动(figure环境)——只需使用\includegraphics将图像直接弹出到notice环境中。但是,您将无法在此非图形中使用标题,因为标题只能在图形或表格环境中使用。如果您想要与此图像关联的标题,可以使用caption

    \documentclass{article}
    \usepackage{caption}% let's us use captions outside of floats
    \usepackage{lipsum}% provides filler text
    \begin{document}
    \lipsum[1]
    \begin{center}
      \includegraphics{mypic}
      \captionof{figure}{This is my picture.}% makes a caption for non-floats
      \label{fig:mypic}
    \end{center}
    \lipsum[2]        
    \end{document}
    

我没有使用过 Sphinx,所以恐怕无法帮助您将其集成到他们的输出中。

于 2009-03-04T05:58:16.100 回答