如何突出顯示引用的部分?

如何突出顯示引用的部分?

我嘗試使用 突出顯示文件中引用的部分\colorbox{}{},但是當我放入其中很大一部分時,它不再適合我的頁面。

\colorbox{yellow}{
Quote from very very very very loooooooooongs section:
The properties of depth-first search depend strongly on whether the 
}

我想要得到的輸出是這樣的:

引用非常非常非常非常 loooooooooongs 部分:
深度優先搜尋的屬性很大程度上取決於是否

答案1

A\colorbox建立一個單行框,其寬度足以包含所有作為參數給出的文字。如果此文字長於一行,則該文字\colorbox對於該行來說將太長並到達頁邊距。另外,因為\colorbox只有一條線,所以不能\\在裡面使用。

克服這個問題的一種方法是將要突出顯示的文字放入\parbox. A\parbox建立一個指定寬度的方塊並斷開內部的線條以符合該寬度。在此範例中,我建立了一個\parboxof width \textwidth-2\fboxsep,其中\fboxsep是顏色框左側和右側的內邊距。因此,該框恰好位於頁邊距內。

\documentclass{article}
\usepackage{showframe}
\usepackage{xcolor}
\setlength\parindent{0pt}
\begin{document}
\colorbox{yellow}{
Quote from very very very very loooooooooongs section:
The properties of depth-first search depend strongly on whether the 
}

\colorbox{yellow}{\parbox{\dimexpr\textwidth-2\fboxsep}{
Quote from very very very very loooooooooongs section:\\
The properties of depth-first search depend strongly on whether the 
}}
\end{document}

在此輸入影像描述


然而,使用強大的tcolorbox套件來實現相同的事情可能會更容易。這是一個範例,我定義了一個環境mybox,​​產生與上面相同的輸出,但具有更簡單的使用者介面。

\documentclass{article}
\usepackage{showframe}
\usepackage{tcolorbox}
\newtcolorbox{mybox}{colback=yellow,boxsep=0pt,left=\fboxsep,right=\fboxsep,top=\fboxsep,bottom=\fboxsep,boxrule=0pt,arc=0pt,outer arc=0pt}
\setlength\parindent{0pt}
\begin{document}
\begin{mybox}
Quote from very very very very loooooooooongs section:
The properties of depth-first search depend strongly on whether the 
\end{mybox}
\end{document}

在此輸入影像描述

相關內容