\hfill \break 不起作用

\hfill \break 不起作用

我有以下文本块:

\colorbox{gray}{[862401.693536] sd 2:0:0:0: [sdb] Write Protect is off\hfill \break
[862401.693548] sd 2:0:0:0: [sdb] Mode Sense: 45 00 00 08\hfill \break
[862401.700884]  sdb: sdb1\hfill \break
[862401.705538] sd 2:0:0:0: [sdb] No Caching mode page present\hfill \break
[862401.705551] sd 2:0:0:0: [sdb] Assuming drive cache: write through\hfill \break
[862401.705562] sd 2:0:0:0: [sdb] Attached SCSI removable disk}

输出结果如附件截图所示。为什么\hfill组合\break不起作用?在此处输入图片描述

答案1

使用大锤tcolorbox

\documentclass{article}

\usepackage{tcolorbox}

\begin{document}
\noindent
\begin{tcolorbox}[boxrule=0pt,arc=0pt,colback=gray]
[862401.693536] sd 2:0:0:0: [sdb] Write Protect is off\newline
[862401.693548] sd 2:0:0:0: [sdb] Mode Sense: 45 00 00 08\newline
[862401.700884]  sdb: sdb1\newline
[862401.705538] sd 2:0:0:0: [sdb] No Caching mode page present\newline
[862401.705551] sd 2:0:0:0: [sdb] Assuming drive cache: write through\newline
[862401.705562] sd 2:0:0:0: [sdb] Attached SCSI removable disk
\end{tcolorbox}
\end{document}

在此处输入图片描述

答案2

\colorbox类似于\mbox,在这种盒子中,粘连设置为其自然大小,这与 的0pt情况类似\hfill\break设置了换行惩罚,但在水平盒子中不会发生换行,因此惩罚不起作用。如果你想要在水平盒子内放置段落,你需要

  \mbox{\parbox{5cm}{some text here}}

\mbox替换为\colorbox{yellow}

\hfill\break无论如何都不应该在乳胶文档中使用,如果您必须强制中断,则乳胶语法将是\\但同样需要在\parbox而不是中使用\mbox

答案3

您可能想要对该soul包进行一些突出显示。

\documentclass{article}

\usepackage{soul,xcolor}

\begin{document}
\noindent
\sethlcolor{gray}\hl{[862401.693536] sd 2:0:0:0: [sdb] Write Protect is off\\
[862401.693548] sd 2:0:0:0: [sdb] Mode Sense: 45 00 00 08\\
[862401.700884]  sdb: sdb1\\
[862401.705538] sd 2:0:0:0: [sdb] No Caching mode page present\\
[862401.705551] sd 2:0:0:0: [sdb] Assuming drive cache: write through\\
[862401.705562] sd 2:0:0:0: [sdb] Attached SCSI removable disk}
\end{document} 

在此处输入图片描述

相关内容