我是乳胶新手,我想在颜色框的顶部和底部添加规则,
我的示例代码是,
\documentclass{article}
\usepackage{graphicx,xcolor,lipsum}
\begin{document}
\colorbox{pink}{\parbox{\textwidth}{%
\vskip10pt
\leftskip10pt\rightskip10pt
\lipsum[1]
\vskip10pt
}
}
\end{document}
- 我的预期输出是,
有人能帮助我完成这个任务吗?
答案1
您可以\hrulefill
在文本之前和之后使用,这虽然不会提供您所描绘的准确输出,但却很容易实现。
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{xcolor,lipsum}
\begin{document}
\colorbox{pink}{%
\parbox{\textwidth}{%
\hrulefill
{% We don't want \...skip to affect \hrulefill
\vskip10pt
\leftskip10pt\rightskip10pt
\lipsum[1]
\vskip10pt
}
\hrulefill
}
}
\end{document}
答案2
使用mdframed
:
\documentclass{article}
\usepackage{mdframed}
\usepackage{xcolor}
\usepackage{lipsum}
\newmdenv[
hidealllines=true,
backgroundcolor=pink,
topline=true,
bottomline=true,
linewidth=3pt,
linecolor=red
]{mybox}
\begin{document}
\begin{mybox}
\lipsum[1]
\end{mybox}
\end{document}
答案3
您可以将其堆叠。请注意,我调整了您的\parbox
宽度以使框位于适当的边距内。我还擅自将其放置在单独的宏中\mycolorbox
。请注意,它不能跨越页面边界。
\documentclass{article}
\usepackage{graphicx,xcolor,lipsum}
\usepackage{stackengine}
\parskip 1ex
\newcommand\mycolorbox[1]{%
\par\noindent\stackunder[-3pt]{\stackon[-3pt]{%
\colorbox{pink}{\parbox{\textwidth-10pt}{%
\vskip10pt
\leftskip10pt\rightskip10pt
#1
\vskip10pt
}
}%
}{\color{blue}\hsmash{\rule{\textwidth+10pt}{3pt}}}%
}{\color{blue}\hsmash{\rule{\textwidth+10pt}{3pt}}}
\par}
\begin{document}
\mycolorbox{\lipsum[1]}
\lipsum[1]
\end{document}
如果我误解了将规则稍微延伸到边距,您可以\textwidth
不+10pt
添加(或将其缩小)来制作它们。这是一个变体:
\documentclass{article}
\usepackage{graphicx,xcolor,lipsum}
\usepackage{stackengine}
\parskip 1ex
\newcommand\mycolorbox[1]{%
\par\noindent\stackunder[-5pt]{\stackon[-5pt]{%
\colorbox{pink}{\parbox{\textwidth-10pt}{%
\vskip10pt
\leftskip10pt\rightskip10pt
#1
\vskip10pt
}
}%
}{\color{blue!70}\hsmash{\rule{\textwidth-4pt}{2pt}}}%
}{\color{blue!70}\hsmash{\rule{\textwidth-4pt}{2pt}}}
\par}
\begin{document}
\mycolorbox{\lipsum[1]}
\lipsum[1]
\end{document}
答案4
\documentclass{standalone}
\usepackage{lipsum}
\usepackage{tcolorbox}
\newtcolorbox{Mybox}{
colback=pink!90!black,
colframe=black,
arc=0pt, outer arc=0pt,
boxrule=0pt,
toprule=3pt,
bottomrule=3pt
}
\begin{document}
\begin{Mybox}
\lipsum[1]
\end{Mybox}
\end{document}
前面的例子很经典,但tcolorbox
我们可以做更多有趣的盒子。
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage[skins,breakable]{tcolorbox}
\newtcolorbox{Mybox}{
width={\linewidth-6pt},
breakable,
enhanced,
colback=pink,
colframe=black,
arc=0pt, outer arc=0pt,
boxrule=0pt,
toprule=0pt,
bottomrule=0pt,
enlarge top by=5mm,
overlay ={
\draw[gray,thick] ([xshift=5mm]frame.north west)--([yshift=5mm]frame.north)--([xshift=-5mm]frame.north east);
\draw[fill=gray] ([yshift=4.5mm]frame.north) circle(3pt);
\draw[line width=3pt, blue!30!black, shorten >=-3pt, shorten < = -3pt] (frame.north west)--(frame.north east);
\draw[line width=3pt, blue!30!black, shorten >=-3pt, shorten < = -3pt] (frame.south west)--(frame.south east);
}
}
\newenvironment{Mypage}
{\par\centering\begin{Mybox}}{\end{Mybox}\par}
\begin{document}
\lipsum[2-3]
\begin{Mypage}
\lipsum[1]
\end{Mypage}
\lipsum[3]
\end{document}