2009-03-03 26 views
2

我正在使用Sphinx來記錄項目。它從restructured text生成LaTeX文件。如何在不干擾其他環境的情況下自定義現有的LaTeX環境

我想設置背景色爲灰色的提示筆記,所以我創造一個灰盒環境後定製通知環境:

\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\[email protected]{#1} 
    \par\strong{#2} 
    \csname [email protected]@#1\endcsname 
} 
{ 
    \csname [email protected]@\[email protected]\endcsname 
    \end{graybox} 
} 
\makeatother 

一切正常,除非我放置一個figure環境內通知環境。在這種情況下,我得到這個錯誤:

LaTeX Error: Not in outer par mode

有沒有辦法設置一個灰色的背景到通知環境?

+0

您可能想要將此標題更改爲「現有的Latex環境」。 – ramanujan 2009-04-20 12:14:54

回答

2

謝謝godbyk and Jouni回答我的問題。

問題是我沒有直接在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\[email protected]{#1} 
    \par\strong{#2} 
    \csname [email protected]@#1\endcsname 
} 
{ 
    \csname [email protected]@\[email protected]\endcsname 
    \end{graybox} 
} 
\makeatother 

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

PS:我不得不把6到的參數時數重新定義'figure':如果我不這樣做,它會在pdf文件中輸出一些'htbp'(我不是LaTeX專家,它只是我爲此問題找到的解決方案)

3

這是一個FAQ。在灰色框內放置一個數字(或任何其他可以在輸出中移動的「浮點數」)是沒有意義的;如果你想讓你的圖形包含一個灰色框,把灰色框環境放在圖形環境中。

1

正如Jouni正確指出的那樣,圖形和表格(即花車)可以左右移動,而灰色方塊不能包含它們。爲了達到預期的效果,你有兩個選擇:

  1. 把你的整個通知到figure環境(使整個通知可以圍繞在頁面上或到一個新的頁面,如果LaTeX的如此選擇浮動)。
  2. 請勿使用浮動(figure環境) - 只需使用\includegraphics即可將圖片直接彈出到notice環境中。但是,您將無法使用帶有這個非數字的標題,因爲標題只能在數字或表格環境中使用。如果你想與此圖像相關的說明,您可以使用caption package

    \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} 
    

我沒有使用過獅身人面像,所以我怕我不能幫你太多與此納入他們的輸出。

相關問題