答案1
tcolorbox
虽然这是一个包,并且至少必须加载一个包才能支持颜色,但使用相同的特殊设置相当容易。
\documentclass{article}
\usepackage{blindtext}
\usepackage[most]{tcolorbox}
\begin{document}
\blindtext
\begin{tcolorbox}[colback=gray!50,enhanced,sharp corners,frame hidden,halign=center]
HOW CAN I DO THIS IN \LaTeX{} THE SIMPLER WAY?
\end{tcolorbox}
\blindtext
\end{document}
答案2
答案3
以下是仅使用 的一种方法xcolor
:
\documentclass{article}
\usepackage[svgnames]{xcolor}
\begin{document}
{\large\rlap{\vspace{-0.95\baselineskip}\color{Gainsboro!80!Lavender}\rule[-0.3\baselineskip]{\linewidth}{1.2\baselineskip}}\noindent\makebox[\linewidth]{ HOW CAN I DO THIS
IN \LaTeX{} THE SIMPLER WAY?}}
\bigskip
{\rlap{\vspace{-1\baselineskip}\color{Gainsboro!60!GhostWhite}\rule[-0.3\baselineskip]{\linewidth}{1.2\baselineskip}}\noindent\makebox[\linewidth]{ HOW CAN I DO THIS
IN \LaTeX{} THE SIMPLER WAY?}}
\bigskip
{\rlap{\small\vspace{-1.06\baselineskip}\color{GhostWhite!80!Lavender}\rule[-0.3\baselineskip]{\linewidth}{1.2\baselineskip}}\noindent\makebox[\linewidth]{ HOW CAN I DO THIS
IN \LaTeX{} THE SIMPLER WAY?}}
\end{document}
答案4
您可以使用xcolor
包装和盒子:
\noindent% prevent the box from being shifted
\colorbox{gray}{% create a colored box
\makebox[\textwidth][c]{% center the text on the page
\bf HOW CAN I DO THIS IN \LaTeX{} THE SIMPLER WAY?
}
}
编辑:请参阅 Schweinebacke 的评论和回答,以防止过满\hbox